Login     Register

        Contact Us     Search

XLeratorDB/financial Documentation

SQL Server constant principal amount amortization


ConstantPrincipalAmount

Updated: 18 September 2014

Use the table-valued function ConstantPrincipalAmount to return the cash flow schedule for a loan with no fixed maturity date where the principal is reduced using a fixed amount. ConstantPrincipalAmount computes the periodic interest and applies the principal payment amounts until the loan balance has been brought to zero. ConstantPrincipalAmount supports separate interest and principal repayment schedules.
The interest and principal payment periods are entered in ConstantPrincipalAmount 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 6 months, then it would have a principal payment frequency of 6.
ConstantPrincipalAmount 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 ConstantPrincipalAmount 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 principle 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 respective 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 ConstantPrincipalAmount 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].[ConstantPrincipalAmount](
  <@OutstandingAmount, float,>
 ,<@InterestBasis, nvarchar(4000),>
 ,<@InterestRate, float,>
 ,<@FreqPayPrincipal, int,>
 ,<@FreqPayInterest, int,>
 ,<@PrinPayAmount, float,>
 ,<@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
@FreqPayPrincipal
the number of months between principal payments. @FreqPayPrincipal is an expression of type int or of a type that can be implicitly converted to int.
@FreqPayInterest
the number of months in a regular interest payment. @FreqPayInterest is an expression of type int or of a type that can be implicitly converted to int.
@PrinPayAmount
the amount of the periodic principal payment. @AmortizationRate is an expression of type float or of a type that can be implicitly converted to float.
@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. @FirstPrincipalPayDate 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. @FirstInterestPayDate 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 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.
·         The time value (see formula above) is calculated as the number of months between PaymentDate and PaymentDate(Period-1) divided by 12.
·         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 interest period is greater than @FreqPayInterest.
·         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 @FreqPayInterest.
·         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 @FreqPayInterest.
Examples
This is a 100,000 loan with quarterly payments of principal and interest and an interest rate of 3.0%. The principal payments 5,250.
SELECT
       *
FROM wct.ConstantPrincipalAmount(
  100000            --@OutstandingAmount
 ,'Actual/365'      --@InterestBasis
 ,.03               --@InterestRate
 ,3                 --@FreqPayPrincipal
 ,3                 --@FreqPayInterest
 ,5250.00           --@PrinPayAmount
 ,'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
5250.00
756.19
6006.19
100756.19
94750.00
100756.19
3
2015-01-31
0.00
0.007562
2
5250.00
693.04
5943.04
101449.23
89500.00
95443.04
6
2015-04-30
0.00
0.007314
3
5250.00
676.79
5926.79
102126.01
84250.00
90176.79
9
2015-07-31
0.00
0.007562
4
5250.00
637.09
5887.09
102763.10
79000.00
84887.09
12
2015-10-31
0.00
0.007562
5
5250.00
597.39
5847.39
103360.49
73750.00
79597.39
15
2016-01-31
0.00
0.007562
6
5250.00
545.52
5795.52
103906.01
68500.00
74295.52
18
2016-04-30
0.00
0.007397
7
5250.00
517.99
5767.99
104424.00
63250.00
69017.99
21
2016-07-31
0.00
0.007562
8
5250.00
478.29
5728.29
104902.29
58000.00
63728.29
24
2016-10-31
0.00
0.007562
9
5250.00
438.59
5688.59
105340.88
52750.00
58438.59
27
2017-01-31
0.00
0.007562
10
5250.00
385.83
5635.83
105726.71
47500.00
53135.83
30
2017-04-30
0.00
0.007314
11
5250.00
359.19
5609.19
106085.90
42250.00
47859.19
33
2017-07-31
0.00
0.007562
12
5250.00
319.49
5569.49
106405.39
37000.00
42569.49
36
2017-10-31
0.00
0.007562
13
5250.00
279.79
5529.79
106685.18
31750.00
37279.79
39
2018-01-31
0.00
0.007562
14
5250.00
232.23
5482.23
106917.41
26500.00
31982.23
42
2018-04-30
0.00
0.007314
15
5250.00
200.39
5450.39
107117.80
21250.00
26700.39
45
2018-07-31
0.00
0.007562
16
5250.00
160.69
5410.69
107278.49
16000.00
21410.69
48
2018-10-31
0.00
0.007562
17
5250.00
120.99
5370.99
107399.48
10750.00
16120.99
51
2019-01-31
0.00
0.007562
18
5250.00
78.63
5328.63
107478.11
5500.00
10828.63
54
2019-04-30
0.00
0.007314
19
5250.00
41.59
5291.59
107519.70
250.00
5541.59
57
2019-07-31
0.00
0.007562
20
250.00
1.89
251.89
107521.59
0.00
251.89
60
2019-10-31
0.00
0.007562

In this example we modify the SQL to have have monthly payments of principal and semi-annual payments of interest.
SELECT
       *
FROM wct.ConstantPrincipalAmount(
  100000            --@OutstandingAmount
 ,'Actual/365'      --@InterestBasis
 ,.03               --@InterestRate
 ,1                 --@FreqPayPrincipal
 ,6                 --@FreqPayInterest
 ,5250.00           --@PrinPayAmount
 ,'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
5250.00
0.00
5250.00
100000.00
94750.00
100000.00
1
2014-11-30
0.00
0.002450
2
5250.00
0.00
5250.00
100000.00
89500.00
94750.00
2
2014-12-31
0.00
0.004989
3
5250.00
0.00
5250.00
100000.00
84250.00
89500.00
3
2015-01-31
0.00
0.007534
4
5250.00
0.00
5250.00
100000.00
79000.00
84250.00
4
2015-02-28
0.00
0.009838
5
5250.00
0.00
5250.00
100000.00
73750.00
79000.00
5
2015-03-31
0.00
0.012395
6
5250.00
1293.54
6543.54
101293.54
68500.00
75043.54
6
2015-04-30
0.00
0.014876
7
5250.00
0.00
5250.00
101293.54
63250.00
68500.00
7
2015-05-31
0.00
0.002532
8
5250.00
0.00
5250.00
101293.54
58000.00
63250.00
8
2015-06-30
0.00
0.004989
9
5250.00
0.00
5250.00
101293.54
52750.00
58000.00
9
2015-07-31
0.00
0.007534
10
5250.00
0.00
5250.00
101293.54
47500.00
52750.00
10
2015-08-31
0.00
0.010085
11
5250.00
0.00
5250.00
101293.54
42250.00
47500.00
11
2015-09-30
0.00
0.012560
12
5250.00
838.08
6088.08
102131.63
37000.00
43088.08
12
2015-10-31
0.00
0.015124
13
5250.00
0.00
5250.00
102131.63
31750.00
37000.00
13
2015-11-30
0.00
0.002450
14
5250.00
0.00
5250.00
102131.63
26500.00
31750.00
14
2015-12-31
0.00
0.004989
15
5250.00
0.00
5250.00
102131.63
21250.00
26500.00
15
2016-01-31
0.00
0.007534
16
5250.00
0.00
5250.00
102131.63
16000.00
21250.00
16
2016-02-29
0.00
0.009920
17
5250.00
0.00
5250.00
102131.63
10750.00
16000.00
17
2016-03-31
0.00
0.012478
18
5250.00
358.13
5608.13
102489.76
5500.00
11108.13
18
2016-04-30
0.00
0.014959
19
5250.00
0.00
5250.00
102489.76
250.00
5500.00
19
2016-05-31
0.00
0.002532
20
250.00
14.57
264.57
102504.34
0.00
264.57
20
2016-06-30
0.00
0.004989

In this example we modify the SQL so that 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.ConstantPrincipalAmount(
  100000            --@OutstandingAmount
 ,'Actual/365'      --@InterestBasis
 ,.03               --@InterestRate
 ,1                 --@FreqPayPrincipal
 ,6                 --@FreqPayInterest
 ,5250.00           --@PrinPayAmount
 ,'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
753.37
753.37
100753.37
100000.00
100753.37
3
2015-01-31
0.00
0.007534
2
5250.00
0.00
5250.00
100753.37
94750.00
100000.00
5
2015-03-31
0.00
0.004825
3
5250.00
0.00
5250.00
100753.37
89500.00
94750.00
6
2015-04-30
0.00
0.007287
4
5250.00
0.00
5250.00
100753.37
84250.00
89500.00
7
2015-05-31
0.00
0.009838
5
5250.00
0.00
5250.00
100753.37
79000.00
84250.00
8
2015-06-30
0.00
0.012312
6
5250.00
1356.03
6606.03
102109.40
73750.00
80356.03
9
2015-07-31
0.00
0.014876
7
5250.00
0.00
5250.00
102109.40
68500.00
73750.00
10
2015-08-31
0.00
0.002532
8
5250.00
0.00
5250.00
102109.40
63250.00
68500.00
11
2015-09-30
0.00
0.004989
9
5250.00
0.00
5250.00
102109.40
58000.00
63250.00
12
2015-10-31
0.00
0.007534
10
5250.00
0.00
5250.00
102109.40
52750.00
58000.00
13
2015-11-30
0.00
0.010003
11
5250.00
0.00
5250.00
102109.40
47500.00
52750.00
14
2015-12-31
0.00
0.012560
12
5250.00
917.06
6167.06
103026.46
42250.00
48417.06
15
2016-01-31
0.00
0.015124
13
5250.00
0.00
5250.00
103026.46
37000.00
42250.00
16
2016-02-29
0.00
0.002369
14
5250.00
0.00
5250.00
103026.46
31750.00
37000.00
17
2016-03-31
0.00
0.004907
15
5250.00
0.00
5250.00
103026.46
26500.00
31750.00
18
2016-04-30
0.00
0.007369
16
5250.00