Logo

SQL Server ConstantPrincipalAmount Function

Updated 2024-02-16 15:02:32.440000

Description

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:

I=P\times\left[\left(\left(1+\frac{R\times{F}}{12}\right)^{12\slash{F}}\right)^T\right]-1

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 [westclintech].[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.

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.

@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.

Return Type

table

colNamecolDatatypecolDesc
Periodint A reference number uniquely identifying a row in the resultant table.
PrincipalPaymentfloatThe amount of the principal payment.
InterestPaymentfloatThe amount of the regular interest payment.
CashFlowfloatPrincipalPayment + InterestPayment + GraceInterest.
OutstandingExposurefloatWhen Period = 0 then @OutstandingAmount. For Period > 0 then OutstandingExposure(Period-1) + InterestPayment.
CapitalAmountInDebtfloatWhen Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) – PrincipalPayment
TotalExposurefloatWhen Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) + InterestPayment
NumberOfMonthintThe number of months between the @ReferenceDate and the PaymentDate.
PaymentDatedatetimeThe end-of-month date of the payment.
GraceInterestfloatThe amount of the grace interest
InterestRatefloatThe 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).

PeriodPrincipal PaymentInterest PaymentCash FlowOutstanding ExposureCapital Amount In DebtTotal ExposureNumber Of MonthPayment DateGrace InterestInterest Rate
00.000.000.00100000.00100000.00100000.0002014-10-310.000.000000
15250.00756.196006.19100756.1994750.00100756.1932015-01-310.000.007562
25250.00693.045943.04101449.2389500.0095443.0462015-04-300.000.007314
35250.00676.795926.79102126.0184250.0090176.7992015-07-310.000.007562
45250.00637.095887.09102763.1079000.0084887.09122015-10-310.000.007562
55250.00597.395847.39103360.4973750.0079597.39152016-01-310.000.007562
65250.00545.525795.52103906.0168500.0074295.52182016-04-300.000.007397
75250.00517.995767.99104424.0063250.0069017.99212016-07-310.000.007562
85250.00478.295728.29104902.2958000.0063728.29242016-10-310.000.007562
95250.00438.595688.59105340.8852750.0058438.59272017-01-310.000.007562
105250.00385.835635.83105726.7147500.0053135.83302017-04-300.000.007314
115250.00359.195609.19106085.9042250.0047859.19332017-07-310.000.007562
125250.00319.495569.49106405.3937000.0042569.49362017-10-310.000.007562
135250.00279.795529.79106685.1831750.0037279.79392018-01-310.000.007562
145250.00232.235482.23106917.4126500.0031982.23422018-04-300.000.007314
155250.00200.395450.39107117.8021250.0026700.39452018-07-310.000.007562
165250.00160.695410.69107278.4916000.0021410.69482018-10-310.000.007562
175250.00120.995370.99107399.4810750.0016120.99512019-01-310.000.007562
185250.0078.635328.63107478.115500.0010828.63542019-04-300.000.007314
195250.0041.595291.59107519.70250.005541.59572019-07-310.000.007562
20250.001.89251.89107521.590.00251.89602019-10-310.000.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.

PeriodPrincipal PaymentInterest PaymentCash FlowOutstanding ExposureCapital Amount In DebtTotal ExposureNumber Of MonthPayment DateGrace InterestInterest Rate
00.000.000.00100000.00100000.00100000.0002014-10-310.000.000000
15250.000.005250.00100000.0094750.00100000.0012014-11-300.000.002450
25250.000.005250.00100000.0089500.0094750.0022014-12-310.000.004989
35250.000.005250.00100000.0084250.0089500.0032015-01-310.000.007534
45250.000.005250.00100000.0079000.0084250.0042015-02-280.000.009838
55250.000.005250.00100000.0073750.0079000.0052015-03-310.000.012395
65250.001293.546543.54101293.5468500.0075043.5462015-04-300.000.014876
75250.000.005250.00101293.5463250.0068500.0072015-05-310.000.002532
85250.000.005250.00101293.5458000.0063250.0082015-06-300.000.004989
95250.000.005250.00101293.5452750.0058000.0092015-07-310.000.007534
105250.000.005250.00101293.5447500.0052750.00102015-08-310.000.010085
115250.000.005250.00101293.5442250.0047500.00112015-09-300.000.012560
125250.00838.086088.08102131.6337000.0043088.08122015-10-310.000.015124
135250.000.005250.00102131.6331750.0037000.00132015-11-300.000.002450
145250.000.005250.00102131.6326500.0031750.00142015-12-310.000.004989
155250.000.005250.00102131.6321250.0026500.00152016-01-310.000.007534
165250.000.005250.00102131.6316000.0021250.00162016-02-290.000.009920
175250.000.005250.00102131.6310750.0016000.00172016-03-310.000.012478
185250.00358.135608.13102489.765500.0011108.13182016-04-300.000.014959
195250.000.005250.00102489.76250.005500.00192016-05-310.000.002532
20250.0014.57264.57102504.340.00264.57202016-06-300.000.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.

