Login     Register

        Contact Us     Search

XLeratorDB/financial Documentation

SQL Server IRR for MBS-type loans


CDRCashflowIRR

Updated: 28 Dec 2016

Use CDRCashflowIRR to calculate the internal rate of return on cash flows produced using the CDRCASHFLOW inputs. CDRCashflowIRR just returns the internal rate of return; if you want to explicitly produce the cash flows, use the CDRCASHFLOW table-valued function.
Syntax
SELECT [wct].[CDRCashflowIRR](
  <@PrinAmt, float,>
 ,<@InterestRate, float,>
 ,<@NumPmts, int,>
 ,<@LastPmtNum, int,>
 ,<@PmtPerYr, int,>
 ,<@LSRatesQuery, nvarchar(max),>
 ,<@CPRRatesQuery, nvarchar(max),>
 ,<@CDRRatesQuery, nvarchar(max),>
 ,<@InterestOnly, bit,>
 ,<@PrinPaymentMultiple, int,>
 ,<@FirstPrinPayNo, int,>
 ,<@PmtPayPct, float,>)
Arguments
@PrinAmt
the principal amount to be amortized. @PrinAmt is an expression of type float or of a type that can be implicitly converted to float.
@InterestRate
the annual rate of interest used to calculate the periodic payment. @InterestRate is an expression of type float or of a type that can be implicitly converted to float.
@NumPmts
the number of periods to be used in the calculation of the periodic payment. @NumPmts is an expression of type int or of a type that can be implicitly converted to int.
@LastPmtNum
the number of the last payment. Use @LastPmtNum for case where the number of payments for the annuity calculation is different than the actual number of payments, For example, an annuity based on 300 monthly payment which will be paid off at the end of 120 months. @LastPmtNum is an expression of type int or of a type that can be implicitly converted to int.
@PmtPerYr
the number of payments per year. @PmtPerYr is an expression of type int or of a type that can be implicitly converted to int.
@LSRatesQuery
a SELECT statement, as a string, which returns the month and loss severity rates to be used in the calculation of the loss severity amounts. @LSRatesQuery should return 2 columns, month and rate, where 1% = .01.
@CPRRatesQuery
a SELECT statement, as a string, which returns the month and prepayment rates to be used in the calculation of the principal prepayments. @CPRratesQuery should return 2 columns, month and rate, where 1% = .01.
@CDRRatesQuery
a SELECT statement, as a string, which returns the month and default rate to be used in the calculation of the default amounts. @CDRRatesQuery should return 2 columns, month and rate, where 1% = .01.
@InterestOnly
a bit value, which when true, identifies that the principal amount is scheduled to be repaid at the end of the loan.
@PrinPaymentMultiple
the ratio of the frequency of the interest payments to the frequency of the interest payments. For example, a loan with monthly payments of interest and quarterly payments of principal would have a @PrinPaymentMultiple of 3. @PrinPaymentMultiple is an expression of type int or of a type that can be implicitly converted to int.
@FirstPrinPayNo
the payment number of the first principal payment. @FirstPrinPayNo is an expression of type int or of a type that can be implicitly converted to int.
@PmtPayPct
a fixed percentage which is applied to the projected principal balance to calculate the projected principal payment. @PmtPayPct is of a type float or of a type that can be implicitly converted to float.
Return Type
float
Remarks
·         If @FirstPrinPayNo is NULL then @FirstPrinPayNo = 1.
·         If @PrinAmt is NULL then @PrinAmt = 0.
·         If @InterestRate is NULL then @InterestRate = 0.
·         If @NumPmts is NULL then @NumPmts = 0.
·         If @LastPmtNum is NULL then @LastPmtNum = @NumPmts.
·         If @InterestOnly is NULL then @InterestOnly = FALSE.
·         If @PrinPaymentMultiple is NULL then @PrinPaymentMultiple = 1.
·         If @FirstPrinPayNo is NULL then @FirstPrinPayNo = @PrinPaymentMultiple.
·         If @NumPmts < 1 then no rows are returned.
·         If @PrinPaymentMultiple < 1 then no rows are returned.
·         If @FirstPrinPayNo < 1 then no rows are returned.
·         @PmtPerYr must be 1, 2, 3, 4, 6, or 12.
·         If @LSRatesQuery returns NULL or no rows then LS is set to zero.
·         If @CDRRatesQuery returns NULL or no rows then CDR is set to zero.
·         If @CPRRatesQuery returns NULL or no rows then CPR is set to zero.
·         Available in XLeratorDB / financial 2008 only
Examples
Use the following CPR rates, which have been inserted into the #cpr table, for all of the examples.
SELECT * INTO #cpr FROM (VALUES
(1,0.002),(25,0.012),(61,0.02),(181,0.06))n(mth,rate)
Use the following CDR rates, which have been inserted into the #cdr table, for all of the examples.
SELECT * INTO #cdr FROM (VALUES
(1,0.1),(61,0.08),(181,0.05))n(mth,rate)
Use the following Loss Severity rates, which have been inserted into the #ls table, for all the examples.
SELECT * INTO #ls FROM (VALUES
(1,0.15),(91,0.16),(181,0.14),(271,0.17),(361,0.13))n(mth,rate)
Example #1
In this example we calculate the internal rate of return for a 100,000,000 loan with a 5% interest rate over 360 months using the data from the #ls, #cpr, and #cdr tables without modification.
SELECT wct.CDRCashflowIRR(
  100000000  --@PrinAmt
 ,0.05       --@InterestRate
 ,360        --@NumPmts
 ,NULL       --@LastPmtNum
 ,12         --@PmtPerYr
 ,'SELECT * FROM #ls'     --@LSRatesQuery
 ,'SELECT * FROM #cpr'    --@CPRRatesQuery
 ,'SELECT * FROM #cdr'    --@CDRRatesQuery
 ,NULL       --@InterestOnly
 ,NULL       --@PrinPaymentMultiple
 ,NULL       --@FirstPrinPayNo
 ,NULL       --@PmtPayPct
 ) as IRR
