<-- Previous || Up || Next -->

Coupon Days After Settlement Test Sub
Math Financial Class

Public Sub CouponDaysAfterSettlementTest()
    'Compare the CouponDaysAfterSettlement function to Excel's COUPDAYBS function.

    'Note: You must establish a Reference to atpvbaen.xls within Excel for this to work.

    Const FmDate = #1/1/1991#
    Const ToDate = #1/1/1998#

    Dim datSettl As Date, datMatur As Date, intFreqLog2%, intFreq%, intBasis%, varResES, varResXL, datNCD As Date

    For datSettl = FmDate To ToDate
        DoEvents
        If Day(datSettl) = 5 Then datSettl = datSettl + 20
        If Day(datSettl) = 1 Then Debug.Print Now, datSettl

        For datMatur = datSettl + 1 To ToDate
            If Day(datMatur) = 5 Then datMatur = datMatur + 20

            For intFreqLog2 = 0 To 2
                intFreq = 2 ^ intFreqLog2

                For intBasis = 0 To 4
                    ' Don't test US_NASD_30_360 and European_30_360 bases
                    ' because of probable bugs in Excel COUPDAYSNC function.
                    If intBasis <> US_NASD_30_360 _
                    And intBasis <> European_30_360 Then
                        varResES = CouponDaysAfterSettlement(datSettl, datMatur, intFreq, intBasis)
                        varResXL = COUPDAYSNC(datSettl, datMatur, intFreq, intBasis)
        
                        If (IsNull(varResES) And Not IsNull(varResXL)) _
                        Or (Not IsNull(varResES) And IsNull(varResXL)) _
                        Or (varResES <> varResXL) Then
                            datNCD = coupncd(datSettl, datMatur, intFreq, intBasis)
                            Debug.Print datSettl, datMatur, datNCD, intFreq, intBasis, varResXL, varResES, varResES - varResXL
                        End If
                    End If
                Next intBasis
            Next intFreqLog2
        Next datMatur
    Next datSettl

End Sub

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.