STEPMDURATION
Updated: 21 April 2014
Use STEPMDURATION to calculate the modified duration for a steppedcoupon bond. Modified duration is calculated as the first derivative of the price with respect to yield multiplied by 1 divided by the dirty price of the bond.
Syntax
SELECT [wctFinancial].[wct].[STEPMDURATION](
<@Settlement, datetime,>
,<@Maturity, datetime,>
,<@Yld, float,>
,<@Redemption, float,>
,<@Frequency, float,>
,<@Basis, nvarchar(4000),>
,<@Coupons, nvarchar(max),>)
Arguments
@Settlement
the settlement date occurring within the coupon period of the bond. @Settlement is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@Maturity
the maturity date of the bond. @Settlement is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@Yld
the yield for the maturity date passed into the function. @Yld is an expression of type float or of a type that can be implicitly converted to float.
@Redemption
the redemption value of the bond assuming a 100 par 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 semiannual, @Frequency = 2; for quarterly, @Frequency = 4; for monthly @Frequency = 12. @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 or omitted

US (NASD) 30/360

1

Actual/Actual

2

Actual/360

3

Actual/365

4

European 30/360

@Coupons
a SELECT statement, as a string, which identifies the coupon dates and rates to be used in the modified duration calculation. The coupon rate is assumed to be in effect from the associated coupon date to the next greater coupon date returned by the SELECT statement. The last rate is assumed to be in effect from the last date until the maturity date of the bond.
Return Type
float
Remarks
Â· If @Basis < 0 or @Basis > 4, STEPMDURATION returns an error.
Â· If @Maturity < @Settlement 0 is returned.
Â· If @Settlement is NULL, @Settlement = GETDATE()
Â· If @Frequency is NULL, @Frequency = 2
Â· If @Basis is NULL, @Basis = 0.
Â· If @Coupons is empty or NULL then coupon rate is assumed to be zero.
Â· Accrued interest is calculated from the previous coupon date to the settlement date.
Â· Previous coupon date is calculated backwards from the maturity date. If the maturity date is the last day of the month, all the previous coupon dates are assumed to occur on the last day of the month.
Â· Previous coupon date <= @Settlement < next coupon date
Examples
In this example we calculate the modified duration for a bond maturing on 20190115 with the following stepup schedule.
20100115

5.0%

20130115

5.5%

20160115

6.0%

The settlement date is April 21, 2014, the yield is 4.0% and the redemption value is 100.
SELECT wct.STEPMDURATION(
'20140421', @Settlement
'20190115', @Maturity
.04, @Yld
100, @Redemption
2, @Frequency
0, @Basis
'SELECT wct.CALCDATE(2010,1,15),0.05 UNION ALL
SELECT wct.CALCDATE(2013,1,15),0.055 UNION ALL
SELECT wct.CALCDATE(2016,1,15),0.06' @Coupons
) as MDURATION
This produces the following result
MDURATION

4.10281510005374
The SELECT statement in @Coupons can make reference to another table, as in the following example.
SELECT
*
INTO
#coups
FROM (
SELECT '2010115',0.05 UNION ALL
SELECT '2013115',0.055 UNION ALL
SELECT '20161,15',0.06
)n(coupdate, couprate)
SELECT wct.STEPMDURATION(
'20140421', @Settlement
'20190115', @Maturity
.04, @Yld
100, @Redemption
2, @Frequency
0, @Basis
'SELECT *FROM #coups' @Coupons
) as MDURATION
This produces the following result.
MDURATION

4.10281510005374
In this example we have multiple securities with different stepup schedules and we only have the prices which need to be converted to yields for input into the modified duration calculation. For purposes of this example, the coupon schedules are stored in a temporary table, #coups.
SELECT
*
INTO
#coups
FROM (
SELECT 'ABC', '20100115', 0.050 UNION ALL
SELECT 'ABC', '20130115', 0.055 UNION ALL
SELECT 'ABC', '20160115', 0.060 UNION ALL
SELECT 'GHI', '20310722', 0.070 UNION ALL
SELECT 'GHI', '20260722', 0.0675 UNION ALL
SELECT 'GHI', '20210722', 0.0650 UNION ALL
SELECT 'GHI', '20160722', 0.0625 UNION ALL
SELECT 'GHI', '20110722', 0.0600 UNION ALL
SELECT 'XYZ', '20230301', 0.0600 UNION ALL
SELECT 'XYZ', '20190301', 0.0575 UNION ALL
SELECT 'XYZ', '2015031', 0.0550 UNION ALL
SELECT 'XYZ', '2011031', 0.0
)c(secid, coupdate, couprate)
SELECT
secid
,wct.STEPMDURATION(
'20140421',
n.maturity,
wct.YIELDSTEP(
'20140421',
n.maturity,
n.price,
n.redemption,
n.frequency,
n.basis,
'SELECT
coupdate,
couprate
FROM
#coups
WHERE
secid = ' + '''' + n.secid + ''''
),
n.redemption,
n.frequency,
n.basis,
'SELECT
coupdate,
couprate
FROM
#coups
WHERE
secid = ' + '''' + n.secid + ''''
) as MDURATION
FROM (
SELECT 'ABC', '20190115', 103.670988, 100, 2, 0 UNION ALL
SELECT 'GHI', '20360722', 120.467994, 103, 2, 1 UNION ALL
SELECT 'XYZ', '20270301', 97.478325, 101, 1, 0
)n(secid, maturity, price, redemption, frequency, basis)
This produces the following result.
secid MDURATION
 
ABC 4.07150412595065
GHI 12.7833372835523
XYZ 9.43882394420961
See Also