This produces the following result.
Example #2
In this example, we have a 10-year, 20,000,000 loan, with monthly payments calculated as though it were a 25-year loan.
SELECT wct.CDRCashflowIRR(
  20000000   --@PrinAmt
 ,0.05       --@InterestRate
 ,300        --@NumPmts
 ,120        --@LastPmtNum
 ,12         --@PmtPerYr
 ,'SELECT * FROM #ls'     --@LSRatesQuery
 ,'SELECT * FROM #cpr'    --@CPRRatesQuery
 ,'SELECT * FROM #cdr'    --@CDRRatesQuery
 ,NULL       --@InterestOnly
 ,NULL       --@PrinPaymentMultiple
 ,NULL       --@FirstPrinPayNo
 ,NULL       --@PmtPayPct
 ) as IRR
This produces the following result.
Example #3
In this example we have a 10-year, 25,000,000 interest-only loan with quarterly payments.
SELECT wct.CDRCashflowIRR(
  25000000   --@PrinAmt
 ,0.04       --@InterestRate
 ,40         --@NumPmts
 ,NULL       --@LastPmtNum
 ,4          --@PmtPerYr
 ,'SELECT * FROM #ls'     --@LSRatesQuery
 ,'SELECT * FROM #cpr'    --@CPRRatesQuery
 ,'SELECT * FROM #cdr'    --@CDRRatesQuery
 ,'True'     --@InterestOnly
 ,NULL       --@PrinPaymentMultiple
 ,NULL       --@FirstPrinPayNo
 ,NULL       --@PmtPayPct
 ) as IRR
This produces the following result.
Example #4
In this example we have a 10,000,000 loan with monthly payments of interest and quarterly payments of principal. The loan matures in 120 months.
SELECT wct.CDRCashflowIRR(
  10000000   --@PrinAmt
 ,0.06       --@InterestRate
 ,120        --@NumPmts
 ,NULL       --@LastPmtNum
 ,12         --@PmtPerYr
 ,'SELECT * FROM #ls'     --@LSRatesQuery
 ,'SELECT * FROM #cpr'    --@CPRRatesQuery
 ,'SELECT * FROM #cdr'    --@CDRRatesQuery
 ,NULL       --@InterestOnly
 ,3          --@PrinPaymentMultiple
 ,NULL       --@FirstPrinPayNo
 ,NULL       --@PmtPayPct
 ) as IRR
This produces the following result.
Example #5
This example uses the same loan as the previous loan, 1 month later.
SELECT wct.CDRCashflowIRR(
  10000000   --@PrinAmt
 ,0.06       --@InterestRate
 ,119        --@NumPmts
 ,NULL       --@LastPmtNum
 ,12         --@PmtPerYr
 ,'SELECT * FROM #ls'     --@LSRatesQuery
 ,'SELECT * FROM #cpr'    --@CPRRatesQuery
 ,'SELECT * FROM #cdr'    --@CDRRatesQuery
 ,NULL       --@InterestOnly
 ,3          --@PrinPaymentMultiple
 ,NULL       --@FirstPrinPayNo
 ,NULL       --@PmtPayPct
 ) as IRR
This produces the following result.
Example #6
This is an interest-only loan.
SELECT wct.CDRCashflowIRR(
    50000    --@PrinAmt
   ,.05      --@InterestRate
   ,36       --@NumPmts
   ,NULL     --@LastPmtNum
   ,12       --@PmtPerYr
   ,'SELECT * FROM #ls'    --@LSRatesQuery
   ,'SELECT * FROM #cpr'   --@CPRRatesQuery
   ,'SELECT * FROM #cdr'   --@CDRRatesQuery
   ,'TRUE'   --@InterestOnly
   ,NULL     --@PrinPaymentMultiple
   ,NULL     --@FirstPrinPayNo
   ,NULL     --@PmtPayPct
 ) as IRR
This produces the following result.
Example #7
In this loan the principal payment is a fixed percentage of the outstanding principal.
SELECT wct.CDRCashflowIRR(
    1000000  --@PrinAmt
   ,.18      --@InterestRate
   ,24       --@NumPmts
   ,NULL     --@LastPmtNum
   ,12       --@PmtPerYr
   ,'SELECT * FROM #ls'    --@LSRatesQuery
   ,'SELECT * FROM #cpr'   --@CPRRatesQuery
   ,'SELECT * FROM #cdr'   --@CDRRatesQuery
   ,NULL     --@InterestOnly
   ,NULL     --@PrinPaymentMultiple
   ,NULL     --@FirstPrinPayNo
   ,0.0100   --@PmtPayPct
 ) as IRR
This produces the following result.
Example #8
In this example we have a 30-year loan with interest-only payments for the first 7 years and fully-amortizing payments thereafter.
SELECT wct.CDRCashflowIRR(
    500000   --@PrinAmt
   ,.05      --@InterestRate
   ,360      --@NumPmts
   ,NULL     --@LastPmtNum
   ,12       --@PmtPerYr
   ,'SELECT * FROM #ls'    --@LSRatesQuery
   ,'SELECT * FROM #cpr'   --@CPRRatesQuery
   ,'SELECT * FROM #cdr'   --@CDRRatesQuery
   ,'False'  --@InterestOnly
   ,NULL     --@PrinPaymentMultiple
   ,85       --@FirstPrinPayNo
   ,NULL     --@PmtPayPct
 ) as IRR
This produces the following result.

 

See Also

 



Copyright 2008-2013 WestClinTech LLC         Privacy Policy        Terms of Service