Login     Register

        Contact Us     Search

XLeratorDB/financial Documentation

SQL Server straight-line principal amortization


ConstantPrincipal

Updated: 18 September 2014

Use the table-valued function ConstantPrincipal to return the cash flow schedule for a loan with a fixed maturity date where the principal is reduced on a straight-line basis. ConstantPrincipal computes the periodic interest and principal amounts bring the loan balance to zero on the maturity date. ConstantPrincipal supports separate interest and principal repayment schedules.
The interest and principal payment periods are entered in ConstantPrincipal as the number of months between payments. For example, a loan with monthly payments of interest would have an interest frequency of 1. If principal is to be repaid every months, then it would have a principal payment frequency of 6.
ConstantPrincipal supports both an initial grace period and an additional grace period during the life of the loan, for principal and/or interest. All payments and their associated dates are calculated with respect to the reference date supplied to the function (which should not be confused with the start date). If an initial interest grace period is entered in ConstantPrincipal and it is greater than the reference date, then it becomes the first interest payment date and subsequent interest payments are calculated from that date forward. The same principal applies for principal payments.
If any payments would otherwise occur in the specified grace period, then that payment is moved to the end of the grace period and all remaining payments are calculated from the end of the grace period.
If no initial grace period is specified then the first payment date is calculated using the respective payment frequency. If the start date has been entered and the number of months between the start date and the reference date is less than the frequency, then the first payment date is calculated by adding the respective frequency (as a number of months) to the start date.
If no start date has been entered but a previous payment date has been entered and the number of months between the previous payment date and the reference date is less than the frequency, then the first payment date is calculated by adding the respective frequency (as a number of months) to the previous payment date.
If there is no start date and previous payment dates or the number of months between those dates and the reference date is greater than the frequency, then the first payment date is calculated by adding the resepctive frequency (as a number of months) to the reference date.
All payments in the resultant table are moved to the end of the month and interest is calculated using these end-of-month dates.
The interest rate is calculated as:

Formula for XLeratorDB ConstantPrincipal loan schedule function for SQL Server
Where:

I
=
InterestRate
R
=
@InterestRate
F
=
@Frequency
T
=
Time, in years, from the previous interest payment date to PaymentDate

In the case where there are one or more principal payments between interest payment dates, the interest payment amount is calculated using the outstanding principal balances during the interest payment period.
If the irregular period is longer than the regular period then the interest amount is broken out into the regular interest amount and a 'grace' interest amount.
Syntax
SELECT * FROM [wct].[ConstantPrincipal](
  <@OutstandingAmount, float,>
 ,<@InterestBasis, nvarchar(4000),>
 ,<@InterestRate, float,>
 ,<@PrincipalPaymentFrequency, int,>
 ,<@InterestPaymentFrequency, int,>
 ,<@LastPrinPayAmount, float,>
 ,<@MaturityDate, datetime,>
 ,<@ReferenceDate, datetime,>
 ,<@PrevPrincipalPayDate, datetime,>
 ,<@PrevInterestPayDate, datetime,>
 ,<@StartDate, datetime,>
 ,<@FirstPrincipalPayDate, datetime,>
 ,<@FirstInterestPayDate, datetime,>
 ,<@PrincipalGracePeriodStartDate, datetime,>
 ,<@PrincipalGracePeriodEndDate, datetime,>
 ,<@InterestGracePeriodStartDate, datetime,>
 ,<@InterestGracePeriodEndDate, datetime,>)
Arguments
@OutstandingAmount
the principal amount of the loan. @OutstandingAmount is an expression of type float or of a type that can be implicitly converted to float.
@InterestBasis
the day count convention used to calculate the interest amount. @InterestBasis can be 30/360, Actual/360, Actual/365, or Actual/Actual. @InterestBasis is an expression of the character string data type category.
@InterestRate
the annual rate of interest for the loan. @InterestRate is an expression of type float or of a type that can be implicitly converted to float
@PrinicpalPaymentFrequency
the number of months between principal payments. @PrincipalPaymentFrequency is an expression of type int or of a type that can be implicitly converted to int.
@InterestPaymentFrequency
the number of months in a regular interest payment. @InterestPaymentFrequency is an expression of type int or of a type that can be implicitly converted to int.
@LastPrinPayAmount
the amount of the principal payment due on the maturity date. @LastPrinPayAmount is an expression of type float or of a type that can be implicitly converted to float.
@MaturityDate
the maturity date of the loan. @MaturityDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@ReferenceDate
the starting date for the number of months with respect to all other dates. @ReferenceDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@PrevPrincipalPayDate
the last principal payment date prior to the reference date. @PrevPrincipalPayDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@PrevInterestPayDate
the last interest payment date prior to the reference date. @PrevPrincipalPayDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@StartDate
the start date of the loan. @StartDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@FirstPrincipalPayDate
the first principal payment date of the loan if other than a regular periodic payment. @FirstPayDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@FirstInterestPayDate
the first interest payment date of the loan if other than a regular periodic payment. @FirstPayDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@PrincipalGracePeriodStartDate
the date on which the (interim) principal grace period commences. @PrincipalGracePeriodStartDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@PrincipalGracePeriodEndDate
the date on which the (interim) principal grace period concludes. @PrincipalGracePeriodEndDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
 
