Logo

SQL Server AIFACTOR Function

Updated 2023-10-06 11:52:14.687000

Description

Use the scalar-valued function AIFACTOR to calculate the Accrued Interest Factor. AIFACTOR returns a decimal value which can then be multiplied by the face amount of the bond to return the monetary value of the accrued interest.

Syntax

SELECT [wct].[AIFACTOR] (
  <@Basis, nvarchar(4000),>
 ,<@Rate, float,>
 ,<@Maturity, datetime,>
 ,<@Settlement, datetime,>
 ,<@Frequency, int,>
 ,<@FirstInterestDate, datetime,>
 ,<@LastInterestDate, datetime,>
 ,<@IssueDate, datetime,>
 ,<@Holidays, nvarchar(max),>);

Arguments

@Basis

the day-count convention used in the calculation of the accrued coupon interest. @Basis is an expression of the character string data type category.

@BasisDay count basis
0 or omittedUS (NASD) 30/360
1Actual/Actual
2Actual/360
3Actual/365
4European 30/360
530/360 ISDA
6NL/ACT
7NL/365
8NL/360
9A/364
10US (NASD) 30/360 non-end-of-month
11Actual/Actual non-end-of-month
12Actual/360 non-end-of-month
13Actual/365 non-end-of-month
14European 30/360 non-end-of-month
1530/360 ISDA non-end-of-month
16NL/ACT non-end-of-month
17NL/365 non-end-of-month
18NL/360 non-end-of-month
19A/364 non-end-of-month
20BUS/252
21Actual/ISDA
22Actual/ISMA
23Actual/365L
24Actual/AFB
30BUS/252 non-end-of-month

@Rate

the coupon rate, as a decimal, for the financial instrument. @Rate is an expression of type float or of a type that can be implicitly converted to float.

@Maturity

the maturity date for the financial instrument. @Maturity is an expression of type datetime or of a type that can be implicitly converted to datetime.

@Settlement

the settlement date of the transaction. @Settlement is an expression of type datetime or of a type that can be implicitly converted to datetime.

@Frequency

the number of coupon payments per year. For annual payments, @Frequency = 1; for semi-annual, @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.

@FirstInterestDate

the first coupon date of the security. The period from the issue date until the first coupon date defines the odd first interest period. All subsequent coupon dates are assumed to occur at regular periodic intervals as defined by @Frequency in relation to the @LastInterestDate (if entered) or @Maturity. @FirstInterestDate is an expression of type datetime or of a type that can be implicitly converted to datetime.

@LastInterestDate

the last coupon date of the security prior to maturity date, if the last coupon period is an odd period. The period from the last interest date date until the maturity date defines the odd last interest period. All previous coupon dates are assumed to occur at regular periodic intervals as defined by @Frequency. @LastInterestDate is an expression of type datetime or of a type that can be implicitly converted to datetime.

@IssueDate

the issue date of the security; the date from which the security starts accruing interest. @IssueDate is an expression of type datetime or of a type that can be implicitly converted to datetime. ### @Holidays a comma separated string containing the holiday (non-business) dates to be used in the calculation of the number of business days. You can use the aggregate function NBD to create an appropriately formatted string.

Return Type

float

Remarks

If @Basis IS NULL, then @Basis = '0'.

For bonds with regular period coupons, coupon dates are calculated backwards from @Maturity.

For bonds with an odd first coupon period, settling in the odd period, the coupon dates are calculated backward from @FirstInterestDate.

Odd first coupon bonds with @Settlement >= @FirstInterestDate and no @LastInterestDate are treated as regular periodic bonds.

If the last interest date is not NULL and the settlement date is less than the @LastInterestDate and greater than or equal to the @FirstInterestDate or @FirstInterestDate IS NULL, than the coupon dates are calculated backwards from @LastInterestDate.

If the @LastInterestDate IS NOT NULL and @Settlement >= @LastInterestDate then coupon dates are calculated from the quasi-maturity date, which is calculated forward from @LastInterestDate.

Examples

Calculate the accrued interest factor for a bond with a coupon rate of 5% paying coupons semi-annually, with a Maturity Date of 2012-05-15 and a settlement date of 2012-02-15.

SELECT wct.AIFACTOR(   '0',          --Basis
                       .05,          --Rate
                       '2012-05-15', --Maturity
                       '2012-02-15', --Settlement
                       2,            --Frequency
                       NULL,         --FirstInterestDate
                       NULL,         --LastInterestDate
                       NULL,         --IssueDate
                       NULL          --Holidays
                   ) as AIFACTOR;

This produces the following result.

AIFACTOR
0.0125

We can use the SeriesDate Function to calculate the AIFACTOR for every day from the settlement date to the maturity date.

SELECT k.SeriesValue,
       wct.AIFACTOR(   '0',           --Basis
                       .05,           --Rate
                       '2012-05-15',  --Maturity
                       k.SeriesValue, --Settlement
                       2,             --Frequency
                       NULL,          --FirstInterestDate
                       NULL,          --LastInterestDate
                       NULL,          --IssueDate
                       NULL           --Holidays
                   ) as AIFACTOR
FROM wct.SeriesDate('2012-02-15', '2012-05-15', NULL, NULL, NULL) k;

This produces the following result.

