Function cap(Sett_d As Date, last_fix_d As Date, base_rate As Double, factor As Double, prev_d As Date, next_d As Date, Mat_d As Date, vola As Double, Date_v As Object, PV_v As Object) As Double ' Valuation of caps Dim Filter As Double, Strike As Double Filter = 10 Strike = base_rate / factor / 100 Dim n As Long, i As Long n = Int((Mat_d - next_d) / 180) - 1 Dim from_d As Date, to_d As Date Dim T1 As Double, T2 As Double, zwi As Double, d1 As Double, d2 As Double, thathelps As Double For i = 1 To n from_d = Application.Run("Edate", next_d, 6 * i) to_d = Application.Run("Edate", next_d, 6 * (1 + i)) T1 = Application.Days360(Sett_d, from_d) / 360 T2 = Application.Days360(Sett_d, to_d) / 360 If from_d >= last_fix_d - Filter And to_d <= Mat_d + Filter Then r = (inter2(Date_v, PV_v, from_d) / inter2(Date_v, PV_v, to_d) - 1) * 360 / (from_d - to_d) d1 = (Application.Ln(r / Strike) + 0.5 * vola ^ 2 * T1) / (vola * T1 ^ 0.5) d2 = d1 - vola * T1 ^ 0.5 thathelps = r * Application.NormSDist(d1) - Strike * Application.NormSDist(d2) zwi = inter2(Date_v, PV_v, from_d) * thathelps * (to_d - from_d) / 360 * 100 Else zwi = 0 End If cap = cap + zwi Next cap = cap * factor End Function