@InterestGracePeriodStartDate
the date on which the (interim) interest grace period commences. @InterestGracePeriodStartDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
@PrincipalGracePeriodEndDate
the date on which the (interim) interest grace period concludes. @GracePeriodEndDate is an expression that returns a datetime or smalldatetime value, or a character string in date format. 
Return Type
RETURNS TABLE (
       [Period] [int] NULL,
       [PrincipalPayment] [float] NULL,
       [InterestPayment] [float] NULL,
       [CashFlow] [float] NULL,
       [OutstandingExposure] [float] NULL,
       [CapitalAmountInDebt] [float] NULL,
       [TotalExposure] [float] NULL,
       [NumberOfMonth] [int] NULL,
       [PaymentDate] [datetime] NULL,
       [GraceInterest] [float] NULL,
       [InterestRate] [float] NULL
)

Column
Description
Period
A reference number uniquely identifying a row in the resultant table.
PrincipalPayment
The amount of the principal payment.
InterestPayment
The amount of the regular interest payment.
CashFlow
PrincipalPayment + InterestPayment + GraceInterest.
OutstandingExposure
When Period = 0 then @OutstandingAmount. For Period > 0 then OutstandingExposure(Period-1) + InterestPayment.
CapitalAmountInDebt
When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) – PrincipalPayment
TotalExposure
When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) + InterestPayment
NumberOfMonth
The number of months between the @ReferenceDate and the PaymentDate.
PaymentDate
The end-of-month date of the payment.
GraceInterest
The amount of the grace interest
InterestRate
The interest rate from the previous interest payment date to the PaymentDate.

Remarks
·         The PaymentDate for all rows is generated as the last day of the month.
·         For Period = 0, PrincipalPayment, InterestPayment, CashFlow, NumberOfMonth, GraceInterest, and InterestRate are set to 0.
·         If @Frequency is NULL then @Frequency = 1.
·         If @InterestRate is NULL then @InterestRate = 0.
·         If @ReferenceDate is NULL then @ReferenceDate = GETDATE().
·         GraceInterest is only calculated on @FirstInterestPayDate and @InterestGracePeriodEndDate.
·         GraceInterest is only calculated if length of the grace interst periods is greater than @PaymentFrequency.
·         GraceInterest is the difference between the interest for the period from the previous interest payment to PaymentDate and interest that would have been calculated for a period with length equal to @PaymentFrequency.
·         CashFlow may not equal PaymentAmount on @FirstPayDate or @GracePeriodEndDate due to GraceInterest.
·         The last row returned will always be for the maturity date and may be shorter than a regular period depending on the combination of dates and @PaymentFrequency
Examples
This is a simple 5-year 100,000 loan with quarterly payments of principal and interest and an interest rate of 4.5%.
SELECT
       *
FROM wct.ConstantPrincipal(
  100000            --@OutstandingAmount
 ,'30/360'          --@InterestBasis
 ,.045              --@InterestRate
 ,3                 --@FreqPayPrincipal
 ,3                 --@FreqPayInterest
 ,10000.00          --@LastPrinPayAmount
 ,'2019-10-01'      --@MaturityDate
 ,'2014-10-01'      --@ReferenceDate
 ,NULL              --@PrevPrincipalPayDate
 ,NULL              --@PrevInterestPayDate
 ,NULL              --@StartDate
 ,NULL              --@FirstPrincipalPayDate
 ,NULL              --@FirstInterestPayDate
 ,NULL              --@PrincipalGracePeriodStartDate
 ,NULL              --@PrincipalGracePeriodEndDate
 ,NULL              --@InterestGracePeriodStartDate
 ,NULL              --@InterestGracePeriodEndDate
)
This produces the following result (which has been reformatted for ease of viewing).

