Logo

ConstantCashFlow

Updated 2024-02-16 14:59:21.310000

Syntax

SELECT * FROM [westclintech].[wct].[ConstantCashFlow](
  <@OutstandingAmount, float,>
 ,<@LastPrinPayAmount, float,>
 ,<@InterestRate, float,>
 ,<@PaymentFrequency, int,>
 ,<@MaturityDate, datetime,>
 ,<@ReferenceDate, datetime,>
 ,<@PrevPayDate, datetime,>
 ,<@StartDate, datetime,>
 ,<@FirstPayDate, datetime,>
 ,<@GracePeriodStartDate, datetime,>
 ,<@GracePeriodEndDate, datetime,>)

Description

Use the table-valued function ConstantCashFlow to return the cash flow schedule for a loan with with a fixed maturity date and annuity-style payments. ConstantCashFlow computes the periodic interest and principal amounts through to the maturity date.

The payment period is entered in ConstantCashFlows 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 frequency of 3. A loan with annual payments would have a frequency of 12.

ConstantCashFlow supports both an initial grace period and an additional grace period during the life of the loan. 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 grace period is entered in ConstantCashFlow 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.

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 interest 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 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 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 payment is calculated as:

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

Where:

{"columns":[{"field":"column 1"},{"field":"column 2"},{"field":"column 3"}],"rows":[{"column 1":"I","column 2":"=","column 3":"InterestPayment"},{"column 1":"P","column 2":"=","column 3":"@OutstandingAmount"},{"column 1":"R","column 2":"=","column 3":"@InterestRate"},{"column 1":"F","column 2":"=","column 3":"@Frequency"},{"column 1":"T","column 2":"=","column 3":"( NumberOfMonth – NumberOfMonth ( Period -1)) / 12"}]}

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.

Arguments

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

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

@LastPrinPayAmount

the amount of principal to be paid off on the the maturity date. @OutstandingAmount is an expression of type float or of a type that can be implicitly converted to float.

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

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

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

@PaymentFrequency

the number of months in a regular payment. @PaymentFrequency is an expression of type int or of a type that can be implicitly converted to int.

@PrevPayDate

the last 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.

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

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

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

Return Type

table

{"columns": [{"field": "colName", "headerName": "Name", "header": "name"}, {"field": "colDatatype", "headerName": "Type", "header": "type"}, {"field": "colDesc", "headerName": "Description", "header": "description", "minWidth": 1000}], "rows": [{"id": "5517a8f9-fe27-49ec-9b0c-2dcdd5cadc4f", "colName": "Period", "colDatatype": "int", "colDesc": "A reference number uniquely identifying a row in the resultant table."}, {"id": "e12d0db1-f837-48c6-b6c3-d578dc3f7a3c", "colName": "PrincipalPayment", "colDatatype": "float", "colDesc": "The amount of the principal payment."}, {"id": "2f5b2874-8670-49d2-8d6e-3a141ee40630", "colName": "InterestPayment", "colDatatype": "float", "colDesc": "The amount of the regular interest payment."}, {"id": "f648f568-986e-4055-bf78-78ce40a628d5", "colName": "CashFlow", "colDatatype": "float", "colDesc": "PrincipalPayment + InterestPayment + GraceInterest."}, {"id": "5e7a4b6d-ec74-42ab-8523-68eb77b60eea", "colName": "OutstandingExposure", "colDatatype": "float", "colDesc": "When Period = 0 then @OutstandingAmount. For Period > 0 then OutstandingExposure(Period-1) + InterestPayment."}, {"id": "3017c4d7-b169-48d1-a5a7-a4a40c8f79e9", "colName": "CapitalAmountInDebt", "colDatatype": "float", "colDesc": "When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) \u2013 PrincipalPayment"}, {"id": "2c03c960-9442-4729-8b2c-73435cfd6df5", "colName": "TotalExposure", "colDatatype": "float", "colDesc": "When Period = 0, @OutstandingAmount. For Period > 0 then CapitalAmountInDebt(Period-1) + InterestPayment"}, {"id": "b21448de-4253-42f2-bb37-d9107606af08", "colName": "NumberOfMonth", "colDatatype": "int", "colDesc": "The number of months between the @ReferenceDate and the PaymentDate."}, {"id": "409aaba2-12e2-4a9e-871e-f359fa53f4d2", "colName": "PaymentDate", "colDatatype": "datetime", "colDesc": "The end-of-month date of the payment."}, {"id": "b853c2c3-077f-4de8-b779-3eccaf9ce0b8", "colName": "GraceInterest", "colDatatype": "float", "colDesc": "The amount of the grace interest"}, {"id": "474ca4e3-23f9-4848-b0ab-2c75be047e96", "colName": "InterestRate", "colDatatype": "float", "colDesc": "The interest amount from PaymentDate(Period-1) to PaymentDate assuming a principal amount of 1"}]}

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 @FirstPayDate and @GracePeriodEndDate.

GraceInterest is only calculated if NumberOfMonth – NumberOfMonth(Period-1) > @PaymentFrequency.

GraceInterest is the difference between the interest for the period from the previous row to the current row minus interest that would have been calculated for a period with length equal to @PaymentFrequency.

CashFlow may change on @FirstPayDate or @GracePeriodEndDate due to GraceInterest.

The final payment is adjusted for CapitalAmountInDebt(Period-1) 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.

Examples

