ConstantCashFlowFR
Updated: 17 April 2015
Use the tablevalued function ConstantCashFlowFR to return the cash flow schedule for a loan with a fixed maturity date and annuitystyle payments using a table of forward rates to calculate each periodic payment. ConstantCashFlowFR computes the periodic interest and principal amount through to the maturity date.
The payment frequency is entered into ConstantCashFlowFR as the number of months between payments. For example, a loan with monthly payments would have a frequency of 1. A loan with quarterly payments would have a frequency of 3. A loan with annual payments would have a frequency of 12.
ConstantCashFlowFR supports both an initial grace period and an additional grace period during the life of the loan. All payments and payment 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 grace period is entered in ConstantCashFlowFR and it is greater than the reference date then it becomes the first payment date and subsequent payments are calculated from that date forward.
If any payment 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 that first payment date is calculated using the 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 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 frequency (as a number of months) to the previous payment date.
If there is no start date and no previous payment date or the number of months between those dates and the reference date is greater than the frequency the first payment date is calculated by adding the 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 endofmonth dates.
The periodic interest payment is calculated as:
Where:
I_{p}

=

Interest payment in period p

C_{p1}

=

Capital Amount In Debt in period p1

R_{p}

=

Interest rate in period p

F

=

@Frequency

N_{p}

=

Number of Month in period p

N_{p1}

=

Number of Month in period p1

If the period is irregular and is longer than the regular period then the interest amount is broken out into a regular interest amount and a 'grace' interest amount. The regular interest amount is simply the normal periodic interest and the grace interest is the difference between the amount calculated using the aboveformula and the normal periodic interest.
The principal payment is calculated as:
PPAY_{p} = PPMT(R_{p} * F/12,1,N(P1),C_{p1},FV,0)
Where:
PPAY_{p}

=

Principal payment in period p

PPMT

=

PPMT function

C_{p1}

=

Capital Amount In Debt in period p1

R_{p}

=

Interest rate in period p

F

=

@Frequency

P1

=

Period â€“ 1

FV

=

@LastPrinPayAmount

Syntax
SELECT * FROM [wct].[ConstantCashFlowFR](
<@OutstandingAmount, float,>
,<@LastPrinPayAmount, float,>
,<@PaymentFrequency, int,>
,<@MaturityDate, datetime,>
,<@ReferenceDate, datetime,>
,<@PrevPayDate, datetime,>
,<@StartDate, datetime,>
,<@FirstPayDate, datetime,>
,<@GracePeriodStartDate, datetime,>
,<@GracePeriodEndDate, datetime,>
,<@FutureRates, nvarchar(max),>)
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.
@LastPrinPayAmount
the amount of principal to be paid off on the maturity date. @OutstandingAmount is an expression of type float or of a type that can be implicitly converted to float.
@PaymentFrequency
the number of months in a regular interest payment. @PaymentFrequency is an expression of type int or of a type that can be implicitly converted to int.
@MaturityDate
the last payment 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.
@PrevPayDate
the last interest payment date prior to the reference date. @PrevPayDate 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.
@FirstPayDate
the first 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.
@GracePeriodStartDate
the date on which the (interim) grace period commences. @GracePeriodStartDate is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@GracePeriodEndDate
the date on which the (interim) grace period concludes. @GracePeriodEndDate is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@FutureRates
a SELECT statement, as a string, which identifies the forward dates and rates to be used in the calculation. The resultant table should consist of 2 columns: a date and a rate. The rate is decimal format such that 1% = .01.
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(Period1) + InterestPayment.

CapitalAmountInDebt

When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period1) â€“ PrincipalPayment

TotalExposure

When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period1) + InterestPayment

NumberOfMonth

The number of months between the @ReferenceDate and the PaymentDate.

PaymentDate

The endofmonth date of the payment.

GraceInterest

The amount of the grace interest

InterestRate