Period
Principal Payment
Interest Payment
Cash Flow
Outstanding Exposure
Capital Amount In Debt
Total Exposure
Number Of Month
Payment Date
Grace Interest
Interest Rate
0
0.00
0.00
0.00
100000.00
100000.00
100000.00
0
2014-10-31
0.00
0.000000
1
4736.84
1125.00
5861.84
101125.00
95263.16
101125.00
3
2015-01-31
0.00
0.011250
2
4736.84
1071.71
5808.55
102196.71
90526.32
96334.87
6
2015-04-30
0.00
0.011250
3
4736.84
1018.42
5755.26
103215.13
85789.47
91544.74
9
2015-07-31
0.00
0.011250
4
4736.84
965.13
5701.97
104180.26
81052.63
86754.61
12
2015-10-31
0.00
0.011250
5
4736.84
911.84
5648.68
105092.11
76315.79
81964.47
15
2016-01-31
0.00
0.011250
6
4736.84
858.55
5595.39
105950.66
71578.95
77174.34
18
2016-04-30
0.00
0.011250
7
4736.84
805.26
5542.11
106755.92
66842.11
72384.21
21
2016-07-31
0.00
0.011250
8
4736.84
751.97
5488.82
107507.89
62105.26
67594.08
24
2016-10-31
0.00
0.011250
9
4736.84
698.68
5435.53
108206.58
57368.42
62803.95
27
2017-01-31
0.00
0.011250
10
4736.84
645.39
5382.24
108851.97
52631.58
58013.82
30
2017-04-30
0.00
0.011250
11
4736.84
592.11
5328.95
109444.08
47894.74
53223.68
33
2017-07-31
0.00
0.011250
12
4736.84
538.82
5275.66
109982.89
43157.89
48433.55
36
2017-10-31
0.00
0.011250
13
4736.84
485.53
5222.37
110468.42
38421.05
43643.42
39
2018-01-31
0.00
0.011250
14
4736.84
432.24
5169.08
110900.66
33684.21
38853.29
42
2018-04-30
0.00
0.011250
15
4736.84
378.95
5115.79
111279.61
28947.37
34063.16
45
2018-07-31
0.00
0.011250
16
4736.84
325.66
5062.50
111605.26
24210.53
29273.03
48
2018-10-31
0.00
0.011250
17
4736.84
272.37
5009.21
111877.63
19473.68
24482.89
51
2019-01-31
0.00
0.011250
18
4736.84
219.08
4955.92
112096.71
14736.84
19692.76
54
2019-04-30
0.00
0.011250
19
4736.84
165.79
4902.63
112262.50
10000.00
14902.63
57
2019-07-31
0.00
0.011250
20
10000.00
112.50
10112.50
112375.00
0.00
10112.50
60
2019-10-31
0.00
0.011250

 
We modify the SQL to have monthly payments of principal and quarterly payments of interest.
SELECT
       *
FROM wct.ConstantPrincipal(
  100000            --@OutstandingAmount
 ,'30/360'          --@InterestBasis
 ,.045              --@InterestRate
 ,1                 --@FreqPayPrincipal
 ,3                 --@FreqPayInterest
 ,10000.00          --@LastPrinPayAmount
 ,'2019-10-01'      --@MaturityDate
 ,'2014-10-01'      --@ReferenceDate
 ,NULL              --@PrevPrincipalPayDate
 ,NULL              --@PrevInterestPayDate
 ,NULL              --@StartDate
 ,NULL              --@FirstPrincipalPayDate
 ,NULL              --@FirstInterestPayDate
 ,NULL              --@PrincipalGracePeriodStartDate
 ,NULL              --@PrincipalGracePeriodEndDate
 ,NULL              --@InterestGracePeriodStartDate
 ,NULL              --@InterestGracePeriodEndDate
)
This produces the following result.

 Period
