Function mcld(CouponRate As Double, n As Integer, k As Integer, yield As Double)
Dim i As Integer
Dim PVCF() As Double
Dim PVTCF As Double
Dim duration As Double
ReDim PVCF(1 To n * k)
PVTCF = 0
For i = 1 To n * k
PVCF(i) = ((CouponRate / k) * 100) / Application.WorksheetFunction.Power(1 + yield / k, i)
PVTCF = PVTCF + PVCF(i)
Next i
PVCF(n * k) = PVCF(n * k) + 100 / Application.WorksheetFunction.Power(1 + yield / k, n * k)
PVTCF = PVTCF + 100 / Application.WorksheetFunction.Power(1 + yield / k, n * k)
duration = 0
For i = 1 To n * k
duration = duration + PVCF(i) * i / k
Next i
duration = duration / PVTCF
mcld = duration
End Function