SeriesValueAIFACTOR
2012-02-15 00:00:00.0000.0125
2012-02-16 00:00:00.0000.0126388888888889
2012-02-17 00:00:00.0000.0127777777777778
2012-02-18 00:00:00.0000.0129166666666667
2012-02-19 00:00:00.0000.0130555555555556
2012-02-20 00:00:00.0000.0131944444444444
2012-02-21 00:00:00.0000.0133333333333333
2012-02-22 00:00:00.0000.0134722222222222
2012-02-23 00:00:00.0000.0136111111111111
2012-02-24 00:00:00.0000.01375
2012-02-25 00:00:00.0000.0138888888888889
2012-02-26 00:00:00.0000.0140277777777778
2012-02-27 00:00:00.0000.0141666666666667
2012-02-28 00:00:00.0000.0143055555555556
2012-02-29 00:00:00.0000.0144444444444444
2012-03-01 00:00:00.0000.0147222222222222
2012-03-02 00:00:00.0000.0148611111111111
2012-03-03 00:00:00.0000.015
2012-03-04 00:00:00.0000.0151388888888889
2012-03-05 00:00:00.0000.0152777777777778
2012-03-06 00:00:00.0000.0154166666666667
2012-03-07 00:00:00.0000.0155555555555556
2012-03-08 00:00:00.0000.0156944444444444
2012-03-09 00:00:00.0000.0158333333333333
2012-03-10 00:00:00.0000.0159722222222222
2012-03-11 00:00:00.0000.0161111111111111
2012-03-12 00:00:00.0000.01625
2012-03-13 00:00:00.0000.0163888888888889
2012-03-14 00:00:00.0000.0165277777777778
2012-03-15 00:00:00.0000.0166666666666667
2012-03-16 00:00:00.0000.0168055555555556
2012-03-17 00:00:00.0000.0169444444444444
2012-03-18 00:00:00.0000.0170833333333333
2012-03-19 00:00:00.0000.0172222222222222
2012-03-20 00:00:00.0000.0173611111111111
2012-03-21 00:00:00.0000.0175
2012-03-22 00:00:00.0000.0176388888888889
2012-03-23 00:00:00.0000.0177777777777778
2012-03-24 00:00:00.0000.0179166666666667
2012-03-25 00:00:00.0000.0180555555555556
2012-03-26 00:00:00.0000.0181944444444444
2012-03-27 00:00:00.0000.0183333333333333
2012-03-28 00:00:00.0000.0184722222222222
2012-03-29 00:00:00.0000.0186111111111111
2012-03-30 00:00:00.0000.01875
2012-03-31 00:00:00.0000.0188888888888889
2012-04-01 00:00:00.0000.0188888888888889
2012-04-02 00:00:00.0000.0190277777777778
2012-04-03 00:00:00.0000.0191666666666667
2012-04-04 00:00:00.0000.0193055555555556
2012-04-05 00:00:00.0000.0194444444444444
2012-04-06 00:00:00.0000.0195833333333333
2012-04-07 00:00:00.0000.0197222222222222
2012-04-08 00:00:00.0000.0198611111111111
2012-04-09 00:00:00.0000.02
2012-04-10 00:00:00.0000.0201388888888889
2012-04-11 00:00:00.0000.0202777777777778
2012-04-12 00:00:00.0000.0204166666666667
2012-04-13 00:00:00.0000.0205555555555556
2012-04-14 00:00:00.0000.0206944444444444
2012-04-15 00:00:00.0000.0208333333333333
2012-04-16 00:00:00.0000.0209722222222222
2012-04-17 00:00:00.0000.0211111111111111
2012-04-18 00:00:00.0000.02125
2012-04-19 00:00:00.0000.0213888888888889
2012-04-20 00:00:00.0000.0215277777777778
2012-04-21 00:00:00.0000.0216666666666667
2012-04-22 00:00:00.0000.0218055555555556
2012-04-23 00:00:00.0000.0219444444444444
2012-04-24 00:00:00.0000.0220833333333333
2012-04-25 00:00:00.0000.0222222222222222
2012-04-26 00:00:00.0000.0223611111111111
2012-04-27 00:00:00.0000.0225
2012-04-28 00:00:00.0000.0226388888888889
2012-04-29 00:00:00.0000.0227777777777778
2012-04-30 00:00:00.0000.0229166666666667
2012-05-01 00:00:00.0000.0230555555555556
2012-05-02 00:00:00.0000.0231944444444444
2012-05-03 00:00:00.0000.0233333333333333
2012-05-04 00:00:00.0000.0234722222222222
2012-05-05 00:00:00.0000.0236111111111111
2012-05-06 00:00:00.0000.02375
2012-05-07 00:00:00.0000.0238888888888889
2012-05-08 00:00:00.0000.0240277777777778
2012-05-09 00:00:00.0000.0241666666666667
2012-05-10 00:00:00.0000.0243055555555556
2012-05-11 00:00:00.0000.0244444444444444
2012-05-12 00:00:00.0000.0245833333333333
2012-05-13 00:00:00.0000.0247222222222222
2012-05-14 00:00:00.0000.0248611111111111
2012-05-15 00:00:00.0000

In this SELECT statement we will calculate the AIFACTOR for each date from the 2012-02-15 though 2012-05-15 and for each day-count convention 0 through 9.

SELECT SeriesValue as SettDate,
       ROUND([0], 6) as [0],
       ROUND([1], 6) as [1],
       ROUND([2], 6) as [2],
       ROUND([3], 6) as [3],
       ROUND([4], 6) as [4],
       ROUND([5], 6) as [5],
       ROUND([6], 6) as [6],
       ROUND([7], 6) as [7],
       ROUND([8], 6) as [8],
       ROUND([9], 6) as [9]
FROM
(
    SELECT k.SeriesValue,
           l.seriesvalue as basis,
           wct.AIFACTOR(   l.seriesValue, --Basis
                           .05,           --rate
                           '2012-05-15',  --Maturity Date
                           k.SeriesValue, --Settlement Date
                           2,             --Frequency
                           NULL,          --First Interest Date
                           NULL,          --Last Interest Date
                           NULL,          --Issue Date
                           NULL           --Holidays
                       ) as AIF
    FROM wct.SeriesDate('2012-02-15', '2012-05-15', NULL, NULL, NULL) k
        CROSS APPLY wct.SERIESINT(0, 9, NULL, NULL, NULL) l
) d
PIVOT
(
    min(AIF)
    for basis in ([0], [1], [2], [3], [4], [5], [6], [7], [8], [9])
) as P;

This produces the following result.

