Function rateudf(nper As Integer, pymt As Double, pv As Double, Optional fv As Double, Optional typ As Byte, Optional guess As Single) As Single
Dim ctr As Integer
Dim emia As Double, emib As Double, guessb As Double
If guess = 0 Then guess = 0.1
Do
emia = pmt(guess, nper, pv, fv, typ)
If WorksheetFunction.Round(emia, 4) = WorksheetFunction.Round(pymt, 4) Then
rateudf = guess
Exit Do
Else
guessb = guess * (pymt - emia) / emia + guess
emib = pmt(guessb, nper, pv, fv, typ)
If WorksheetFunction.Round(emib, 4) = WorksheetFunction.Round(pymt, 4) Then
rateudf = guessb
Exit Do
End If
End If
guess = (pymt - emia) / (emib - emia) * (guessb - guess) + guess
ctr = ctr + 1
Loop Until ctr >= 1000
End Function
|