Hello guys,
I got the following code:
When I want to run the first function, I get an ByRef argument type mismatch for Yld and I dont understand why.
Thanks for help in advance!
I got the following code:
Code:
Public Function YTM(FaceV, Coupon, Price, Matur, Freq As Double) As Double
Dim i As Long
Dim Yld, Diff As Double
Const Inc As Double = 0.00001
Const Iters As Long = 100000
Select Case FaceV * Coupon / Price
Case Is > Coupon
Yld = (FaceV * Coupon / Price)
Do
Yld = Yld + Inc
i = i + 1
Diff = Price - CurrP(FaceV, Coupon, Matur, Freq, Yld)
Loop While i <= Iters And Diff < 0
Case Is < Coupon
Yld = (FaceV * Coupon / Price)
Do
Yld = Yld - Inc
i = i + 1
Diff = Price - CurrP(FaceV, Coupon, Matur, Freq, Yld)
Loop While i <= Iters And Diff > 0
Case Is = Coupon
Yld = Coupon
End Select
MsgBox Round(Yld * 100, 4) & "% Yield - " & Yld
YTM = Yld
End Function
Code:
Public Function CurrP(FaceV, Coupon, Matur, Freq, YTM As Double) As Double
Dim i As Integer
Dim Price As Double
Freq = 1 / Freq
Price = (Matur - (Freq * Int(Matur / Freq))) * Coupon * FaceV
For i = 1 To Int(Matur * Freq)
Price = Price + (Coupon * FaceV * Freq) / (1 + YTM) ^ i
Next i
Price = Price + (FaceV) / (1 + YTM) ^ Int(Matur * Freq)
CurrP = Price
End Function
When I want to run the first function, I get an ByRef argument type mismatch for Yld and I dont understand why.
Thanks for help in advance!