SettDate0123456789
2012-02-15 00:00:00.0000.01250.0126370.0127780.0126030.01250.01250.0127070.0126030.0127780.012637
2012-02-16 00:00:00.0000.0126390.0127750.0129170.012740.0126390.0126390.0128450.012740.0129170.012775
2012-02-17 00:00:00.0000.0127780.0129120.0130560.0128770.0127780.0127780.0129830.0128770.0130560.012912
2012-02-18 00:00:00.0000.0129170.0130490.0131940.0130140.0129170.0129170.0131220.0130140.0131940.013049
2012-02-19 00:00:00.0000.0130560.0131870.0133330.0131510.0130560.0130560.013260.0131510.0133330.013187
2012-02-20 00:00:00.0000.0131940.0133240.0134720.0132880.0131940.0131940.0133980.0132880.0134720.013324
2012-02-21 00:00:00.0000.0133330.0134620.0136110.0134250.0133330.0133330.0135360.0134250.0136110.013462
2012-02-22 00:00:00.0000.0134720.0135990.013750.0135620.0134720.0134720.0136740.0135620.013750.013599
2012-02-23 00:00:00.0000.0136110.0137360.0138890.0136990.0136110.0136110.0138120.0136990.0138890.013736
2012-02-24 00:00:00.0000.013750.0138740.0140280.0138360.013750.013750.013950.0138360.0140280.013874
2012-02-25 00:00:00.0000.0138890.0140110.0141670.0139730.0138890.0138890.0140880.0139730.0141670.014011
2012-02-26 00:00:00.0000.0140280.0141480.0143060.014110.0140280.0140280.0142270.014110.0143060.014148
2012-02-27 00:00:00.0000.0141670.0142860.0144440.0142470.0141670.0141670.0143650.0142470.0144440.014286
2012-02-28 00:00:00.0000.0143060.0144230.0145830.0143840.0143060.0143060.0145030.0143840.0145830.014423
2012-02-29 00:00:00.0000.0144440.014560.0147220.0145210.0144440.0145830.0145030.0143840.0145830.01456
2012-03-01 00:00:00.0000.0147220.0146980.0148610.0146580.0147220.0147220.0146410.0145210.0147220.014698
2012-03-02 00:00:00.0000.0148610.0148350.0150.0147950.0148610.0148610.0147790.0146580.0148610.014835
2012-03-03 00:00:00.0000.0150.0149730.0151390.0149320.0150.0150.0149170.0147950.0150.014973
2012-03-04 00:00:00.0000.0151390.015110.0152780.0150680.0151390.0151390.0150550.0149320.0151390.01511
2012-03-05 00:00:00.0000.0152780.0152470.0154170.0152050.0152780.0152780.0151930.0150680.0152780.015247
2012-03-06 00:00:00.0000.0154170.0153850.0155560.0153420.0154170.0154170.0153310.0152050.0154170.015385
2012-03-07 00:00:00.0000.0155560.0155220.0156940.0154790.0155560.0155560.015470.0153420.0155560.015522
2012-03-08 00:00:00.0000.0156940.0156590.0158330.0156160.0156940.0156940.0156080.0154790.0156940.015659
2012-03-09 00:00:00.0000.0158330.0157970.0159720.0157530.0158330.0158330.0157460.0156160.0158330.015797
2012-03-10 00:00:00.0000.0159720.0159340.0161110.015890.0159720.0159720.0158840.0157530.0159720.015934
2012-03-11 00:00:00.0000.0161110.0160710.016250.0160270.0161110.0161110.0160220.015890.0161110.016071
2012-03-12 00:00:00.0000.016250.0162090.0163890.0161640.016250.016250.016160.0160270.016250.016209
2012-03-13 00:00:00.0000.0163890.0163460.0165280.0163010.0163890.0163890.0162980.0161640.0163890.016346
2012-03-14 00:00:00.0000.0165280.0164840.0166670.0164380.0165280.0165280.0164360.0163010.0165280.016484
2012-03-15 00:00:00.0000.0166670.0166210.0168060.0165750.0166670.0166670.0165750.0164380.0166670.016621
2012-03-16 00:00:00.0000.0168060.0167580.0169440.0167120.0168060.0168060.0167130.0165750.0168060.016758
2012-03-17 00:00:00.0000.0169440.0168960.0170830.0168490.0169440.0169440.0168510.0167120.0169440.016896
2012-03-18 00:00:00.0000.0170830.0170330.0172220.0169860.0170830.0170830.0169890.0168490.0170830.017033
2012-03-19 00:00:00.0000.0172220.017170.0173610.0171230.0172220.0172220.0171270.0169860.0172220.01717
2012-03-20 00:00:00.0000.0173610.0173080.01750.017260.0173610.0173610.0172650.0171230.0173610.017308
2012-03-21 00:00:00.0000.01750.0174450.0176390.0173970.01750.01750.0174030.017260.01750.017445
2012-03-22 00:00:00.0000.0176390.0175820.0177780.0175340.0176390.0176390.0175410.0173970.0176390.017582
2012-03-23 00:00:00.0000.0177780.017720.0179170.0176710.0177780.0177780.017680.0175340.0177780.01772
2012-03-24 00:00:00.0000.0179170.0178570.0180560.0178080.0179170.0179170.0178180.0176710.0179170.017857
2012-03-25 00:00:00.0000.0180560.0179950.0181940.0179450.0180560.0180560.0179560.0178080.0180560.017995
2012-03-26 00:00:00.0000.0181940.0181320.0183330.0180820.0181940.0181940.0180940.0179450.0181940.018132
2012-03-27 00:00:00.0000.0183330.0182690.0184720.0182190.0183330.0183330.0182320.0180820.0183330.018269
2012-03-28 00:00:00.0000.0184720.0184070.0186110.0183560.0184720.0184720.018370.0182190.0184720.018407
2012-03-29 00:00:00.0000.0186110.0185440.018750.0184930.0186110.0186110.0185080.0183560.0186110.018544
2012-03-30 00:00:00.0000.018750.0186810.0188890.018630.018750.018750.0186460.0184930.018750.018681
2012-03-31 00:00:00.0000.0188890.0188190.0190280.0187670.018750.018750.0187850.018630.0188890.018819
2012-04-01 00:00:00.0000.0188890.0189560.0191670.0189040.0188890.0188890.0189230.0187670.0190280.018956
2012-04-02 00:00:00.0000.0190280.0190930.0193060.0190410.0190280.0190280.0190610.0189040.0191670.019093
2012-04-03 00:00:00.0000.0191670.0192310.0194440.0191780.0191670.0191670.0191990.0190410.0193060.019231
2012-04-04 00:00:00.0000.0193060.0193680.0195830.0193150.0193060.0193060.0193370.0191780.0194440.019368
2012-04-05 00:00:00.0000.0194440.0195050.0197220.0194520.0194440.0194440.0194750.0193150.0195830.019505
2012-04-06 00:00:00.0000.0195830.0196430.0198610.0195890.0195830.0195830.0196130.0194520.0197220.019643
2012-04-07 00:00:00.0000.0197220.019780.020.0197260.0197220.0197220.0197510.0195890.0198610.01978
2012-04-08 00:00:00.0000.0198610.0199180.0201390.0198630.0198610.0198610.019890.0197260.020.019918
2012-04-09 00:00:00.0000.020.0200550.0202780.020.020.020.0200280.0198630.0201390.020055
2012-04-10 00:00:00.0000.0201390.0201920.0204170.0201370.0201390.0201390.0201660.020.0202780.020192
2012-04-11 00:00:00.0000.0202780.020330.0205560.0202740.0202780.0202780.0203040.0201370.0204170.02033
2012-04-12 00:00:00.0000.0204170.0204670.0206940.0204110.0204170.0204170.0204420.0202740.0205560.020467
2012-04-13 00:00:00.0000.0205560.0206040.0208330.0205480.0205560.0205560.020580.0204110.0206940.020604
2012-04-14 00:00:00.0000.0206940.0207420.0209720.0206850.0206940.0206940.0207180.0205480.0208330.020742
2012-04-15 00:00:00.0000.0208330.0208790.0211110.0208220.0208330.0208330.0208560.0206850.0209720.020879
2012-04-16 00:00:00.0000.0209720.0210160.021250.0209590.0209720.0209720.0209940.0208220.0211110.021016
2012-04-17 00:00:00.0000.0211110.0211540.0213890.0210960.0211110.0211110.0211330.0209590.021250.021154
2012-04-18 00:00:00.0000.021250.0212910.0215280.0212330.021250.021250.0212710.0210960.0213890.021291
2012-04-19 00:00:00.0000.0213890.0214290.0216670.021370.0213890.0213890.0214090.0212330.0215280.021429
2012-04-20 00:00:00.0000.0215280.0215660.0218060.0215070.0215280.0215280.0215470.021370.0216670.021566
2012-04-21 00:00:00.0000.0216670.0217030.0219440.0216440.0216670.0216670.0216850.0215070.0218060.021703
2012-04-22 00:00:00.0000.0218060.0218410.0220830.0217810.0218060.0218060.0218230.0216440.0219440.021841
2012-04-23 00:00:00.0000.0219440.0219780.0222220.0219180.0219440.0219440.0219610.0217810.0220830.021978
2012-04-24 00:00:00.0000.0220830.0221150.0223610.0220550.0220830.0220830.0220990.0219180.0222220.022115
2012-04-25 00:00:00.0000.0222220.0222530.02250.0221920.0222220.0222220.0222380.0220550.0223610.022253
2012-04-26 00:00:00.0000.0223610.022390.0226390.0223290.0223610.0223610.0223760.0221920.02250.02239
2012-04-27 00:00:00.0000.02250.0225270.0227780.0224660.02250.02250.0225140.0223290.0226390.022527
2012-04-28 00:00:00.0000.0226390.0226650.0229170.0226030.0226390.0226390.0226520.0224660.0227780.022665
2012-04-29 00:00:00.0000.0227780.0228020.0230560.022740.0227780.0227780.022790.0226030.0229170.022802
2012-04-30 00:00:00.0000.0229170.022940.0231940.0228770.0229170.0229170.0229280.022740.0230560.02294
2012-05-01 00:00:00.0000.0230560.0230770.0233330.0230140.0230560.0230560.0230660.0228770.0231940.023077
2012-05-02 00:00:00.0000.0231940.0232140.0234720.0231510.0231940.0231940.0232040.0230140.0233330.023214
2012-05-03 00:00:00.0000.0233330.0233520.0236110.0232880.0233330.0233330.0233430.0231510.0234720.023352
2012-05-04 00:00:00.0000.0234720.0234890.023750.0234250.0234720.0234720.0234810.0232880.0236110.023489
2012-05-05 00:00:00.0000.0236110.0236260.0238890.0235620.0236110.0236110.0236190.0234250.023750.023626
2012-05-06 00:00:00.0000.023750.0237640.0240280.0236990.023750.023750.0237570.0235620.0238890.023764
2012-05-07 00:00:00.0000.0238890.0239010.0241670.0238360.0238890.0238890.0238950.0236990.0240280.023901
2012-05-08 00:00:00.0000.0240280.0240380.0243060.0239730.0240280.0240280.0240330.0238360.0241670.024038
2012-05-09 00:00:00.0000.0241670.0241760.0244440.024110.0241670.0241670.0241710.0239730.0243060.024176
2012-05-10 00:00:00.0000.0243060.0243130.0245830.0242470.0243060.0243060.0243090.024110.0244440.024313
2012-05-11 00:00:00.0000.0244440.0244510.0247220.0243840.0244440.0244440.0244480.0242470.0245830.024451
2012-05-12 00:00:00.0000.0245830.0245880.0248610.0245210.0245830.0245830.0245860.0243840.0247220.024588
2012-05-13 00:00:00.0000.0247220.0247250.0250.0246580.0247220.0247220.0247240.0245210.0248610.024725
2012-05-14 00:00:00.0000.0248610.0248630.0251390.0247950.0248610.0248610.0248620.0246580.0250.024863
2012-05-15 00:00:00.0000000000000

