http://www.six-swiss-exchange.com/download/trading/products/bonds/accrued_interest_en.pdf
'
' Calculate_accrued_interest
'
Public Const GERMAN = 1, SPEC_GERMAN = 2, ENGLISH = 3, FRENCH = 4, _
US = 5, ISMA_YEAR = 6, ISMA_99N = 7, ISMA_99U = 8 ' day count methods
Public Const ERROR_BAD_DCM = -1, ERROR_BAD_DATES = -2 ' error returns
Public Function AI_Factor(ByVal DCM As Long, _
ByVal D1M1Y1 As Date, ByVal D2M2Y2 As Date, ByVal D3M3Y3 As Date, _
ByVal F As Double, _
ByVal Maturity As Date _
) As Double
' DCM is day count method code
' D1M1Y1 is D1.M1.Y1 etc.
' F is the coupon frequency
' Maturity is the maturity date
Dim D1, D1x, M1, Y1 As Long ' variables used to hold day, month and year
Dim D2, D2x, M2, Y2 As Long ' values separately
Dim D3, M3, Y3 As Long
Dim Anchor As Date ' "anchor" date: start date for notional...
Dim AD, AM, AY As Long ' ...periods
Dim WM, WY As Long ' "working dates" in notional period loop
Dim Target As Date ' end date for notional period loop
Dim N, Nx As Long ' number of interest-bearing days
Dim Y As Double ' length of a year (ISMA-Year)
Dim L As Long ' regular coupon length in months
Dim C, Cx As Double ' notional period length in days
Dim Fx As Double ' applicable coupon frequency
Dim Periodic, Regular As Boolean ' various flags
Dim Direction As Long
Dim CurrC, NextC, TempD As Date ' used for temporary serial date values
Dim i As Long ' temporary loop variable
'
' Check input dates
'
If (D1M1Y1 = 0) Or (D2M2Y2 = 0) Or (D3M3Y3 = 0) Or _
(D2M2Y2 < D1M1Y1) Or (D3M3Y3 <= D1M1Y1) Or (Maturity = 0) Then
AI_Factor = ERROR_BAD_DATES
Exit Function
End If
'
' Determine Number of Interest-bearing days, N
'
Select Case DCM
Case GERMAN ' RULE 1
D1 = Day(D1M1Y1): M1 = Month(D1M1Y1): Y1 = Year(D1M1Y1)
D2 = Day(D2M2Y2): M2 = Month(D2M2Y2): Y2 = Year(D2M2Y2)
If D1 = 31 Then
D1x = 30
ElseIf IsFebUltimo(D1M1Y1) Then ' end of February
D1x = 30
Else
D1x = D1
End If
If D2 = 31 Then
D2x = 30
ElseIf IsFebUltimo(D2M2Y2) Then ' end of February
D2x = 30
Else
D2x = D2
End If
N = (D2x – D1x) + 30 * (M2 – M1) + 360 * (Y2 – Y1)
Keine Kommentare:
Kommentar veröffentlichen