PeriodPrincipal PaymentInterest PaymentCash FlowOutstanding ExposureCapital Amount In DebtTotal ExposureNumber Of MonthPayment DateGrace InterestInterest Rate
00.000.000.00100000.00100000.00100000.0002014-10-310.000.000000
10.00753.37753.37100753.37100000.00100753.3732015-01-310.000.007534
25250.000.005250.00100753.3794750.00100000.0052015-03-310.000.004825
35250.000.005250.00100753.3789500.0094750.0062015-04-300.000.007287
45250.000.005250.00100753.3784250.0089500.0072015-05-310.000.009838
55250.000.005250.00100753.3779000.0084250.0082015-06-300.000.012312
65250.001356.036606.03102109.4073750.0080356.0392015-07-310.000.014876
75250.000.005250.00102109.4068500.0073750.00102015-08-310.000.002532
85250.000.005250.00102109.4063250.0068500.00112015-09-300.000.004989
95250.000.005250.00102109.4058000.0063250.00122015-10-310.000.007534
105250.000.005250.00102109.4052750.0058000.00132015-11-300.000.010003
115250.000.005250.00102109.4047500.0052750.00142015-12-310.000.012560
125250.00917.066167.06103026.4642250.0048417.06152016-01-310.000.015124
135250.000.005250.00103026.4637000.0042250.00162016-02-290.000.002369
145250.000.005250.00103026.4631750.0037000.00172016-03-310.000.004907
155250.000.005250.00103026.4626500.0031750.00182016-04-300.000.007369
165250.000.005250.00103026.4621250.0026500.00192016-05-310.000.009920
175250.000.005250.00103026.4616000.0021250.00202016-06-300.000.012395
185250.00434.515684.51103460.9610750.0016434.51212016-07-310.000.014959
195250.000.005250.00103460.965500.0010750.00222016-08-310.000.002532
205250.000.005250.00103460.96250.005500.00232016-09-300.000.004989
21250.0041.50291.50103502.470.00291.50242016-10-310.000.007534

We modify the SQL so that there are no payments in 2016.

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
                                   '2016-01-01', --@PrincipalGracePeriodStartDate
                                   '2017-01-01', --@PrincipalGracePeriodEndDate
                                   '2016-01-01', --@InterestGracePeriodStartDate
                                   '2017-01-01' --@InterestGracePeriodEndDate
    )

This produces the following result.

PeriodPrincipal PaymentInterest PaymentCash FlowOutstanding ExposureCapital Amount In DebtTotal ExposureNumber Of MonthPayment DateGrace InterestInterest Rate
00.000.000.00100000.00100000.00100000.0002014-10-310.000.000000
10.00753.37753.37100753.37100000.00100753.3732015-01-310.000.007534
25250.000.005250.00100753.3794750.00100000.0052015-03-310.000.004825
35250.000.005250.00100753.3789500.0094750.0062015-04-300.000.007287
45250.000.005250.00100753.3784250.0089500.0072015-05-310.000.009838
55250.000.005250.00100753.3779000.0084250.0082015-06-300.000.012312
65250.001356.036606.03102109.4073750.0080356.0392015-07-310.000.014876
75250.000.005250.00102109.4068500.0073750.00102015-08-310.000.002532
85250.000.005250.00102109.4063250.0068500.00112015-09-300.000.004989
95250.000.005250.00102109.4058000.0063250.00122015-10-310.000.007534
105250.000.005250.00102109.4052750.0058000.00132015-11-300.000.010003
115250.000.005250.00102109.4047500.0052750.00142015-12-310.000.012560
125250.001563.617634.53103673.0142250.0049063.61272017-01-31820.920.045892
135250.000.005250.00103673.0137000.0042250.00282017-02-280.000.002287
145250.000.005250.00103673.0131750.0037000.00292017-03-310.000.004825
155250.000.005250.00103673.0126500.0031750.00302017-04-300.000.007287
165250.000.005250.00103673.0121250.0026500.00312017-05-310.000.009838
175250.000.005250.00103673.0116000.0021250.00322017-06-300.000.012312
185250.00431.015681.01104104.0210750.0016431.01332017-07-310.000.014876
195250.000.005250.00104104.025500.0010750.00342017-08-310.000.002532
205250.000.005250.00104104.02250.005500.00352017-09-300.000.004989
21250.0041.50291.50104145.520.00291.50362017-10-310.000.007534