If the maturity date, last interest date, or first interest date is the last day of the month, then the calculation of the previous coupon date (which is used in the calculation of the accrued interest), can be affected by the choice of @Basis. In this example, we will look at the difference between the Actual/Actual (1) and the Actual/Actual NON_EOM (11) values for @Basis.

SELECT LEFT(convert(varchar, l.seriesvalue, 106), 11) as Settlement,
       wct.AIFACTOR(   1,             --Basis
                       .05,           --rate
                       '2012-06-30',  --Maturity Date
                       l.SeriesValue, --Settlement Date
                       2,             --Frequency
                       NULL,          --First Interest Date
                       NULL,          --Last Interest Date
                       NULL,          --Issue Date
                       NULL           --Holidays
                   ) as [Actual/Actual],
       wct.AIFACTOR(   11,            --Basis
                       .05,           --rate
                       '2012-06-30',  --Maturity Date
                       l.SeriesValue, --Settlement Date
                       2,             --Frequency
                       NULL,          --First Interest Date
                       NULL,          --Last Interest Date
                       NULL,          --Issue Date
                       NULL           --Holidays
                   ) as [Actual/Actual NON EOM]
FROM wct.SeriesDate('2011-11-30', '2012-01-31', NULL, NULL, NULL) l;

This produces the following result.