This is a simple a 300,000 loan with quarterly payments and an interest rate of 6.0%.

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             0,            --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             NULL,         --@PrevPayDate

                             NULL,         --@StartDate

                             NULL,         --@FirstPayDate

                             NULL,         --@GracePeriodStartDate

                             NULL          --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"12973.72076234","InterestPayment":"4500","CashFlow":"17473.72076234","OutstandingExposure":"304500","CapitalAmountInDebt":"287026.27923766","TotalExposure":"304500","NumberOfMonth":"3","PaymentDate":"2015-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"2","PrincipalPayment":"13168.3265737751","InterestPayment":"4305.3941885649","CashFlow":"17473.72076234","OutstandingExposure":"308805.394188565","CapitalAmountInDebt":"273857.952663885","TotalExposure":"291331.673426225","NumberOfMonth":"6","PaymentDate":"2015-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"13365.8514723817","InterestPayment":"4107.86928995827","CashFlow":"17473.72076234","OutstandingExposure":"312913.263478523","CapitalAmountInDebt":"260492.101191503","TotalExposure":"277965.821953843","NumberOfMonth":"9","PaymentDate":"2015-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"13566.3392444674","InterestPayment":"3907.38151787255","CashFlow":"17473.72076234","OutstandingExposure":"316820.644996396","CapitalAmountInDebt":"246925.761947036","TotalExposure":"264399.482709376","NumberOfMonth":"12","PaymentDate":"2015-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"13769.8343331344","InterestPayment":"3703.88642920554","CashFlow":"17473.72076234","OutstandingExposure":"320524.531425601","CapitalAmountInDebt":"233155.927613901","TotalExposure":"250629.648376241","NumberOfMonth":"15","PaymentDate":"2016-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"13976.3818481315","InterestPayment":"3497.33891420852","CashFlow":"17473.72076234","OutstandingExposure":"324021.87033981","CapitalAmountInDebt":"219179.54576577","TotalExposure":"236653.26652811","NumberOfMonth":"18","PaymentDate":"2016-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"14186.0275758534","InterestPayment":"3287.69318648655","CashFlow":"17473.72076234","OutstandingExposure":"327309.563526296","CapitalAmountInDebt":"204993.518189916","TotalExposure":"222467.238952256","NumberOfMonth":"21","PaymentDate":"2016-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"14398.8179894912","InterestPayment":"3074.90277284875","CashFlow":"17473.72076234","OutstandingExposure":"330384.466299145","CapitalAmountInDebt":"190594.700200425","TotalExposure":"208068.420962765","NumberOfMonth":"24","PaymentDate":"2016-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"14614.8002593336","InterestPayment":"2858.92050300638","CashFlow":"17473.72076234","OutstandingExposure":"333243.386802151","CapitalAmountInDebt":"175979.899941092","TotalExposure":"193453.620703432","NumberOfMonth":"27","PaymentDate":"2017-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"14834.0222632236","InterestPayment":"2639.69849911637","CashFlow":"17473.72076234","OutstandingExposure":"335883.085301268","CapitalAmountInDebt":"161145.877677868","TotalExposure":"178619.598440208","NumberOfMonth":"30","PaymentDate":"2017-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"15056.5325971719","InterestPayment":"2417.18816516802","CashFlow":"17473.72076234","OutstandingExposure":"338300.273466436","CapitalAmountInDebt":"146089.345080696","TotalExposure":"163563.065843036","NumberOfMonth":"33","PaymentDate":"2017-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"15282.3805861295","InterestPayment":"2191.34017621044","CashFlow":"17473.72076234","OutstandingExposure":"340491.613642646","CapitalAmountInDebt":"130806.964494567","TotalExposure":"148280.685256907","NumberOfMonth":"36","PaymentDate":"2017-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"13","PrincipalPayment":"15511.6162949215","InterestPayment":"1962.1044674185","CashFlow":"17473.72076234","OutstandingExposure":"342453.718110065","CapitalAmountInDebt":"115295.348199645","TotalExposure":"132769.068961985","NumberOfMonth":"39","PaymentDate":"2018-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"14","PrincipalPayment":"15744.2905393453","InterestPayment":"1729.43022299468","CashFlow":"17473.72076234","OutstandingExposure":"344183.148333059","CapitalAmountInDebt":"99551.0576602998","TotalExposure":"117024.77842264","NumberOfMonth":"42","PaymentDate":"2018-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"15980.4548974355","InterestPayment":"1493.2658649045","CashFlow":"17473.72076234","OutstandingExposure":"345676.414197964","CapitalAmountInDebt":"83570.6027628643","TotalExposure":"101044.323525204","NumberOfMonth":"45","PaymentDate":"2018-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"16220.161720897","InterestPayment":"1253.55904144297","CashFlow":"17473.72076234","OutstandingExposure":"346929.973239407","CapitalAmountInDebt":"67350.4410419673","TotalExposure":"84824.1618043073","NumberOfMonth":"48","PaymentDate":"2018-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"17","PrincipalPayment":"16463.4641467104","InterestPayment":"1010.25661562951","CashFlow":"17473.72076234","OutstandingExposure":"347940.229855036","CapitalAmountInDebt":"50886.9768952569","TotalExposure":"68360.6976575968","NumberOfMonth":"51","PaymentDate":"2019-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"18","PrincipalPayment":"16710.4161089111","InterestPayment":"763.304653428853","CashFlow":"17473.72076234","OutstandingExposure":"348703.534508465","CapitalAmountInDebt":"34176.5607863458","TotalExposure":"51650.2815486857","NumberOfMonth":"54","PaymentDate":"2019-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"19","PrincipalPayment":"16961.0723505448","InterestPayment":"512.648411795187","CashFlow":"17473.72076234","OutstandingExposure":"349216.182920261","CapitalAmountInDebt":"17215.488435801","TotalExposure":"34689.209198141","NumberOfMonth":"57","PaymentDate":"2019-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"20","PrincipalPayment":"17215.488435801","InterestPayment":"258.232326537014","CashFlow":"17473.720762338","OutstandingExposure":"349474.415246798","CapitalAmountInDebt":"0","TotalExposure":"17473.720762338","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.0149999999999999"}]}