Principal Payment
Interest Payment
Cash Flow
Outstanding Exposure
Capital Amount In Debt
Total Exposure
Number Of Month
Payment Date
Grace Interest
Interest Rate
0
0.00
0.00
0.00
100000.00
100000.00
100000.00
0
2014-10-31
0.00
0.000000
1
1525.42
0.00
1525.42
100000.00
98474.58
100000.00
1
2014-11-30
0.00
0.003736
2
1525.42
0.00
1525.42
100000.00
96949.15
98474.58
2
2014-12-31
0.00
0.007486
3
1525.42
1107.88
2633.31
101107.88
95423.73
98057.03
3
2015-01-31
0.00
0.011250
4
1525.42
0.00
1525.42
101107.88
93898.31
95423.73
4
2015-02-28
0.00
0.003736
5
1525.42
0.00
1525.42
101107.88
92372.88
93898.31
5
2015-03-31
0.00
0.007486
6
1525.42
1056.40
2581.82
102164.28
90847.46
93429.28
6
2015-04-30
0.00
0.011250
7
1525.42
0.00
1525.42
102164.28
89322.03
90847.46
7
2015-05-31
0.00
0.003736
8
1525.42
0.00
1525.42
102164.28
87796.61
89322.03
8
2015-06-30
0.00
0.007486
9
1525.42
1004.92
2530.34
103169.20
86271.19
88801.53
9
2015-07-31
0.00
0.011250
10
1525.42
0.00
1525.42
103169.20
84745.76
86271.19
10
2015-08-31
0.00
0.003736
11
1525.42
0.00
1525.42
103169.20
83220.34
84745.76
11
2015-09-30
0.00
0.007486
12
1525.42
953.43
2478.86
104122.63
81694.92
84173.77
12
2015-10-31
0.00
0.011250
13
1525.42
0.00
1525.42
104122.63
80169.49
81694.92
13
2015-11-30
0.00
0.003736
14
1525.42
0.00
1525.42
104122.63
78644.07
80169.49
14
2015-12-31
0.00
0.007486
15
1525.42
901.95
2427.37
105024.58
77118.64
79546.02
15
2016-01-31
0.00
0.011250
16
1525.42
0.00
1525.42
105024.58
75593.22
77118.64
16
2016-02-29
0.00
0.003736
17
1525.42
0.00
1525.42
105024.58
74067.80
75593.22
17
2016-03-31
0.00
0.007486
18
1525.42
850.47
2375.89
105875.04
72542.37
74918.26
18
2016-04-30
0.00
0.011250
19
1525.42
0.00
1525.42
105875.04
71016.95
72542.37
19
2016-05-31
0.00
0.003736
20
1525.42
0.00
1525.42
105875.04
69491.53
71016.95
20
2016-06-30
0.00
0.007486
21
1525.42
798.98
2324.41
106674.03
67966.10
70290.51
21
2016-07-31
0.00
0.011250
22
1525.42
0.00
1525.42
106674.03
66440.68
67966.10
22
2016-08-31
0.00
0.003736
23
1525.42
0.00
1525.42
106674.03
64915.25
66440.68
23
2016-09-30
0.00
0.007486
24
1525.42
747.50
2272.92
107421.53
63389.83
65662.75
24
2016-10-31
0.00
0.011250
25
1525.42
0.00
1525.42
107421.53
61864.41
63389.83
25
2016-11-30
0.00
0.003736
26
1525.42
0.00
1525.42
107421.53
60338.98
61864.41
26
2016-12-31
0.00
0.007486
27
1525.42
696.02
2221.44
108117.54
58813.56
61035.00
27
2017-01-31
0.00
0.011250
28
1525.42
0.00
1525.42
108117.54
57288.14
58813.56
28
2017-02-28
0.00
0.003736
29
1525.42
0.00
1525.42
108117.54
55762.71
57288.14
29
2017-03-31
0.00
0.007486
30
1525.42
644.53
2169.96
108762.08
54237.29
56407.25
30
2017-04-30
0.00
0.011250
31
1525.42
0.00
1525.42
108762.08
52711.86
54237.29
31
2017-05-31
0.00
0.003736
32
1525.42
0.00
1525.42
108762.08
51186.44
52711.86
32
2017-06-30
0.00
0.007486
33
1525.42
593.05
2118.47
109355.13
49661.02
51779.49
33
2017-07-31
0.00
0.011250
34
1525.42
0.00
1525.42
109355.13
48135.59
49661.02
34
2017-08-31
0.00
0.003736
35
1525.42
0.00
1525.42
109355.13
46610.17
48135.59
35
2017-09-30
0.00
0.007486
36
1525.42
541.57
2066.99
109896.70
45084.75
47151.74
36
2017-10-31
0.00
0.011250
37
1525.42
0.00
1525.42
109896.70
43559.32
45084.75
37
2017-11-30
0.00
0.003736
38
1525.42
0.00
1525.42
109896.70
42033.90
43559.32
38
2017-12-31
0.00
0.007486
39
1525.42
490.09
2015.51
110386.78
40508.47
42523.98
39
2018-01-31
0.00
0.011250
40
1525.42
0.00
1525.42
110386.78
38983.05
40508.47
40
2018-02-28
0.00
0.003736
41
1525.42
0.00
1525.42
110386.78
37457.63
38983.05
41
2018-03-31
0.00
0.007486
42
1525.42
438.60
1964.03
110825.39
35932.20
37896.23
42
2018-04-30
0.00
0.011250
43
1525.42
0.00
1525.42
110825.39
34406.78
35932.20
43
2018-05-31
0.00
0.003736
44
1525.42
0.00
1525.42
110825.39
32881.36
34406.78
44
2018-06-30
0.00
0.007486
45
1525.42
387.12
1912.54
111212.50
31355.93
33268.47
45
2018-07-31
0.00
0.011250
46
1525.42
0.00
1525.42
111212.50
29830.51
31355.93
46
2018-08-31
0.00
0.003736
47
1525.42
0.00
1525.42
111212.50
28305.08
29830.51
47
2018-09-30
0.00
0.007486
48
1525.42
335.64
1861.06
111548.14
26779.66
28640.72
48
2018-10-31
0.00
0.011250
49
1525.42
0.00
1525.42
111548.14
25254.24
26779.66
49
2018-11-30
0.00
0.003736
50
1525.42
0.00
1525.42
111548.14
23728.81
25254.24
50
2018-12-31
0.00
0.007486
51
1525.42
284.15
1809.58
111832.29
22203.39
24012.97
51
2019-01-31
0.00
0.011250
52
1525.42
0.00
1525.42
111832.29
20677.97
22203.39
52
2019-02-28
0.00
0.003736
53
1525.42
0.00
1525.42
111832.29
19152.54
20677.97
53
2019-03-31
0.00
0.007486
54
1525.42
232.67
1758.09
112064.96
17627.12
19385.21
54
2019-04-30
0.00
0.011250
55
1525.42
0.00
1525.42
112064.96
16101.69
17627.12
55
2019-05-31
0.00
0.003736
56
1525.42
0.00
1525.42
112064.96
14576.27
16101.69
56
2019-06-30
0.00
0.007486
57
1525.42
181.19
1706.61
112246.15
13050.85
14757.46
57
2019-07-31
0.00
0.011250
58
1525.42
0.00
1525.42
112246.15
11525.42
13050.85
58
2019-08-31
0.00
0.003736
59
1525.42
0.00
1525.42
112246.15
10000.00
11525.42
59
2019-09-30
0.00
0.007486
60
10000.00
129.70
10129.70
112375.85
0.00
10129.70
60
2019-10-31
0.00
0.011250