SettlementActual/ActualActual/Actual NON EOM
30 Nov 20110.02078804347826090.0209016393442623
01 Dec 20110.02092391304347830.0210382513661202
02 Dec 20110.02105978260869570.0211748633879781
03 Dec 20110.0211956521739130.0213114754098361
04 Dec 20110.02133152173913040.021448087431694
05 Dec 20110.02146739130434780.0215846994535519
06 Dec 20110.02160326086956520.0217213114754098
07 Dec 20110.02173913043478260.0218579234972678
08 Dec 20110.0218750.0219945355191257
09 Dec 20110.02201086956521740.0221311475409836
10 Dec 20110.02214673913043480.0222677595628415
11 Dec 20110.02228260869565220.0224043715846995
12 Dec 20110.02241847826086960.0225409836065574
13 Dec 20110.0225543478260870.0226775956284153
14 Dec 20110.02269021739130430.0228142076502732
15 Dec 20110.02282608695652170.0229508196721312
16 Dec 20110.02296195652173910.0230874316939891
17 Dec 20110.02309782608695650.023224043715847
18 Dec 20110.02323369565217390.0233606557377049
19 Dec 20110.02336956521739130.0234972677595628
20 Dec 20110.02350543478260870.0236338797814208
21 Dec 20110.02364130434782610.0237704918032787
22 Dec 20110.02377717391304350.0239071038251366
23 Dec 20110.02391304347826090.0240437158469945
24 Dec 20110.02404891304347830.0241803278688525
25 Dec 20110.02418478260869570.0243169398907104
26 Dec 20110.0243206521739130.0244535519125683
27 Dec 20110.02445652173913040.0245901639344262
28 Dec 20110.02459239130434780.0247267759562842
29 Dec 20110.02472826086956520.0248633879781421
30 Dec 20110.02486413043478260
31 Dec 201100.000136612021857923
01 Jan 20120.0001373626373626370.000273224043715847
02 Jan 20120.0002747252747252750.000409836065573771
03 Jan 20120.0004120879120879120.000546448087431694
04 Jan 20120.0005494505494505490.000683060109289617
05 Jan 20120.0006868131868131870.000819672131147541
06 Jan 20120.0008241758241758240.000956284153005465
07 Jan 20120.0009615384615384620.00109289617486339
08 Jan 20120.00109890109890110.00122950819672131
09 Jan 20120.001236263736263740.00136612021857923
10 Jan 20120.001373626373626370.00150273224043716
11 Jan 20120.001510989010989010.00163934426229508
12 Jan 20120.001648351648351650.00177595628415301
13 Jan 20120.001785714285714290.00191256830601093
14 Jan 20120.001923076923076920.00204918032786885
15 Jan 20120.002060439560439560.00218579234972678
16 Jan 20120.00219780219780220.0023224043715847
17 Jan 20120.002335164835164840.00245901639344262
18 Jan 20120.002472527472527470.00259562841530055
19 Jan 20120.002609890109890110.00273224043715847
20 Jan 20120.002747252747252750.00286885245901639
21 Jan 20120.002884615384615380.00300546448087432
22 Jan 20120.003021978021978020.00314207650273224
23 Jan 20120.003159340659340660.00327868852459016
24 Jan 20120.00329670329670330.00341530054644809
25 Jan 20120.003434065934065930.00355191256830601
26 Jan 20120.003571428571428570.00368852459016393
27 Jan 20120.003708791208791210.00382513661202186
28 Jan 20120.003846153846153850.00396174863387978
29 Jan 20120.003983516483516480.00409836065573771
30 Jan 20120.004120879120879120.00423497267759563
31 Jan 20120.004258241758241760.00437158469945355

The BUS/252 day-count convention only accrues interest on business days, so there is no change in the AIFACTOR on weekends or holidays. In addition, the calculation of the coupon interest amount for the coupon period is different than for other day-count conventions and is consistent with the ANDIMA specification.

SELECT LEFT(convert(varchar, l.seriesvalue, 106), 11) as Settlement,
       wct.AIFACTOR(   20,              --Basis
                       .05,             --rate
                       '2012-06-30',    --Maturity Date
                       l.SeriesValue,   --Settlement Date
                       2,               --Frequency
                       NULL,            --First Interest Date
                       NULL,            --Last Interest Date
                       NULL,            --Issue Date
                       '20111225,20120101,20120220,20120221,20120406,20120421,20120501,20120607'				--Holidays
                   ) as AIFACTOR