In this example, we modify the SQL to reflect a final principal payment of 172,000.

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             172000,       --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             NULL,         --@PrevPayDate

                             NULL,         --@StartDate

                             NULL,         --@FirstPayDate

                             NULL,         --@GracePeriodStartDate

                             NULL          --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"5872.44417451952","InterestPayment":"4500","CashFlow":"10372.4441745195","OutstandingExposure":"304500","CapitalAmountInDebt":"294127.55582548","TotalExposure":"304500","NumberOfMonth":"3","PaymentDate":"2015-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"2","PrincipalPayment":"5960.53083713731","InterestPayment":"4411.91333738221","CashFlow":"10372.4441745195","OutstandingExposure":"308911.913337382","CapitalAmountInDebt":"288167.024988343","TotalExposure":"298539.469162863","NumberOfMonth":"6","PaymentDate":"2015-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"6049.93879969437","InterestPayment":"4322.50537482515","CashFlow":"10372.4441745195","OutstandingExposure":"313234.418712207","CapitalAmountInDebt":"282117.086188649","TotalExposure":"292489.530363168","NumberOfMonth":"9","PaymentDate":"2015-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"6140.68788168979","InterestPayment":"4231.75629282973","CashFlow":"10372.4441745195","OutstandingExposure":"317466.175005037","CapitalAmountInDebt":"275976.398306959","TotalExposure":"286348.842481479","NumberOfMonth":"12","PaymentDate":"2015-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"6232.79819991513","InterestPayment":"4139.64597460438","CashFlow":"10372.4441745195","OutstandingExposure":"321605.820979642","CapitalAmountInDebt":"269743.600107044","TotalExposure":"280116.044281563","NumberOfMonth":"15","PaymentDate":"2016-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"6326.29017291386","InterestPayment":"4046.15400160566","CashFlow":"10372.4441745195","OutstandingExposure":"325651.974981247","CapitalAmountInDebt":"263417.30993413","TotalExposure":"273789.75410865","NumberOfMonth":"18","PaymentDate":"2016-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"6421.18452550757","InterestPayment":"3951.25964901195","CashFlow":"10372.4441745195","OutstandingExposure":"329603.234630259","CapitalAmountInDebt":"256996.125408622","TotalExposure":"267368.569583142","NumberOfMonth":"21","PaymentDate":"2016-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"6517.50229339018","InterestPayment":"3854.94188112934","CashFlow":"10372.4441745195","OutstandingExposure":"333458.176511388","CapitalAmountInDebt":"250478.623115232","TotalExposure":"260851.067289752","NumberOfMonth":"24","PaymentDate":"2016-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"6615.26482779103","InterestPayment":"3757.17934672848","CashFlow":"10372.4441745195","OutstandingExposure":"337215.355858117","CapitalAmountInDebt":"243863.358287441","TotalExposure":"254235.802461961","NumberOfMonth":"27","PaymentDate":"2017-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"6714.4938002079","InterestPayment":"3657.95037431162","CashFlow":"10372.4441745195","OutstandingExposure":"340873.306232429","CapitalAmountInDebt":"237148.864487233","TotalExposure":"247521.308661753","NumberOfMonth":"30","PaymentDate":"2017-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"6815.21120721102","InterestPayment":"3557.2329673085","CashFlow":"10372.4441745195","OutstandingExposure":"344430.539199737","CapitalAmountInDebt":"230333.653280022","TotalExposure":"240706.097454542","NumberOfMonth":"33","PaymentDate":"2017-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"6917.43937531918","InterestPayment":"3455.00479920033","CashFlow":"10372.4441745195","OutstandingExposure":"347885.543998937","CapitalAmountInDebt":"223416.213904703","TotalExposure":"233788.658079223","NumberOfMonth":"36","PaymentDate":"2017-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"13","PrincipalPayment":"7021.20096594897","InterestPayment":"3351.24320857055","CashFlow":"10372.4441745195","OutstandingExposure":"351236.787207508","CapitalAmountInDebt":"216395.012938754","TotalExposure":"226767.457113274","NumberOfMonth":"39","PaymentDate":"2018-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"14","PrincipalPayment":"7126.5189804382","InterestPayment":"3245.92519408131","CashFlow":"10372.4441745195","OutstandingExposure":"354482.712401589","CapitalAmountInDebt":"209268.493958316","TotalExposure":"219640.938132835","NumberOfMonth":"42","PaymentDate":"2018-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"7233.41676514477","InterestPayment":"3139.02740937474","CashFlow":"10372.4441745195","OutstandingExposure":"357621.739810964","CapitalAmountInDebt":"202035.077193171","TotalExposure":"212407.521367691","NumberOfMonth":"45","PaymentDate":"2018-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"7341.91801662194","InterestPayment":"3030.52615789757","CashFlow":"10372.4441745195","OutstandingExposure":"360652.265968861","CapitalAmountInDebt":"194693.159176549","TotalExposure":"205065.603351069","NumberOfMonth":"48","PaymentDate":"2018-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"17","PrincipalPayment":"7452.04678687127","InterestPayment":"2920.39738764824","CashFlow":"10372.4441745195","OutstandingExposure":"363572.66335651","CapitalAmountInDebt":"187241.112389678","TotalExposure":"197613.556564197","NumberOfMonth":"51","PaymentDate":"2019-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"18","PrincipalPayment":"7563.82748867434","InterestPayment":"2808.61668584517","CashFlow":"10372.4441745195","OutstandingExposure":"366381.280042355","CapitalAmountInDebt":"179677.284901004","TotalExposure":"190049.729075523","NumberOfMonth":"54","PaymentDate":"2019-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"19","PrincipalPayment":"7677.28490100446","InterestPayment":"2695.15927351505","CashFlow":"10372.4441745195","OutstandingExposure":"369076.43931587","CapitalAmountInDebt":"171999.999999999","TotalExposure":"182372.444174519","NumberOfMonth":"57","PaymentDate":"2019-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"20","PrincipalPayment":"171999.999999999","InterestPayment":"2579.99999999997","CashFlow":"174579.999999999","OutstandingExposure":"371656.43931587","CapitalAmountInDebt":"0","TotalExposure":"174579.999999999","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.0149999999999999"}]}