In this example we modify the SQL so that the first interest payment isn't due until January of 2015 and the first principal payment isn't due until March of 2015.
SELECT
       *
FROM wct.ConstantPrincipal(
  100000            --@OutstandingAmount
 ,'30/360'          --@InterestBasis
 ,.045              --@InterestRate
 ,1                 --@FreqPayPrincipal
 ,3                 --@FreqPayInterest
 ,10000.00          --@LastPrinPayAmount
 ,'2019-10-01'      --@MaturityDate
 ,'2014-10-01'      --@ReferenceDate
 ,NULL              --@PrevPrincipalPayDate
 ,NULL              --@PrevInterestPayDate
 ,NULL              --@StartDate
 ,'2015-03-01'      --@FirstPrincipalPayDate
 ,'2015-01-01'      --@FirstInterestPayDate
 ,NULL              --@PrincipalGracePeriodStartDate
 ,NULL              --@PrincipalGracePeriodEndDate
 ,NULL              --@InterestGracePeriodStartDate
 ,NULL              --@InterestGracePeriodEndDate
)
This produces the following result.

Period
Principal Payment
Interest Payment
Cash Flow
Outstanding Exposure
Capital Amount In Debt
Total Exposure
Number Of Month
Payment Date
Grace Interest
Interest Rate
0
0.00
0.00
0.00
100000.00
100000.00
100000.00
0
2014-10-31
0.00
0.000000
1
0.00
1125.00
1125.00
101125.00
100000.00
101125.00
3
2015-01-31
0.00
0.011250
2
1636.36
0.00
1636.36
101125.00
98363.64
100000.00
5
2015-03-31
0.00
0.007486
3
1636.36
1118.89
2755.25
102243.89
96727.27
99482.52
6
2015-04-30
0.00
0.011250
4
1636.36
0.00
1636.36
102243.89
95090.91
96727.27
7
2015-05-31
0.00
0.003736
5
1636.36
0.00
1636.36
102243.89
93454.55
95090.91
8
2015-06-30
0.00
0.007486
6
1636.36
1069.82
2706.18
103313.70
91818.18
94524.36
9
2015-07-31
0.00
0.011250
7
1636.36
0.00
1636.36
103313.70
90181.82
91818.18
10
2015-08-31
0.00
0.003736
8
1636.36
0.00
1636.36
103313.70
88545.45
90181.82
11
2015-09-30
0.00
0.007486
9
1636.36
1014.59
2650.95
104328.30
86909.09
89560.05
12
2015-10-31
0.00
0.011250
10
1636.36
0.00
1636.36
104328.30
85272.73
86909.09
13
2015-11-30
0.00
0.003736
11
1636.36
0.00
1636.36
104328.30
83636.36
85272.73
14
2015-12-31
0.00
0.007486
12
1636.36
959.36
2595.73
105287.66
82000.00
84595.73
15
2016-01-31
0.00
0.011250
13
1636.36
0.00
1636.36
105287.66
80363.64
82000.00
16
2016-02-29
0.00
0.003736
14
1636.36
0.00
1636.36
105287.66
78727.27
80363.64
17
2016-03-31
0.00
0.007486
15
1636.36
904.14
2540.50
106191.80
77090.91
79631.41
18
2016-04-30
0.00
0.011250
16
1636.36
0.00
1636.36
106191.80
75454.55
77090.91
19
2016-05-31
0.00
0.003736
17
1636.36
0.00
1636.36
106191.80
73818.18
75454.55
20
2016-06-30
0.00
0.007486
18
1636.36
848.91
2485.27
107040.71
72181.82
74667.09
21
2016-07-31
0.00
0.011250
19
1636.36
0.00
1636.36
107040.71
70545.45
72181.82
22
2016-08-31
0.00
0.003736
20
1636.36
0.00
1636.36
107040.71
68909.09
70545.45
23
2016-09-30
0.00
0.007486
21
1636.36
793.68
2430.05
107834.39
67272.73
69702.77
24
2016-10-31
0.00
0.011250
22
1636.36
0.00
1636.36
107834.39
65636.36
67272.73
25
2016-11-30
0.00
0.003736
23
1636.36
0.00
1636.36
107834.39
64000.00
65636.36
26
2016-12-31
0.00
0.007486
24
1636.36
738.45
2374.82
108572.84
62363.64
64738.45
27
2017-01-31
0.00
0.011250
25
1636.36
0.00
1636.36
108572.84
60727.27
62363.64
28
2017-02-28
0.00
0.003736
26
1636.36
0.00
1636.36
108572.84
59090.91
60727.27
29
2017-03-31
0.00
0.007486
27
1636.36
683.23
2319.59
109256.07
57454.55
59774.14
30
2017-04-30
0.00
0.011250
28
1636.36
0.00
1636.36
109256.07
55818.18
57454.55
31
2017-05-31
0.00
0.003736
29
1636.36
0.00
1636.36
109256.07
54181.82
55818.18
32
2017-06-30
0.00
0.007486
30
1636.36
628.00
2264.36
109884.07
52545.45
54809.82
33
2017-07-31
0.00
0.011250
31
1636.36
0.00
1636.36
109884.07
50909.09
52545.45
34
2017-08-31
0.00
0.003736
32
1636.36
0.00
1636.36
109884.07
49272.73
50909.09
35
2017-09-30
0.00
0.007486
33
1636.36
572.77
2209.14
110456.84
47636.36
49845.50
36
2017-10-31
0.00
0.011250
34
1636.36
0.00
1636.36
110456.84
46000.00
47636.36
37
2017-11-30
0.00
0.003736
35
1636.36
0.00
1636.36
110456.84
44363.64
46000.00
38
2017-12-31
0.00
0.007486
36
1636.36
517.55
2153.91
110974.39
42727.27
44881.18
39
2018-01-31
0.00
0.011250
37
1636.36
0.00
1636.36
110974.39
41090.91
42727.27
40
2018-02-28
0.00
0.003736
38
1636.36
0.00
1636.36
110974.39
39454.55
41090.91
41
2018-03-31
0.00
0.007486
39
1636.36
462.32
2098.68
111436.71
37818.18
39916.86
42
2018-04-30
0.00
0.011250
40
1636.36
0.00
1636.36
111436.71
36181.82
37818.18
43
2018-05-31
0.00
0.003736
41
1636.36
0.00
1636.36
111436.71
34545.45
36181.82
44
2018-06-30
0.00
0.007486
42
1636.36
407.09
2043.45
111843.80
32909.09
34952.55
45
2018-07-31
0.00
0.011250
43
1636.36
0.00
1636.36
111843.80
31272.73
32909.09
46
2018-08-31
0.00
0.003736
44
1636.36
0.00
1636.36
111843.80
29636.36
31272.73
47
2018-09-30
0.00
0.007486
45
1636.36
351.86
1988.23
112195.66
28000.00
29988.23
48
2018-10-31
0.00
0.011250
46
1636.36
0.00
1636.36
112195.66
26363.64
28000.00
49
2018-11-30
0.00
0.003736
47
1636.36
0.00
1636.36
112195.66
24727.27
26363.64
50
2018-12-31
0.00
0.007486
48
1636.36
296.64
1933.00
112492.30
23090.91
25023.91
51
2019-01-31
0.00
0.011250
49
1636.36
0.00
1636.36
112492.30
21454.55
23090.91
52
2019-02-28
0.00
0.003736
50
1636.36
0.00
1636.36
112492.30
19818.18
21454.55
53
2019-03-31
0.00
0.007486
51
1636.36
241.41
1877.77
112733.71
18181.82
20059.59
54
2019-04-30
0.00
0.011250
52
1636.36
0.00
1636.36
112733.71
16545.45
18181.82
55
2019-05-31
0.00
0.003736
53
1636.36
0.00
1636.36
112733.71
14909.09
16545.45
56
2019-06-30
0.00
0.007486
54
1636.36
186.18
1822.55
112919.89
13272.73
15095.27
57
2019-07-31
0.00
0.011250
55
1636.36
0.00
1636.36
112919.89
11636.36
13272.73
58
2019-08-31
0.00
0.003736
56
1636.36
0.00
1636.36
112919.89
10000.00
11636.36
59
2019-09-30
0.00
0.007486
57
10000.00
130.95
10130.95
113050.85
0.00
10130.95
60
2019-10-31
0.00
0.011250