FROM wct.SeriesDate('2011-11-30', '2012-01-31', NULL, NULL, NULL) l
GROUP BY l.seriesvalue
ORDER BY SeriesValue

This produces the following result.

Settlement                AIFACTOR
----------- ----------------------
30 Nov 2011     0.0203921465830275
01 Dec 2011     0.0205792304966333
02 Dec 2011      0.020766314410239
03 Dec 2011     0.0209533983238448
04 Dec 2011     0.0209533983238448
05 Dec 2011     0.0209533983238448
06 Dec 2011     0.0211404822374505
07 Dec 2011     0.0213275661510563
08 Dec 2011     0.0215146500646621
09 Dec 2011     0.0217017339782678
10 Dec 2011     0.0218888178918736
11 Dec 2011     0.0218888178918736
12 Dec 2011     0.0218888178918736
13 Dec 2011     0.0220759018054793
14 Dec 2011     0.0222629857190851
15 Dec 2011     0.0224500696326908
16 Dec 2011     0.0226371535462966
17 Dec 2011     0.0228242374599024
18 Dec 2011     0.0228242374599024
19 Dec 2011     0.0228242374599024
20 Dec 2011     0.0230113213735081
21 Dec 2011     0.0231984052871139
22 Dec 2011     0.0233854892007196
23 Dec 2011     0.0235725731143254
24 Dec 2011     0.0237596570279311
25 Dec 2011     0.0237596570279311
26 Dec 2011     0.0237596570279311
27 Dec 2011     0.0239467409415369
28 Dec 2011     0.0241338248551427
29 Dec 2011     0.0243209087687484
30 Dec 2011     0.0245079926823542
31 Dec 2011                      0
01 Jan 2012                      0
02 Jan 2012                      0
03 Jan 2012   0.000197560612767679
04 Jan 2012   0.000395121225535359
05 Jan 2012   0.000592681838303038
06 Jan 2012   0.000790242451070718
07 Jan 2012   0.000987803063838397
08 Jan 2012   0.000987803063838397
09 Jan 2012   0.000987803063838397
10 Jan 2012    0.00118536367660608
11 Jan 2012    0.00138292428937376
12 Jan 2012    0.00158048490214144
13 Jan 2012    0.00177804551490911
14 Jan 2012    0.00197560612767679
15 Jan 2012    0.00197560612767679
16 Jan 2012    0.00197560612767679
17 Jan 2012    0.00217316674044447
18 Jan 2012    0.00237072735321215
19 Jan 2012    0.00256828796597983
20 Jan 2012    0.00276584857874751
21 Jan 2012    0.00296340919151519
22 Jan 2012    0.00296340919151519
23 Jan 2012    0.00296340919151519
24 Jan 2012    0.00316096980428287
25 Jan 2012    0.00335853041705055
26 Jan 2012    0.00355609102981823
27 Jan 2012    0.00375365164258591
28 Jan 2012    0.00395121225535359
29 Jan 2012    0.00395121225535359
30 Jan 2012    0.00395121225535359
31 Jan 2012    0.00414877286812127

Here's an example of the accrued interest factor calculation using the Actual/Actual ISDA day-count convention.

SELECT LEFT(convert(varchar, l.seriesvalue, 106), 11) as Settlement,
       wct.AIFACTOR(   21,            --Basis
                       .05,           --rate
                       '2012-05-31',  --Maturity Date
                       l.SeriesValue, --Settlement Date
                       2,             --Frequency
                       NULL,          --First Interest Date
                       NULL,          --Last Interest Date
                       NULL,          --Issue Date
                       NULL           --Holidays
                   ) as AIFACTOR
FROM wct.SeriesDate('2011-11-30', '2012-01-31', NULL, NULL, NULL) l;

This produces the following result.

SettlementAIFACTOR
30 Nov 20110
01 Dec 20110.000136986301369863
02 Dec 20110.000273972602739726
03 Dec 20110.000410958904109589
04 Dec 20110.000547945205479452
05 Dec 20110.000684931506849315
06 Dec 20110.000821917808219178
07 Dec 20110.000958904109589041
08 Dec 20110.0010958904109589
09 Dec 20110.00123287671232877
10 Dec 20110.00136986301369863
11 Dec 20110.00150684931506849
12 Dec 20110.00164383561643836
13 Dec 20110.00178082191780822
14 Dec 20110.00191780821917808
15 Dec 20110.00205479452054795
16 Dec 20110.00219178082191781
17 Dec 20110.00232876712328767
18 Dec 20110.00246575342465753
19 Dec 20110.0026027397260274
20 Dec 20110.00273972602739726
21 Dec 20110.00287671232876712
22 Dec 20110.00301369863013699
23 Dec 20110.00315068493150685
24 Dec 20110.00328767123287671
25 Dec 20110.00342465753424658
26 Dec 20110.00356164383561644
27 Dec 20110.0036986301369863
28 Dec 20110.00383561643835616
29 Dec 20110.00397260273972603
30 Dec 20110.00410958904109589
31 Dec 20110.00424657534246575
01 Jan 20120.00438356164383562
02 Jan 20120.00452017366569354
03 Jan 20120.00465678568755146
04 Jan 20120.00479339770940939
05 Jan 20120.00493000973126731
06 Jan 20120.00506662175312523
07 Jan 20120.00520323377498316
08 Jan 20120.00533984579684108
09 Jan 20120.00547645781869901
10 Jan 20120.00561306984055693
11 Jan 20120.00574968186241485
12 Jan 20120.00588629388427278
13 Jan 20120.0060229059061307
14 Jan 20120.00615951792798862
15 Jan 20120.00629612994984655
16 Jan 20120.00643274197170447
17 Jan 20120.00656935399356239
18 Jan 20120.00670596601542032
19 Jan 20120.00684257803727824
20 Jan 20120.00697919005913616
21 Jan 20120.00711580208099409
22 Jan 20120.00725241410285201
23 Jan 20120.00738902612470993
24 Jan 20120.00752563814656786
25 Jan 20120.00766225016842578
26 Jan 20120.0077988621902837
27 Jan 20120.00793547421214163
28 Jan 20120.00807208623399955
29 Jan 20120.00820869825585747
30 Jan 20120.0083453102777154
31 Jan 20120.00848192229957332