In this example we modify the SQL by adding a first payment date of 15-June-2015.

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             172000,       --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             NULL,         --@PrevPayDate

                             NULL,         --@StartDate

                             '2015-06-15', --@FirstPayDate

                             NULL,         --@GracePeriodStartDate

                             NULL          --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"6247.14006594731","InterestPayment":"4500","CashFlow":"15314.6400659472","OutstandingExposure":"304500","CapitalAmountInDebt":"293752.859934053","TotalExposure":"304500","NumberOfMonth":"6","PaymentDate":"2015-06-30 00:00:00.000","GraceInterest":"4567.49999999992","InterestRate":"0.0302249999999997"},{"Period":"2","PrincipalPayment":"6340.84716693652","InterestPayment":"4406.29289901079","CashFlow":"10747.1400659473","OutstandingExposure":"308906.292899011","CapitalAmountInDebt":"287412.012767116","TotalExposure":"298159.152833064","NumberOfMonth":"9","PaymentDate":"2015-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"6435.95987444057","InterestPayment":"4311.18019150674","CashFlow":"10747.1400659473","OutstandingExposure":"313217.473090518","CapitalAmountInDebt":"280976.052892676","TotalExposure":"291723.192958623","NumberOfMonth":"12","PaymentDate":"2015-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"6532.49927255718","InterestPayment":"4214.64079339013","CashFlow":"10747.1400659473","OutstandingExposure":"317432.113883908","CapitalAmountInDebt":"274443.553620118","TotalExposure":"285190.693686066","NumberOfMonth":"15","PaymentDate":"2016-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"6630.48676164553","InterestPayment":"4116.65330430178","CashFlow":"10747.1400659473","OutstandingExposure":"321548.767188209","CapitalAmountInDebt":"267813.066858473","TotalExposure":"278560.20692442","NumberOfMonth":"18","PaymentDate":"2016-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"6729.94406307022","InterestPayment":"4017.19600287709","CashFlow":"10747.1400659473","OutstandingExposure":"325565.963191087","CapitalAmountInDebt":"261083.122795403","TotalExposure":"271830.26286135","NumberOfMonth":"21","PaymentDate":"2016-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"6830.89322401627","InterestPayment":"3916.24684193104","CashFlow":"10747.1400659473","OutstandingExposure":"329482.210033018","CapitalAmountInDebt":"254252.229571386","TotalExposure":"264999.369637334","NumberOfMonth":"24","PaymentDate":"2016-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"6933.35662237651","InterestPayment":"3813.7834435708","CashFlow":"10747.1400659473","OutstandingExposure":"333295.993476588","CapitalAmountInDebt":"247318.87294901","TotalExposure":"258066.013014957","NumberOfMonth":"27","PaymentDate":"2017-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"7037.35697171216","InterestPayment":"3709.78309423515","CashFlow":"10747.1400659473","OutstandingExposure":"337005.776570824","CapitalAmountInDebt":"240281.515977298","TotalExposure":"251028.656043245","NumberOfMonth":"30","PaymentDate":"2017-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"7142.91732628784","InterestPayment":"3604.22273965947","CashFlow":"10747.1400659473","OutstandingExposure":"340609.999310483","CapitalAmountInDebt":"233138.59865101","TotalExposure":"243885.738716957","NumberOfMonth":"33","PaymentDate":"2017-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"7250.06108618216","InterestPayment":"3497.07897976515","CashFlow":"10747.1400659473","OutstandingExposure":"344107.078290248","CapitalAmountInDebt":"225888.537564828","TotalExposure":"236635.677630775","NumberOfMonth":"36","PaymentDate":"2017-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"7358.81200247489","InterestPayment":"3388.32806347242","CashFlow":"10747.1400659473","OutstandingExposure":"347495.406353721","CapitalAmountInDebt":"218529.725562353","TotalExposure":"229276.8656283","NumberOfMonth":"39","PaymentDate":"2018-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"13","PrincipalPayment":"7469.19418251201","InterestPayment":"3277.94588343529","CashFlow":"10747.1400659473","OutstandingExposure":"350773.352237156","CapitalAmountInDebt":"211060.531379841","TotalExposure":"221807.671445788","NumberOfMonth":"42","PaymentDate":"2018-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"14","PrincipalPayment":"7581.23209524969","InterestPayment":"3165.90797069761","CashFlow":"10747.1400659473","OutstandingExposure":"353939.260207853","CapitalAmountInDebt":"203479.299284591","TotalExposure":"214226.439350539","NumberOfMonth":"45","PaymentDate":"2018-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"7694.95057667844","InterestPayment":"3052.18948926887","CashFlow":"10747.1400659473","OutstandingExposure":"356991.449697122","CapitalAmountInDebt":"195784.348707913","TotalExposure":"206531.48877386","NumberOfMonth":"48","PaymentDate":"2018-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"7810.37483532861","InterestPayment":"2936.76523061869","CashFlow":"10747.1400659473","OutstandingExposure":"359928.214927741","CapitalAmountInDebt":"187973.973872584","TotalExposure":"198721.113938531","NumberOfMonth":"51","PaymentDate":"2019-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"17","PrincipalPayment":"7927.53045785854","InterestPayment":"2819.60960808876","CashFlow":"10747.1400659473","OutstandingExposure":"362747.82453583","CapitalAmountInDebt":"180046.443414726","TotalExposure":"190793.583480673","NumberOfMonth":"54","PaymentDate":"2019-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"18","PrincipalPayment":"8046.44341472642","InterestPayment":"2700.69665122088","CashFlow":"10747.1400659473","OutstandingExposure":"365448.521187051","CapitalAmountInDebt":"171999.999999999","TotalExposure":"182747.140065946","NumberOfMonth":"57","PaymentDate":"2019-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"19","PrincipalPayment":"171999.999999999","InterestPayment":"2579.99999999997","CashFlow":"174579.999999999","OutstandingExposure":"368028.521187051","CapitalAmountInDebt":"0","TotalExposure":"174579.999999999","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.0149999999999999"}]}

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

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             172000,       --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             NULL,         --@PrevPayDate

                             NULL,         --@StartDate

                             '2015-06-15', --@FirstPayDate

                             '2018-01-01', --@GracePeriodStartDate

                             '2019-01-01'  --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"7672.87752393459","InterestPayment":"4500","CashFlow":"16740.3775239345","OutstandingExposure":"304500","CapitalAmountInDebt":"292327.122476065","TotalExposure":"304500","NumberOfMonth":"6","PaymentDate":"2015-06-30 00:00:00.000","GraceInterest":"4567.49999999992","InterestRate":"0.0302249999999997"},{"Period":"2","PrincipalPayment":"7787.9706867936","InterestPayment":"4384.90683714098","CashFlow":"12172.8775239346","OutstandingExposure":"308884.906837141","CapitalAmountInDebt":"284539.151789272","TotalExposure":"296712.029313206","NumberOfMonth":"9","PaymentDate":"2015-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"7904.79024709551","InterestPayment":"4268.08727683908","CashFlow":"12172.8775239346","OutstandingExposure":"313152.99411398","CapitalAmountInDebt":"276634.361542176","TotalExposure":"288807.239066111","NumberOfMonth":"12","PaymentDate":"2015-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"8023.36210080194","InterestPayment":"4149.51542313264","CashFlow":"12172.8775239346","OutstandingExposure":"317302.509537113","CapitalAmountInDebt":"268610.999441374","TotalExposure":"280783.876965309","NumberOfMonth":"15","PaymentDate":"2016-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"8143.71253231397","InterestPayment":"4029.16499162061","CashFlow":"12172.8775239346","OutstandingExposure":"321331.674528733","CapitalAmountInDebt":"260467.28690906","TotalExposure":"272640.164432995","NumberOfMonth":"18","PaymentDate":"2016-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"8265.86822029867","InterestPayment":"3907.0093036359","CashFlow":"12172.8775239346","OutstandingExposure":"325238.683832369","CapitalAmountInDebt":"252201.418688762","TotalExposure":"264374.296212696","NumberOfMonth":"21","PaymentDate":"2016-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"8389.85624360315","InterestPayment":"3783.02128033143","CashFlow":"12172.8775239346","OutstandingExposure":"329021.705112701","CapitalAmountInDebt":"243811.562445159","TotalExposure":"255984.439969093","NumberOfMonth":"24","PaymentDate":"2016-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"8515.7040872572","InterestPayment":"3657.17343667738","CashFlow":"12172.8775239346","OutstandingExposure":"332678.878549378","CapitalAmountInDebt":"235295.858357901","TotalExposure":"247468.735881836","NumberOfMonth":"27","PaymentDate":"2017-03-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"8643.43964856606","InterestPayment":"3529.43787536852","CashFlow":"12172.8775239346","OutstandingExposure":"336208.316424747","CapitalAmountInDebt":"226652.418709335","TotalExposure":"238825.29623327","NumberOfMonth":"30","PaymentDate":"2017-06-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"8773.09124329455","InterestPayment":"3399.78628064003","CashFlow":"12172.8775239346","OutstandingExposure":"339608.102705387","CapitalAmountInDebt":"217879.327466041","TotalExposure":"230052.204989975","NumberOfMonth":"33","PaymentDate":"2017-09-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"8904.68761194397","InterestPayment":"3268.18991199061","CashFlow":"12172.8775239346","OutstandingExposure":"342876.292617377","CapitalAmountInDebt":"208974.639854097","TotalExposure":"221147.517378031","NumberOfMonth":"36","PaymentDate":"2017-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"9038.25792612312","InterestPayment":"3134.61959781145","CashFlow":"22965.1749461134","OutstandingExposure":"346010.912215189","CapitalAmountInDebt":"199936.381927974","TotalExposure":"212109.259451908","NumberOfMonth":"49","PaymentDate":"2019-01-31 00:00:00.000","GraceInterest":"10792.2974221788","InterestRate":"0.066644053219634"},{"Period":"13","PrincipalPayment":"9173.83179501497","InterestPayment":"2999.0457289196","CashFlow":"12172.8775239346","OutstandingExposure":"349009.957944108","CapitalAmountInDebt":"190762.550132959","TotalExposure":"202935.427656893","NumberOfMonth":"52","PaymentDate":"2019-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"14","PrincipalPayment":"9311.43927194019","InterestPayment":"2861.43825199438","CashFlow":"12172.8775239346","OutstandingExposure":"351871.396196103","CapitalAmountInDebt":"181451.110861018","TotalExposure":"193623.988384953","NumberOfMonth":"55","PaymentDate":"2019-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"9451.1108610193","InterestPayment":"2721.76666291528","CashFlow":"12172.8775239346","OutstandingExposure":"354593.162859018","CapitalAmountInDebt":"171999.999999999","TotalExposure":"184172.877523934","NumberOfMonth":"58","PaymentDate":"2019-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"171999.999999999","InterestPayment":"1715.72841831479","CashFlow":"173715.728418314","OutstandingExposure":"356308.891277333","CapitalAmountInDebt":"0","TotalExposure":"173715.728418314","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.00997516522276043"}]}

In the example we modify the SQL by changing the @FirstPayDate to NULL and @PrevPayDate to '2014-11-15', so the the first payment date will be calculated using a previous payment date.

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             172000,       --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             '2014-11-15', --@PrevPayDate

                             NULL,         --@StartDate

                             NULL,         --@FirstPayDate

                             '2018-01-01', --@GracePeriodStartDate

                             '2019-01-01'  --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"7137.9299622016","InterestPayment":"4500","CashFlow":"11637.9299622016","OutstandingExposure":"304500","CapitalAmountInDebt":"292862.070037798","TotalExposure":"304500","NumberOfMonth":"2","PaymentDate":"2015-02-28 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"2","PrincipalPayment":"7244.99891163462","InterestPayment":"4392.93105056698","CashFlow":"11637.9299622016","OutstandingExposure":"308892.931050567","CapitalAmountInDebt":"285617.071126164","TotalExposure":"297255.001088365","NumberOfMonth":"5","PaymentDate":"2015-05-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"7353.67389530914","InterestPayment":"4284.25606689246","CashFlow":"11637.9299622016","OutstandingExposure":"313177.187117459","CapitalAmountInDebt":"278263.397230855","TotalExposure":"289901.327193056","NumberOfMonth":"8","PaymentDate":"2015-08-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"7463.97900373878","InterestPayment":"4173.95095846282","CashFlow":"11637.9299622016","OutstandingExposure":"317351.138075922","CapitalAmountInDebt":"270799.418227116","TotalExposure":"282437.348189317","NumberOfMonth":"11","PaymentDate":"2015-11-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"7575.93868879485","InterestPayment":"4061.99127340674","CashFlow":"11637.9299622016","OutstandingExposure":"321413.129349329","CapitalAmountInDebt":"263223.479538321","TotalExposure":"274861.409500523","NumberOfMonth":"14","PaymentDate":"2016-02-29 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"7689.57776912678","InterestPayment":"3948.35219307481","CashFlow":"11637.9299622016","OutstandingExposure":"325361.481542404","CapitalAmountInDebt":"255533.901769194","TotalExposure":"267171.831731396","NumberOfMonth":"17","PaymentDate":"2016-05-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"7804.92143566368","InterestPayment":"3833.00852653791","CashFlow":"11637.9299622016","OutstandingExposure":"329194.490068942","CapitalAmountInDebt":"247728.980333531","TotalExposure":"259366.910295732","NumberOfMonth":"20","PaymentDate":"2016-08-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"7921.99525719863","InterestPayment":"3715.93470500296","CashFlow":"11637.9299622016","OutstandingExposure":"332910.424773945","CapitalAmountInDebt":"239806.985076332","TotalExposure":"251444.915038533","NumberOfMonth":"23","PaymentDate":"2016-11-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"8040.82518605661","InterestPayment":"3597.10477614498","CashFlow":"11637.9299622016","OutstandingExposure":"336507.52955009","CapitalAmountInDebt":"231766.159890275","TotalExposure":"243404.089852477","NumberOfMonth":"26","PaymentDate":"2017-02-28 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"8161.43756384746","InterestPayment":"3476.49239835413","CashFlow":"11637.9299622016","OutstandingExposure":"339984.021948444","CapitalAmountInDebt":"223604.722326428","TotalExposure":"235242.652288629","NumberOfMonth":"29","PaymentDate":"2017-05-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"8283.85912730517","InterestPayment":"3354.07083489642","CashFlow":"11637.9299622016","OutstandingExposure":"343338.09278334","CapitalAmountInDebt":"215320.863199123","TotalExposure":"226958.793161324","NumberOfMonth":"32","PaymentDate":"2017-08-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"8408.11701421475","InterestPayment":"3229.81294798684","CashFlow":"11637.9299622016","OutstandingExposure":"346567.905731327","CapitalAmountInDebt":"206912.746184908","TotalExposure":"218550.676147109","NumberOfMonth":"35","PaymentDate":"2017-11-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"13","PrincipalPayment":"8534.23876942797","InterestPayment":"3103.69119277362","CashFlow":"23421.7820578452","OutstandingExposure":"349671.596924101","CapitalAmountInDebt":"198378.50741548","TotalExposure":"210016.437377681","NumberOfMonth":"49","PaymentDate":"2019-01-31 00:00:00.000","GraceInterest":"11783.8520956436","InterestRate":"0.0719508274038996"},{"Period":"14","PrincipalPayment":"8662.25235096939","InterestPayment":"2975.6776112322","CashFlow":"11637.9299622016","OutstandingExposure":"352647.274535333","CapitalAmountInDebt":"189716.255064511","TotalExposure":"201354.185026712","NumberOfMonth":"52","PaymentDate":"2019-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"8792.18613623393","InterestPayment":"2845.74382596766","CashFlow":"11637.9299622016","OutstandingExposure":"355493.0183613","CapitalAmountInDebt":"180924.068928277","TotalExposure":"192561.998890478","NumberOfMonth":"55","PaymentDate":"2019-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"8924.06892827744","InterestPayment":"2713.86103392415","CashFlow":"11637.9299622016","OutstandingExposure":"358206.879395225","CapitalAmountInDebt":"171999.999999999","TotalExposure":"183637.929962201","NumberOfMonth":"58","PaymentDate":"2019-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"17","PrincipalPayment":"171999.999999999","InterestPayment":"1715.72841831479","CashFlow":"173715.728418314","OutstandingExposure":"359922.607813539","CapitalAmountInDebt":"0","TotalExposure":"173715.728418314","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.00997516522276043"}]}

In this SQL, we eliminate the grace period and the previous payment date and add a start date.

SELECT *

FROM wct.ConstantCashFlow(   300000,       --@OutstandingAmount

                             172000,       --@LastPrinPayAmount

                             .06,          --@InterestRate

                             3,            --@PaymentFrequency

                             '2019-12-15', --@MaturityDate

                             '2014-12-15', --@ReferenceDate

                             NULL,         --@PrevPayDate

                             '2014-10-15', --@StartDate

                             NULL,         --@FirstPayDate

                             NULL,         --@GracePeriodStartDate

                             NULL          --@GracePeriodEndDate

                         );

This produces the following result.

{"columns":[{"field":"Period","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PrincipalPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestPayment","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CashFlow","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"OutstandingExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"CapitalAmountInDebt","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"TotalExposure","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"NumberOfMonth","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"PaymentDate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GraceInterest","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"InterestRate","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Period":"0","PrincipalPayment":"0","InterestPayment":"0","CashFlow":"0","OutstandingExposure":"300000","CapitalAmountInDebt":"300000","TotalExposure":"300000","NumberOfMonth":"0","PaymentDate":"2014-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0"},{"Period":"1","PrincipalPayment":"5535.45419193173","InterestPayment":"4500","CashFlow":"10035.4541919317","OutstandingExposure":"304500","CapitalAmountInDebt":"294464.545808068","TotalExposure":"304500","NumberOfMonth":"1","PaymentDate":"2015-01-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"2","PrincipalPayment":"5618.4860048107","InterestPayment":"4416.96818712102","CashFlow":"10035.4541919317","OutstandingExposure":"308916.968187121","CapitalAmountInDebt":"288846.059803258","TotalExposure":"298881.513995189","NumberOfMonth":"4","PaymentDate":"2015-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"3","PrincipalPayment":"5702.76329488286","InterestPayment":"4332.69089704886","CashFlow":"10035.4541919317","OutstandingExposure":"313249.65908417","CapitalAmountInDebt":"283143.296508375","TotalExposure":"293178.750700306","NumberOfMonth":"7","PaymentDate":"2015-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"4","PrincipalPayment":"5788.30474430611","InterestPayment":"4247.14944762562","CashFlow":"10035.4541919317","OutstandingExposure":"317496.808531796","CapitalAmountInDebt":"277354.991764069","TotalExposure":"287390.445956","NumberOfMonth":"10","PaymentDate":"2015-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"5","PrincipalPayment":"5875.1293154707","InterestPayment":"4160.32487646103","CashFlow":"10035.4541919317","OutstandingExposure":"321657.133408257","CapitalAmountInDebt":"271479.862448598","TotalExposure":"281515.31664053","NumberOfMonth":"13","PaymentDate":"2016-01-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"6","PrincipalPayment":"5963.25625520276","InterestPayment":"4072.19793672897","CashFlow":"10035.4541919317","OutstandingExposure":"325729.331344985","CapitalAmountInDebt":"265516.606193395","TotalExposure":"275552.060385327","NumberOfMonth":"16","PaymentDate":"2016-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"7","PrincipalPayment":"6052.7050990308","InterestPayment":"3982.74909290093","CashFlow":"10035.4541919317","OutstandingExposure":"329712.080437886","CapitalAmountInDebt":"259463.901094364","TotalExposure":"269499.355286296","NumberOfMonth":"19","PaymentDate":"2016-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"8","PrincipalPayment":"6143.49567551626","InterestPayment":"3891.95851641547","CashFlow":"10035.4541919317","OutstandingExposure":"333604.038954302","CapitalAmountInDebt":"253320.405418848","TotalExposure":"263355.85961078","NumberOfMonth":"22","PaymentDate":"2016-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"9","PrincipalPayment":"6235.648110649","InterestPayment":"3799.80608128272","CashFlow":"10035.4541919317","OutstandingExposure":"337403.845035585","CapitalAmountInDebt":"247084.757308199","TotalExposure":"257120.211500131","NumberOfMonth":"25","PaymentDate":"2017-01-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"10","PrincipalPayment":"6329.18283230874","InterestPayment":"3706.27135962299","CashFlow":"10035.4541919317","OutstandingExposure":"341110.116395208","CapitalAmountInDebt":"240755.57447589","TotalExposure":"250791.028667822","NumberOfMonth":"28","PaymentDate":"2017-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"11","PrincipalPayment":"6424.12057479337","InterestPayment":"3611.33361713836","CashFlow":"10035.4541919317","OutstandingExposure":"344721.450012346","CapitalAmountInDebt":"234331.453901097","TotalExposure":"244366.908093029","NumberOfMonth":"31","PaymentDate":"2017-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"12","PrincipalPayment":"6520.48238341527","InterestPayment":"3514.97180851646","CashFlow":"10035.4541919317","OutstandingExposure":"348236.421820862","CapitalAmountInDebt":"227810.971517682","TotalExposure":"237846.425709614","NumberOfMonth":"34","PaymentDate":"2017-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"13","PrincipalPayment":"6618.28961916649","InterestPayment":"3417.16457276523","CashFlow":"10035.4541919317","OutstandingExposure":"351653.586393628","CapitalAmountInDebt":"221192.681898515","TotalExposure":"231228.136090447","NumberOfMonth":"37","PaymentDate":"2018-01-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"14","PrincipalPayment":"6717.56396345399","InterestPayment":"3317.89022847773","CashFlow":"10035.4541919317","OutstandingExposure":"354971.476622105","CapitalAmountInDebt":"214475.117935061","TotalExposure":"224510.572126993","NumberOfMonth":"40","PaymentDate":"2018-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"15","PrincipalPayment":"6818.3274229058","InterestPayment":"3217.12676902592","CashFlow":"10035.4541919317","OutstandingExposure":"358188.603391131","CapitalAmountInDebt":"207656.790512156","TotalExposure":"217692.244704087","NumberOfMonth":"43","PaymentDate":"2018-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"16","PrincipalPayment":"6920.60233424939","InterestPayment":"3114.85185768233","CashFlow":"10035.4541919317","OutstandingExposure":"361303.455248814","CapitalAmountInDebt":"200736.188177906","TotalExposure":"210771.642369838","NumberOfMonth":"46","PaymentDate":"2018-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"17","PrincipalPayment":"7024.41136926313","InterestPayment":"3011.04282266859","CashFlow":"10035.4541919317","OutstandingExposure":"364314.498071482","CapitalAmountInDebt":"193711.776808643","TotalExposure":"203747.231000575","NumberOfMonth":"49","PaymentDate":"2019-01-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"18","PrincipalPayment":"7129.77753980207","InterestPayment":"2905.67665212964","CashFlow":"10035.4541919317","OutstandingExposure":"367220.174723612","CapitalAmountInDebt":"186581.999268841","TotalExposure":"196617.453460773","NumberOfMonth":"52","PaymentDate":"2019-04-30 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"19","PrincipalPayment":"7236.7242028991","InterestPayment":"2798.72998903261","CashFlow":"10035.4541919317","OutstandingExposure":"370018.904712644","CapitalAmountInDebt":"179345.275065942","TotalExposure":"189380.729257874","NumberOfMonth":"55","PaymentDate":"2019-07-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"20","PrincipalPayment":"7345.27506594259","InterestPayment":"2690.17912598913","CashFlow":"10035.4541919317","OutstandingExposure":"372709.083838634","CapitalAmountInDebt":"171999.999999999","TotalExposure":"182035.454191931","NumberOfMonth":"58","PaymentDate":"2019-10-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.015"},{"Period":"21","PrincipalPayment":"171999.999999999","InterestPayment":"1715.72841831479","CashFlow":"173715.728418314","OutstandingExposure":"374424.812256948","CapitalAmountInDebt":"0","TotalExposure":"173715.728418314","NumberOfMonth":"60","PaymentDate":"2019-12-31 00:00:00.000","GraceInterest":"0","InterestRate":"0.00997516522276043"}]}

See Also

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

BULLET - Schedule with single interest and principal payment at maturity

CONSTANTPAYMENTAMOUNT - Schedule with no maturity with fixed periodic payment amount

CONSTANTPRINCIPAL - Schedule with fixed maturity date where the periodic principal payment is calculated on a straight-line basis

CONSTANTPRINCIPALAMOUNT - Schedule with no fixed maturity with a fixed periodic principal payment

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