We modify the SQL so that there are no payments in 2018.
SELECT
       *
FROM wct.ConstantPrincipal(
  100000            --@OutstandingAmount
 ,'30/360'          --@InterestBasis
 ,.045              --@InterestRate
 ,1                 --@FreqPayPrincipal
 ,3                 --@FreqPayInterest
 ,10000.00          --@LastPrinPayAmount
 ,'2019-10-01'      --@MaturityDate
 ,'2014-10-01'      --@ReferenceDate
 ,NULL              --@PrevPrincipalPayDate
 ,NULL              --@PrevInterestPayDate
 ,NULL              --@StartDate
 ,'2015-03-01'      --@FirstPrincipalPayDate
 ,'2015-01-01'      --@FirstInterestPayDate
 ,'2018-01-01'      --@PrincipalGracePeriodStartDate
 ,'2019-01-01'      --@PrincipalGracePeriodEndDate
 ,'2018-01-01'      --@InterestGracePeriodStartDate
 ,'2019-01-01'      --@InterestGracePeriodEndDate
)
This produces the following result.

Period
Principal Payment
Interest Payment
Cash Flow
Outstanding Exposure
Capital Amount In Debt
Total Exposure
Number Of Month
Payment Date
Grace Interest
Interest Rate
0
0.00
0.00
0.00
100000.00
100000.00
100000.00
0
2014-10-31
0.00
0.000000
1
0.00
1125.00
1125.00
101125.00
100000.00
101125.00
3
2015-01-31
0.00
0.011250
2
2093.02
0.00
2093.02
101125.00
97906.98
100000.00
5
2015-03-31
0.00
0.007486
3
2093.02
1117.18
3210.20
102242.18
95813.95
99024.16
6
2015-04-30
0.00
0.011250
4
2093.02
0.00
2093.02
102242.18
93720.93
95813.95
7
2015-05-31
0.00
0.003736
5
2093.02
0.00
2093.02
102242.18
91627.91
93720.93
8
2015-06-30
0.00
0.007486
6
2093.02
1054.42
3147.44
103296.60
89534.88
92682.33
9
2015-07-31
0.00
0.011250
7
2093.02
0.00
2093.02
103296.60
87441.86
89534.88
10
2015-08-31
0.00
0.003736
8
2093.02
0.00
2093.02
103296.60
85348.84
87441.86
11
2015-09-30
0.00
0.007486
9
2093.02
983.78
3076.80
104280.38
83255.81
86332.62
12
2015-10-31
0.00
0.011250
10
2093.02
0.00
2093.02
104280.38
81162.79
83255.81
13
2015-11-30
0.00
0.003736
11
2093.02
0.00
2093.02
104280.38
79069.77
81162.79
14
2015-12-31
0.00
0.007486
12
2093.02
913.14
3006.16
105193.52
76976.74
79982.91
15
2016-01-31
0.00
0.011250
13
2093.02
0.00
2093.02
105193.52
74883.72
76976.74
16
2016-02-29
0.00
0.003736
14
2093.02
0.00
2093.02
105193.52
72790.70
74883.72
17
2016-03-31
0.00
0.007486
15
2093.02
842.50
2935.52
106036.02
70697.67
73633.20
18
2016-04-30
0.00
0.011250
16
2093.02
0.00
2093.02
106036.02
68604.65
70697.67
19
2016-05-31
0.00
0.003736
17
2093.02
0.00
2093.02
106036.02
66511.63
68604.65
20
2016-06-30
0.00
0.007486
18
2093.02
771.86
2864.88
106807.88
64418.60
67283.49
21
2016-07-31
0.00
0.011250
19
2093.02
0.00
2093.02
106807.88
62325.58
64418.60
22
2016-08-31
0.00
0.003736
20
2093.02
0.00
2093.02
106807.88
60232.56
62325.58
23
2016-09-30
0.00
0.007486
21
2093.02
701.22
2794.24
107509.10
58139.53
60933.78
24
2016-10-31
0.00
0.011250
22
2093.02
0.00
2093.02
107509.10
56046.51
58139.53
25
2016-11-30
0.00
0.003736
23
2093.02
0.00
2093.02
107509.10
53953.49
56046.51
26
2016-12-31
0.00
0.007486
24
2093.02
630.58
2723.61
108139.68
51860.47
54584.07
27
2017-01-31
0.00
0.011250
25
2093.02
0.00
2093.02
108139.68
49767.44
51860.47
28
2017-02-28
0.00
0.003736
26
2093.02
0.00
2093.02
108139.68
47674.42
49767.44
29
2017-03-31
0.00
0.007486
27
2093.02
559.94
2652.97
108699.63
45581.40
48234.36
30
2017-04-30
0.00
0.011250
28
2093.02
0.00
2093.02
108699.63
43488.37
45581.40
31
2017-05-31
0.00
0.003736
29
2093.02
0.00
2093.02
108699.63
41395.35
43488.37
32
2017-06-30
0.00
0.007486
30
2093.02
489.30
2582.33
109188.93
39302.33
41884.65
33
2017-07-31
0.00
0.011250
31
2093.02
0.00
2093.02
109188.93
37209.30
39302.33
34
2017-08-31
0.00
0.003736
32
2093.02
0.00
2093.02
109188.93
35116.28
37209.30
35
2017-09-30
0.00
0.007486
33
2093.02
418.66
2511.69
109607.59
33023.26
35534.94
36
2017-10-31
0.00
0.011250
34
2093.02
0.00
2093.02
109607.59
30930.23
33023.26
37
2017-11-30
0.00
0.003736
35
2093.02
0.00
2093.02
109607.59
28837.21
30930.23
38
2017-12-31
0.00
0.007486
36
2093.02
324.42
3776.71
109932.01
26744.19
29161.63
51
2019-01-31
1359.27
0.057530
37
2093.02
0.00
2093.02
109932.01
24651.16
26744.19
52
2019-02-28
0.00
0.003736
38
2093.02
0.00
2093.02
109932.01
22558.14
24651.16
53
2019-03-31
0.00
0.007486
39
2093.02
277.38
2370.41
110209.39
20465.12
22835.52
54
2019-04-30
0.00
0.011250
40
2093.02
0.00
2093.02
110209.39
18372.09
20465.12
55
2019-05-31
0.00
0.003736
41
2093.02
0.00
2093.02
110209.39
16279.07
18372.09
56
2019-06-30
0.00
0.007486
42
2093.02
206.74
2299.77
110416.14
14186.05
16485.81
57
2019-07-31
0.00
0.011250
43
2093.02
0.00
2093.02
110416.14
12093.02
14186.05
58
2019-08-31
0.00
0.003736
44
2093.02
0.00
2093.02
110416.14
10000.00
12093.02
59
2019-09-30
0.00
0.007486
45
10000.00
136.11
10136.11
110552.24
0.00
10136.11
60
2019-10-31
0.00
0.011250