Notice how the AIFACTOR increases smoothly by 0.00013698630 for each day in 2011 and then AIFACTOR changes by 0.00013661202 for each day in 2012.

Here's an example of the accrued interest factor calculation using the Actual/365L day-count convention.

SELECT LEFT(convert(varchar, l.seriesvalue, 106), 11) as Settlement,
       wct.AIFACTOR(   23,            --Basis
                       .05,           --rate
                       '2012-05-31',  --Maturity Date
                       l.SeriesValue, --Settlement Date
                       2,             --Frequency
                       NULL,          --First Interest Date
                       NULL,          --Last Interest Date
                       NULL,          --Issue Date
                       NULL           --Holidays
                   ) as AIFACTOR
FROM wct.SeriesDate('2011-11-30', '2012-01-31', NULL, NULL, NULL) l;

This produces the following result.

SettlementAIFACTOR
30 Nov 20110
01 Dec 20110.000136612021857923
02 Dec 20110.000273224043715847
03 Dec 20110.000409836065573771
04 Dec 20110.000546448087431694
05 Dec 20110.000683060109289617
06 Dec 20110.000819672131147541
07 Dec 20110.000956284153005465
08 Dec 20110.00109289617486339
09 Dec 20110.00122950819672131
10 Dec 20110.00136612021857923
11 Dec 20110.00150273224043716
12 Dec 20110.00163934426229508
13 Dec 20110.00177595628415301
14 Dec 20110.00191256830601093
15 Dec 20110.00204918032786885
16 Dec 20110.00218579234972678
17 Dec 20110.0023224043715847
18 Dec 20110.00245901639344262
19 Dec 20110.00259562841530055
20 Dec 20110.00273224043715847
21 Dec 20110.00286885245901639
22 Dec 20110.00300546448087432
23 Dec 20110.00314207650273224
24 Dec 20110.00327868852459016
25 Dec 20110.00341530054644809
26 Dec 20110.00355191256830601
27 Dec 20110.00368852459016393
28 Dec 20110.00382513661202186
29 Dec 20110.00396174863387978
30 Dec 20110.00409836065573771
31 Dec 20110.00423497267759563
01 Jan 20120.00437158469945355
02 Jan 20120.00450819672131148
03 Jan 20120.0046448087431694
04 Jan 20120.00478142076502732
05 Jan 20120.00491803278688525
06 Jan 20120.00505464480874317
07 Jan 20120.00519125683060109
08 Jan 20120.00532786885245902
09 Jan 20120.00546448087431694
10 Jan 20120.00560109289617486
11 Jan 20120.00573770491803279
12 Jan 20120.00587431693989071
13 Jan 20120.00601092896174863
14 Jan 20120.00614754098360656
15 Jan 20120.00628415300546448
16 Jan 20120.0064207650273224
17 Jan 20120.00655737704918033
18 Jan 20120.00669398907103825
19 Jan 20120.00683060109289617
20 Jan 20120.0069672131147541
21 Jan 20120.00710382513661202
22 Jan 20120.00724043715846995
23 Jan 20120.00737704918032787
24 Jan 20120.00751366120218579
25 Jan 20120.00765027322404372
26 Jan 20120.00778688524590164
27 Jan 20120.00792349726775956
28 Jan 20120.00806010928961749
29 Jan 20120.00819672131147541
30 Jan 20120.00833333333333333
31 Jan 20120.00846994535519126

Notice how the AIFACTOR increases smoothly by 0.00013661202 for each day in the coupon period even as the year changes from 2011 to 2012.

Here's an example of the accrued interest factor calculation using the Actual/AFB day-count convention.

SELECT LEFT(convert(varchar, l.seriesvalue, 106), 11) as Settlement,
       wct.AIFACTOR(   24,            --Basis
                       .05,           --rate
                       '2012-05-31',  --Maturity Date
                       l.SeriesValue, --Settlement Date
                       2,             --Frequency
                       NULL,          --First Interest Date
                       NULL,          --Last Interest Date
                       NULL,          --Issue Date
                       NULL           --Holidays
                   ) as AIFACTOR
FROM wct.SeriesDate('2011-11-30', '2012-01-31', NULL, NULL, NULL) l;

This produces the following results.

SettlementAIFACTOR
30 Nov 20110
01 Dec 20110.000136612021857923
02 Dec 20110.000273224043715847
03 Dec 20110.000409836065573771
04 Dec 20110.000546448087431694
05 Dec 20110.000683060109289617
06 Dec 20110.000819672131147541
07 Dec 20110.000956284153005465
08 Dec 20110.00109289617486339
09 Dec 20110.00122950819672131
10 Dec 20110.00136612021857923
11 Dec 20110.00150273224043716
12 Dec 20110.00163934426229508
13 Dec 20110.00177595628415301
14 Dec 20110.00191256830601093
15 Dec 20110.00204918032786885
16 Dec 20110.00218579234972678
17 Dec 20110.0023224043715847
18 Dec 20110.00245901639344262
19 Dec 20110.00259562841530055
20 Dec 20110.00273224043715847
21 Dec 20110.00286885245901639
22 Dec 20110.00300546448087432
23 Dec 20110.00314207650273224
24 Dec 20110.00327868852459016
25 Dec 20110.00341530054644809
26 Dec 20110.00355191256830601
27 Dec 20110.00368852459016393
28 Dec 20110.00382513661202186
29 Dec 20110.00396174863387978
30 Dec 20110.00409836065573771
31 Dec 20110.00423497267759563
01 Jan 20120.00437158469945355
02 Jan 20120.00450819672131148
03 Jan 20120.0046448087431694
04 Jan 20120.00478142076502732
05 Jan 20120.00491803278688525
06 Jan 20120.00505464480874317
07 Jan 20120.00519125683060109
08 Jan 20120.00532786885245902
09 Jan 20120.00546448087431694
10 Jan 20120.00560109289617486
11 Jan 20120.00573770491803279
12 Jan 20120.00587431693989071
13 Jan 20120.00601092896174863
14 Jan 20120.00614754098360656
15 Jan 20120.00628415300546448
16 Jan 20120.0064207650273224
17 Jan 20120.00655737704918033
18 Jan 20120.00669398907103825
19 Jan 20120.00683060109289617
20 Jan 20120.0069672131147541
21 Jan 20120.00710382513661202
22 Jan 20120.00724043715846995
23 Jan 20120.00737704918032787
24 Jan 20120.00751366120218579
25 Jan 20120.00765027322404372
26 Jan 20120.00778688524590164
27 Jan 20120.00792349726775956
28 Jan 20120.00806010928961749
29 Jan 20120.00819672131147541
30 Jan 20120.00833333333333333
31 Jan 20120.00846994535519126