The Interest Rate used in the calculation of the interest and principal payment

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 @ReferenceDate is NULL then @ReferenceDate = GETDATE()
Â· GraceInterest is only calculated on @FirstPayDate and @GracePeriodEndDate.
Â· GraceInterest is only calculated if NumberOfMonth â€“ NumberOfMonth(Period1) > @PaymentFrequency.
Â· GraceInterest is the difference between the interest for the period from the previous row to the current row minus the interest that would have been calculated for a period with length equal to @PaymentFrequency.
Â· The final payment is adjusted for CapitalAmountInDebt(Period1) and the length of the period if it is less than @PaymentFrequency.
Â· 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.
Â· The interest rate used in the calculation comes from the @FutureRates resultant table. The rate value for the maximum date less than or equal to the PaymentDate is used.
Examples
Use the following forward rates, which have been inserted into a #fwdrates table, for all the examples.
SELECT
CAST(dt as datetime) as dt,
rate
INTO
#fwdrates
FROM (VALUES
('20141231',0.025)
,('20150131',0.025102)
,('20150228',0.025205)
,('20150331',0.025308)
,('20150430',0.02541)
,('20150531',0.025513)
,('20150630',0.025615)
,('20150731',0.025718)
,('20150831',0.02582)
,('20150930',0.025923)
,('20151031',0.026025)
,('20151130',0.026128)
,('20151231',0.026231)
,('20160131',0.026333)
,('20160229',0.026436)
,('20160331',0.026539)
,('20160430',0.026641)
,('20160531',0.026744)
,('20160630',0.026847)
,('20160731',0.026949)
,('20160831',0.027052)
,('20160930',0.027155)
,('20161031',0.027257)
,('20161130',0.02736)
,('20161231',0.027463)
,('20170131',0.027566)
,('20170228',0.027668)
,('20170331',0.027771)
,('20170430',0.027874)
,('20170531',0.027977)
,('20170630',0.028079)
,('20170731',0.028182)
,('20170831',0.028285)
,('20170930',0.028388)
,('20171031',0.028491)
,('20171130',0.028594)
,('20171231',0.028696)
,('20180131',0.028799)
,('20180228',0.028902)
,('20180331',0.029005)
,('20180430',0.029108)
,('20180531',0.029211)
,('20180630',0.029314)
,('20180731',0.029417)
,('20180831',0.02952)
,('20180930',0.029623)
,('20181031',0.029726)
,('20181130',0.029829)
,('20181231',0.029932)
,('20190131',0.030035)
,('20190228',0.030138)
,('20190331',0.030241)
,('20190430',0.030344)
,('20190531',0.030447)
,('20190630',0.03055)
,('20190731',0.030653)
,('20190831',0.030756)
,('20190930',0.030859)
,('20191031',0.030962)
,('20191130',0.031065)
,('20191231',0.031168)
)n(dt,rate)
This is a simple 300,000 loan with quarterly payments with the interest rates coming from #fwdrates.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,0 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,NULL @PrevPayDate
,NULL @StartDate
,NULL @FirstPayDate
,NULL @GracePeriodStartDate
,NULL @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following result.
In this example the SQL reflects a final principal payment of 172,000.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,172000 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,NULL @PrevPayDate
,NULL @StartDate
,NULL @FirstPayDate
,NULL @GracePeriodStartDate
,NULL @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following result.
In this example the last principal payment amount has been set to zero and a first payment date of 15June2015 has been added.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,0 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,NULL @PrevPayDate
,NULL @StartDate
,'20150615' @FirstPayDate
,NULL @GracePeriodStartDate
,NULL @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following result.
In this example there are no payments in 2018.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,0 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,NULL @PrevPayDate
,NULL @StartDate
,'20150615' @FirstPayDate
,'20180101' @GracePeriodStartDate
,'20190101' @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following results
In this example the first payment date is set to NULL and the previous payment date is set to '20141115' so that the first payment date will be calculated using the previous payment date.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,0 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,'20141115' @PrevPayDate
,NULL @StartDate
,NULL @FirstPayDate
,'20180101' @GracePeriodStartDate
,'20190101' @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following result.
In this example the grace period and the previous payment date are eliminated and a start date has been added.
SELECT
*
FROM
wct.ConstantCashFlowFR(
300000 @OutstandingAmount
,0 @LastPrinPayAmount
,3 @PaymentFrequency
,'20191215' @MaturityDate
,'20141215' @ReferenceDate
,'20141115' @PrevPayDate
,NULL @StartDate
,'20141015' @FirstPayDate
,NULL @GracePeriodStartDate
,NULL @GracePeriodEndDate,
,'SELECT * FROM #fwdrates' @FutureRates
)
This produces the following result.
See Also