In this example we change the SQL so that the principal payment frequency will be every 5 months and the first payment dates are calculated from the previous interest and previous principal payment dates.

SELECT *
  FROM wct.ConstantPrincipalAmount(100000, --@OutstandingAmount
                                   'Actual/365', --@InterestBasis
                                   .03, --@InterestRate
                                   5, --@FreqPayPrincipal
                                   6, --@FreqPayInterest
                                   5250.00, --@PrinPayAmount
                                   '2014-10-01', --@ReferenceDate
                                   '2014-06-01', --@PrevPrincipalPayDate
                                   '2014-09-01', --@PrevInterestPayDate
                                   NULL, --@StartDate
                                   NULL, --@FirstPrincipalPayDate
                                   NULL, --@FirstInterestPayDate
                                   NULL, --@PrincipalGracePeriodStartDate
                                   NULL, --@PrincipalGracePeriodEndDate
                                   NULL, --@InterestGracePeriodStartDate
                                   NULL --@InterestGracePeriodEndDate
    )

This produces the following result.

PeriodPrincipal PaymentInterest PaymentCash FlowOutstanding ExposureCapital Amount In DebtTotal ExposureNumber Of MonthPayment DateGrace InterestInterest Rate
00.000.000.00100000.00100000.00100000.0002014-10-310.000.000000
15250.000.005250.00100000.0094750.00100000.0012014-11-300.000.002450
20.001187.421187.42101187.4294750.0095937.4252015-03-310.000.012395
35250.000.005250.00101187.4289500.0094750.0062015-04-300.000.002450
45250.001359.236609.23102546.6584250.0090859.23112015-09-300.000.015041
55250.000.005250.00102546.6579000.0084250.00162016-02-290.000.012478
60.001253.941253.94103800.5979000.0080253.94172016-03-310.000.015041
75250.000.005250.00103800.5973750.0079000.00212016-07-310.000.010003
80.001162.081162.08104962.6773750.0074912.08232016-09-300.000.015041
95250.000.005250.00104962.6768500.0073750.00262016-12-310.000.007534
100.001064.511064.51106027.1868500.0069564.51292017-03-310.000.014959
115250.000.005250.00106027.1863250.0068500.00312017-05-310.000.004989
120.00977.82977.82107005.0063250.0064227.82352017-09-300.000.015041
135250.000.005250.00107005.0058000.0063250.00362017-10-310.000.002532
145250.00881.066131.06107886.0652750.0058881.06412018-03-310.000.014959
155250.000.005250.00107886.0647500.0052750.00462018-08-310.000.012560
160.00780.57780.57108666.6347500.0048280.57472018-09-300.000.015041
175250.000.005250.00108666.6342250.0047500.00512019-01-310.000.010085
180.00685.20685.20109351.8342250.0042935.20532019-03-310.000.014959
195250.000.005250.00109351.8337000.0042250.00562019-06-300.000.007452
200.00595.95595.95109947.7837000.0037595.95592019-09-300.000.015041
215250.000.005250.00109947.7831750.0037000.00612019-11-300.000.004989
220.00504.02504.02110451.8031750.0032254.02652020-03-310.000.015041
235250.000.005250.00110451.8026500.0031750.00662020-04-300.000.002450
245250.00411.625661.62110863.4221250.0026911.62712020-09-300.000.015041
255250.000.005250.00110863.4216000.0021250.00762021-02-280.000.012395
260.00304.58304.58111168.0016000.0016304.58772021-03-310.000.014959
275250.000.005250.00111168.0010750.0016000.00812021-07-310.000.010003
280.00214.47214.47111382.4710750.0010964.47832021-09-300.000.015041
295250.000.005250.00111382.475500.0010750.00862021-12-310.000.007534
300.00122.12122.12111504.585500.005622.12892022-03-310.000.014959
315250.000.005250.00111504.58250.005500.00912022-05-310.000.004989
320.0030.2130.21111534.80250.00280.21952022-09-300.000.015041
33250.000.63250.63111535.430.00250.63962022-10-310.000.002532

See Also

Balloon - Schedule with periodic interest payments and principal repaid at maturity

Bullet - Schedule with single interest and principal payment at maturity

ConstantCashFlow - Schedule with equal periodic cash flows

ConstantPaymentAmount - Schedule with no maturity with fixed periodic payment amount

CONSTANTPRINCIPALRATE - Schedule with no fixed maturity where a fixed percentage principal payment

PAYMENTPERIODS - Number of months until first payment date, start of grace period, end of grace period, and total number payments for a loan