This produces the same result as Actual/Actual Long.

Finally, let's look at a comparison of all the day-count conventions for a single settlement date.

DECLARE @h as varchar(max);
SET @h = '20120101,20120220,20120221,20120406,20120421,20120501,20120607,20120907,
          20121012,20121102,20121115,20121225';
SELECT n.description,
       wct.AIFACTOR(   n.basis,      --Basis
                       .10,          --Rate
                       '2012-05-31', --Maturity Date
                       '2012-03-31', --Settlement Date
                       2,            --Frequency
                       NULL,         --First Interest Date
                       NULL,         --Last Interest Date
                       NULL,         --Issue Date
                       @h            --Holidays
                   ) * 10000 as [Interest]
FROM
(
    SELECT 0,
           'BOND'
    UNION ALL
    SELECT 1,
           'Actual / Actual'
    UNION ALL
    SELECT 2,
           'Actual / 360'
    UNION ALL
    SELECT 3,
           'Actual / 365'
    UNION ALL
    SELECT 4,
           '30E / 360'
    UNION ALL
    SELECT 5,
           '30 / 360 ISDA'
    UNION ALL
    SELECT 6,
           'NL / ACT'
    UNION ALL
    SELECT 7,
           'NL / 365'
    UNION ALL
    SELECT 8,
           'NL / 360'
    UNION ALL
    SELECT 9,
           'Actual / 364'
    UNION ALL
    SELECT 10,
           'BOND NON-EOM'
    UNION ALL
    SELECT 11,
           'Actual / Actual NON-EOM'
    UNION ALL
    SELECT 12,
           'Actual / 360 NON-EOM'
    UNION ALL
    SELECT 13,
           'Actual / 365 NON-EOM'
    UNION ALL
    SELECT 14,
           '30E / 360 NON-EOM'
    UNION ALL
    SELECT 15,
           '30 / 360 ISDA NON-EOM'
    UNION ALL
    SELECT 16,
           'NL / ACT NON-EOM'
    UNION ALL
    SELECT 17,
           'NL / 365 NON-EOM'
    UNION ALL
    SELECT 18,
           'NL / 360 NON-EOM'
    UNION ALL
    SELECT 19,
           'Actual / 364 NON-EOM'
    UNION ALL
    SELECT 20,
           'BUS / 252'
    UNION ALL
    SELECT 21,
           'Actual / ISDA'
    UNION ALL
    SELECT 22,
           'Actual / ISMA'
    UNION ALL
    SELECT 23,
           'Actual / 365L'
    UNION ALL
    SELECT 24,
           'Actual / AFB'
    UNION ALL
    SELECT 30,
           'BUS / 252 NON-EOM'
) n(basis, Description);

This produces the following result.

DescriptionInterest
BOND333.333333333333
Actual / Actual333.333333333333
Actual / 360338.888888888889
Actual / 365334.246575342466
30E / 360333.333333333333
30 / 360 ISDA333.333333333333
NL / ACT332.417582417582
NL / 365331.506849315069
NL / 360336.111111111111
Actual / 364335.164835164835
BOND NON-EOM333.333333333333
Actual / Actual NON-EOM333.333333333333
Actual / 360 NON-EOM338.888888888889
Actual / 365 NON-EOM334.246575342466
30E / 360 NON-EOM333.333333333333
30 / 360 ISDA NON-EOM333.333333333333
NL / ACT NON-EOM332.417582417582
NL / 365 NON-EOM331.506849315069
NL / 360 NON-EOM336.111111111111
Actual / 364 NON-EOM335.164835164835
BUS / 252330.516609656145
Actual / ISDA333.572872220975
Actual / ISMA333.333333333333
Actual / 365L333.333333333333
Actual / AFB333.333333333333
BUS / 252 NON-EOM330.516609656145

See Also

ACCRINT - Calculate the accrued interest for a security that pays periodic interest.

ACCRINTM - Calculate the accrued interest for a security that pays interest at maturity.

AIFACTOR_IAM - Calculate the Accrued Interest Factor for an Interest-at-Maturity security

AIFACTOR_OFC - Calculate the Accrued Interest Factor for a bond during its odd first coupon period

AIFACTOR_OLC - Calculate the Accrued Interest Factor for a bond during its odd last coupon period

AIFACTOR_RPI - Calculate the Accrued Interest Factor for a Regular Periodic Interest period

BONDINT - Accrued interest on a bond paying regular, periodic interest

COMPINT - Calculate the accrued interest for a security where interest is compounded periodically and paid at maturity

ODDCOMPINT - Calculate the accrued interest in first coupon period for a bond with an odd first coupon and a par value of 100

ODDFINT - Accrued interest for a bond with an odd first coupon

ODDLINT - Accrued interest for a bond with an odd last coupon