SQL Server RPIFACTORS Function
Updated 2023-10-06 21:19:58.703000
Description
Use the table-valued function RPIFACTORS to return the components used in the calculation of price and yield for a bond with regular periodic coupons.
Syntax
SELECT * FROM [westclintech].[wct].[RPIFACTORS](
<@Settlement, datetime,>
,<@Maturity, datetime,>
,<@Rate, float,>
,<@Price, float,>
,<@Yield, float,>
,<@Redemption, float,>
,<@Frequency, float,>
,<@Basis, nvarchar(4000),>)
Arguments
@Settlement
the settlement date of the security. @Settlement is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@Maturity
the maturity date of the security. @Maturity is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@Rate
the security's annual coupon rate. @Rate is an expression of type float or of a type that can be implicitly converted to float.
@Price
the price of the bond. @Price is an expression of type float or of a type that can be implicitly converted to float.
@Yield
the security's annual yield. @Yld is an expression of type float or of a type that can be implicitly converted to float.
@Redemption
the security's redemption value per 100 face value. @Redemption is an expression of type float or of a type that can be implicitly converted to float.
@Frequency
the number of coupon payments per year. For annual payments, @Frequency = 1; for semi-annual, @Frequency = 2; for quarterly, @Frequency = 4; for bimonthly @Frequency = 6; for monthly, @Frequency = 12. For bonds with @Basis = 'A/364' or 9, you can enter 364 for payments made every 52 weeks, 182 for payments made every 26 weeks, 91 for payments made every 13 weeks, 28 for payments made every 4 weeks, 14 for payments made every 2 weeks, and 7 for weekly payments. @Frequency is an expression of type float or of a type that can be implicitly converted to float.
@Basis
is the type of day count to use. @Basis is an expression of the character string data type category.
| @Basis | Day count basis |
|---|---|
| 0 , 'BOND' | US (NASD) 30/360 |
| 1 , 'ACTUAL' | Actual/Actual |
| 2 , 'A360' | Actual/360 |
| 3 , 'A365' | Actual/365 |
| 4 , '30E/360 (ISDA)' , '30E/360' , 'ISDA' , '30E/360 ISDA' , 'EBOND' | European 30/360 |
| 5 , '30/360' , '30/360 ISDA' , 'GERMAN' | 30/360 ISDA |
| 6 , 'NL/ACT' | No Leap Year/ACT |
| 7 , 'NL/365' | No Leap Year /365 |
| 8 , 'NL/360' | No Leap Year /360 |
| 9 , 'A/364' | Actual/364 |
| 10 , 'BOND NON-EOM' | US (NASD) 30/360 non-end-of-month |
| 11 , 'ACTUAL NON-EOM' | Actual/Actual non-end-of-month |
| 12 , 'A360 NON-EOM' | Actual/360 non-end-of-month |
| 13 , 'A365 NON-EOM' | Actual/365 non-end-of-month |
| 14 , '30E/360 NON-EOM' , '30E/360 ICMA NON-EOM' , 'EBOND NON-EOM' | European 30/360 non-end-of-month |
| 15 , '30/360 NON-EOM' , '30/360 ISDA NON-EOM' , 'GERMAN NON-EOM' | 30/360 ISDA non-end-of-month |
| 16 , 'NL/ACT NON-EOM' | No Leap Year/ACT non-end-of-month |
| 17 , 'NL/365 NON-EOM' | No Leap Year/365 non-end-of-month |
| 18 , 'NL/360 NON-EOM' | No Leap Year/360 non-end-of-month |
| 19 , 'A/364 NON-EOM' | Actual/364 non-end-of-month |
Return Type
table
| colName | colDatatype | colDesc |
|---|---|---|
| Prevcoup | datetime | Greatest coupon date less than or equal to the settlement date. |
| NextCoup | datetime | Least coupon date greater than the settlement date. |
| A | float | Number of accrued days from the previous coupon date to the settlement date. |
| DSC | float | Number of days from the settlement date to the next coupon date. |
| E | float | Number of days in the coupon period. |
| N | int | Number of coupons from the settlement date to the maturity date |
| C | float | Coupon amount |
| P | float | Price. If @Yield is NOT NULL then P is calculated from the inputs otherwise P is the value entered in @Price. |
| AI | float | Accrued interest as of the settlement date. |
| Y | float | Yield. If @Yield is NOT NULL then Y is the value entered in @Yield otherwise Y is calculated from the inputs. |
Remarks
If @Settlement is NULL then @Settlement = GETDATE().
If @Rate is NULL then @Rate = 0.
If @Redemption is NULL then @Redemption = 100.
If @Frequency is NULL then @Frequency = 2.
If @Basis is NULL then @Basis = 0.
If @Frequency is any number other than 1, 2, 4, 6 or 12, or for @Basis = 'A/364' any number other than 1, 2, 4, 6 or 12 as well as 7, 14, 28, 91, 182 or 364 RPIFACTORS returns an error.
If @Basis invalid (see above list), RPIFACTORS returns an error.
If @Maturity is NULL then an error is returned.
DSC = E - A.
Examples
In this example we calculate the factors for a bond maturing on 2034-06-15. The settlement date is 2014-05-01, the yield is 2.76%, the coupon rate is 2.50%, the redemption value is 100, the coupon is paid twice-yearly, and the basis code is 1.
SELECT *
FROM wct.RPIFACTORS( '2014-05-01', --@Settlement
'2034-06-15', --@Maturity
0.025, --@Rate
NULL, --@Price
0.0276, --@Yield
100, --@Redemption
2, --@Frequency
1 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2013-12-15 00:00:00.000 | 2014-06-15 00:00:00.000 | 137 | 45 | 182 | 41 | 1.25 | 96.0043799057024 | 0.940934065934066 | 0.0276 |
In this example, we calculate the factors for a zero-coupon bond.
SELECT *
FROM wct.RPIFACTORS( '2014-05-01', --@Settlement
'2044-06-15', --@Maturity
0.00, --@Rate
NULL, --@Price
0.0301, --@Yield
100, --@Redemption
2, --@Frequency
1 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2013-12-15 00:00:00.000 | 2014-06-15 00:00:00.000 | 137 | 45 | 182 | 61 | 0 | 40.6583576113141 | 0 | 0.0301 |
In this example we calculate the factors for a bond settling in the final coupon period.
SELECT *
FROM wct.RPIFACTORS( '2014-05-01', --@Settlement
'2014-07-15', --@Maturity
0.0190, --@Rate
NULL, --@Price
0.0005, --@Yield
100, --@Redemption
2, --@Frequency
0 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2014-01-15 00:00:00.000 | 2014-07-15 00:00:00.000 | 106 | 74 | 180 | 1 | 0.95 | 100.380181205142 | 0.559444444444444 | 0.0005 |
Here we calculate the factors for a bond maturing on the 30th of September 2034, with semi-annual coupons payable on March 30th and September 30th.
SELECT *
FROM wct.RPIFACTORS( '2014-05-01', --@Settlement
'2034-09-30', --@Maturity
0.0257, --@Rate
98.123291, --@Price
NULL, --@Yield
100, --@Redemption
2, --@Frequency
11 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2014-03-30 00:00:00.000 | 2014-09-30 00:00:00.000 | 32 | 152 | 184 | 41 | 1.285 | 98.123291 | 0.223478260869565 | 0.0268999998648661 |
Here's an example with a negative yield.
SELECT *
FROM wct.RPIFACTORS( '2014-05-01', --@Settlement
'2014-09-30', --@Maturity
0.0257, --@Rate
101, --@Price
NULL, --@Yield
98, --@Redemption
2, --@Frequency
0 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2014-03-31 00:00:00.000 | 2014-09-30 00:00:00.000 | 31 | 149 | 180 | 1 | 1.285 | 101 | 0.221305555555556 | -0.0462187493233163 |
This is an example of a bond paying interest every 26 weeks.
SELECT *
FROM wct.RPIFACTORS( '2014-10-01', --@Settlement
'2023-03-13', --@Maturity
0.1250, --@Rate
NULL, --@Price
0.1100, --@Yield
100, --@Redemption
182, --@Frequency
9 --@Basis
);
This produces the following result.
| PrevCoup | NextCoup | A | DSC | E | N | C | P | AI | Y |
|---|---|---|---|---|---|---|---|---|---|
| 2014-09-22 00:00:00.000 | 2015-03-23 00:00:00.000 | 9 | 173 | 182 | 17 | 6.25 | 108.126105929164 | 0.309065934065934 | 0.11 |
See Also
BONDAMORT - Bond amortization schedule using constant effective daily interest method
BONDINT - Accrued interest on a bond paying regular, periodic interest
OFCFACTORS - Returns the components of the ODDFPRICE equation
PRICE - Price of a bond paying regular periodic interest
RPI - Calculate the price and/or yield of a bond with regular periodic coupons