Logo

SQL Server INTERPDFACT Function

Updated 2024-02-23 17:08:39.987000

Description

Use the table-valued-function INTERPDFACT to calculate interpolated discount factors for a range of dates. INTERPDFACT uses the following formula in its calculation.

df=df_1^{(1-\alpha)*d\slash{d_1}}*df_2^{\alpha*d\slash{d_2}
\alpha=\frac{d-d_1}{d_2-d_1}

Where

d = number of days from @StartDate to the interpolated date

d1 = number of days from @StartDate to the greatest discount factor date less than or equal to the interpolated date

d2 = number of days from @StartDate to the lowest discount factor date greater than the interpolated date

df1 discount factor for d1

df2 discount factor for d2

Syntax

SELECT * FROM [wctFinancial].[wct].[INTERPDFACT](
  <@InputData_RangeQuery, nvarchar(max),>
 ,<@iStartDate, datetime,>
 ,<@iEndDate, datetime,>
 ,<@Startdate, datetime,>)

Arguments

@InputData_RangeQuery

a T-SQL statement, as a string, that specifies the discount factors and their associated dates.

@iStartDate

the start date of the interpolation date range. @iStartDate must be of the type datetime or of a type that implicitly converts to datetime.

@iEndDate

the end date of the interpolation date range. @iEndDate must be of the type datetime or of a type that implicitly converts to datetime.

@Startdate

the starting date used in the calculation of the discount factors. @StartDate must be of the type datetime or of a type that implicitly converts to datetime.

Return Type

table

colNamecolDatatypecolDesc
vDatedatetimeThe interpolated date.
DFfloatDiscount factor.
ZCfloatZero coupon rate.
CCfloatContinuously compounded zero coupon rate.

Remarks

The function is insensitive to order; it does not matter what order the dates and rates are passed in.

If @StartDate is NULL, it defaults to GETDATE().

If @iStartDate and @iEndDate are NULL, then the function will return the interpolated discount factor for every date from the start of the yield curve to the end.

Examples

SELECT cast(dfdate as datetime) as dfdate,
       df
INTO   #x
  FROM (   SELECT '2013-01-16',
                  0.999995555575309
           UNION ALL
           SELECT '2013-01-17',
                  0.99999111117037
           UNION ALL
           SELECT '2013-01-24',
                  0.999956112706425
           UNION ALL
           SELECT '2013-01-31',
                  0.999916450742048
           UNION ALL
           SELECT '2013-02-18',
                  0.999804481000583
           UNION ALL
           SELECT '2013-03-18',
                  0.999574621744643
           UNION ALL
           SELECT '2013-04-17',
                  0.999241679910437
           UNION ALL
           SELECT '2013-06-19',
                  0.998800609148515
           UNION ALL
           SELECT '2013-09-18',
                  0.998022836090921
           UNION ALL
           SELECT '2013-12-18',
                  0.997197057207847
           UNION ALL
           SELECT '2014-03-19',
                  0.996311568695976
           UNION ALL
           SELECT '2014-06-18',
                  0.995354720378904
           UNION ALL
           SELECT '2014-09-17',
                  0.994289565586446
           UNION ALL
           SELECT '2014-12-17',
                  0.993104681356623
           UNION ALL
           SELECT '2015-01-19',
                  0.992402694592988
           UNION ALL
           SELECT '2016-01-18',
                  0.98508478388398
           UNION ALL
           SELECT '2017-01-17',
                  0.973098042807202
           UNION ALL
           SELECT '2018-01-17',
                  0.955265832115111
           UNION ALL
           SELECT '2020-01-17',
                  0.906604451702898
           UNION ALL
           SELECT '2023-01-17',
                  0.820620615064395
           UNION ALL
           SELECT '2043-01-19',
                  0.385646181323946) n(dfdate, df);

SELECT *
  FROM wct.INTERPDFACT('SELECT dfdate, df FROM #x', --@InputData_RangeQuery
                       '2013-01-16', --@iStartDate
                       '2013-02-13', --@iEndDate
                       '2013-01-15' --@StartDate
    );

This produces the following result.

vDateDFZCCC
2013-01-160.9999955555753090.0016222186171510.001622222222071
2013-01-170.9999911111703700.0016222186173010.001622225827171
2013-01-180.9999864816283590.0016447463335180.001644757450800
2013-01-190.9999817286704870.0016672740497380.001667289281630
2013-01-200.9999768522985160.0016898017659560.001689821323847
2013-01-210.9999718525142490.0017123294821690.001712353581617
2013-01-220.9999667293195400.0017348571983880.001734886059131
2013-01-230.9999614827162840.0017573849146040.001757418760534
2013-01-240.9999561127064250.0017799126308220.001779951690026
2013-01-250.9999507428066880.0017979318367840.001797976119136
2013-01-260.9999452742058120.0018159510427430.001816000734693
2013-01-270.9999397069054150.0018339702487070.001834025539353
2013-01-280.9999340409071480.0018519894546670.001852050535799
2013-01-290.9999282762126880.0018700086606250.001870075726686
2013-01-300.9999224128237430.0018880278665860.001888101114699
2013-01-310.9999164507420480.0019060470725470.001906126702502
2013-02-010.9999107295084260.0019167755231700.001916861085282
2013-02-020.9999049495270940.0019275039737950.001927595586134
2013-02-030.9998991107990720.0019382324244170.001938330205998
2013-02-040.9998932133253880.0019489608750420.001949064945830
2013-02-050.9998872571070840.0019596893256650.001959799806567
2013-02-060.9998812421452080.0019704177762880.001970534789163
2013-02-070.9998751684408230.0019811462269120.001981269894563
2013-02-080.9998690359949980.0019918746775340.001992005123713
2013-02-090.9998628448088140.0020026031281590.002002740477565
2013-02-100.9998565948833640.0020133315787830.002013475957063
2013-02-110.9998502862197500.0020240600294050.002024211563149
2013-02-120.9998439188190840.0020347884800300.002034947296780
2013-02-130.9998374926824880.0020455169306520.002045683158898