In this example we change the SQL so that the principal payment frequency to every 5 months, the interest payment frequency to every 6 months, remove the grace periods, and calculate the first payment dates from the previous interest and previous principal payemnt dates.
SELECT
       *
FROM wct.ConstantPrincipal(
  100000            --@OutstandingAmount
 ,'30/360'          --@InterestBasis
 ,.045              --@InterestRate
 ,5                 --@FreqPayPrincipal
 ,6                 --@FreqPayInterest
 ,10000.00          --@LastPrinPayAmount
 ,'2019-10-01'      --@MaturityDate
 ,'2014-10-01'      --@ReferenceDate
 ,'2014-06-01'      --@PrevPrincipalPayDate
 ,'2014-05-01'      --@PrevInterestPayDate
 ,NULL              --@StartDate
 ,NULL              --@FirstPrincipalPayDate
 ,NULL              --@FirstInterestPayDate
 ,NULL              --@PrincipalGracePeriodStartDate
 ,NULL              --@PrincipalGracePeriodEndDate
 ,NULL              --@InterestGracePeriodStartDate
 ,NULL              --@InterestGracePeriodEndDate
)
This produces the following result.

Period
Principal Payment
Interest Payment
Cash Flow
Outstanding Exposure
Capital Amount In Debt
Total Exposure
Number Of Month
Payment Date
Grace Interest
Interest Rate
0
0.00
0.00
0.00
100000.00
100000.00
100000.00
0
2014-10-31
0.00
0.000000
1
7500.00
371.53
7871.53
100371.53
92500.00
100371.53
1
2014-11-30
0.00
0.003715
2
7500.00
0.00
7500.00
100371.53
85000.00
92500.00
6
2015-04-30
0.00
0.018715
3
0.00
2053.39
2053.39
102424.92
85000.00
87053.39
7
2015-05-31
0.00
0.022500
4
7500.00
0.00
7500.00
102424.92
77500.00
85000.00
11
2015-09-30
0.00
0.014944
5
0.00
1856.67
1856.67
104281.58
77500.00
79356.67
13
2015-11-30
0.00
0.022500
6
7500.00
0.00
7500.00
104281.58
70000.00
77500.00
16
2016-02-29
0.00
0.011187
7
0.00
1659.84
1659.84
105941.43
70000.00
71659.84
19
2016-05-31
0.00
0.022500
8
7500.00
0.00
7500.00
105941.43
62500.00
70000.00
21
2016-07-31
0.00
0.007444
9
0.00
1462.92
1462.92
107404.35
62500.00
63962.92
25
2016-11-30
0.00
0.022500
10
7500.00
0.00
7500.00
107404.35
55000.00
62500.00
26
2016-12-31
0.00
0.003715
11
7500.00
1265.89
8765.89
108670.23
47500.00
56265.89
31
2017-05-31
0.00
0.022500
12
7500.00
0.00
7500.00
108670.23
40000.00
47500.00
36
2017-10-31
0.00
0.018715
13
0.00
1040.89
1040.89
109711.12
40000.00
41040.89
37
2017-11-30
0.00
0.022500
14
7500.00
0.00
7500.00
109711.12
32500.00
40000.00
41
2018-03-31
0.00
0.014944
15
0.00
844.17
844.17
110555.28
32500.00
33344.17
43
2018-05-31
0.00
0.022500
16
7500.00
0.00
7500.00
110555.28
25000.00
32500.00
46
2018-08-31
0.00
0.011187
17
0.00
647.34
647.34
111202.63
25000.00
25647.34
49
2018-11-30
0.00
0.022500
18
7500.00
0.00
7500.00
111202.63
17500.00
25000.00
51
2019-01-31
0.00
0.007444
19
0.00
450.42
450.42
111653.05
17500.00
17950.42
55
2019-05-31
0.00
0.022500
20
7500.00
0.00
7500.00
111653.05
10000.00
17500.00
56
2019-06-30
0.00
0.003715
21
10000.00
215.43
10215.43
111868.48
0.00
10215.43
60
2019-10-31
0.00
0.018715

 

See Also

 



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service