Hi People,
I am struggling to code up a UDF that can be used to find out the implied volatility for a futures option given the following variables:
Option Price
Spot Price
Strike Price
Risk Free Rate (RFR)
Option Type ie Call or Put
Expiry Date
Deal Date
I have found the following code online but I cannot understand the Variables named "Seed" and I also don't understand "ctr" as I have highlighted below:
Can anyone tell me what this means?
I am struggling to code up a UDF that can be used to find out the implied volatility for a futures option given the following variables:
Option Price
Spot Price
Strike Price
Risk Free Rate (RFR)
Option Type ie Call or Put
Expiry Date
Deal Date
I have found the following code online but I cannot understand the Variables named "Seed" and I also don't understand "ctr" as I have highlighted below:
Function BlackScholesNewton(ByVal Seed As Double, ByVal
Precision As Double, ByVal S As Double, ByVal K As Double, ByVal r
As Double, ByVal q As Double, ByVal t As Double, ByVal sigma As
Double) As Double
Dim x_next As Double
Dim x_n As Double
Dim error_val As Double
Dim ctr As Integer
x_n = Seed
ctr = 0
Do
x_next = x_n - Black_Scholes(S, K, r, q, t, sigma) / Vega(S, K, r, q, t,
sigma)
error_val = x_next - x_n
x_n = x_next
ctr = ctr + 1
Loop Until (Abs(error_val) <= Precision Or ctr = 1000)
BlackScholesNewton = x_next
End FunctionPrecision As Double, ByVal S As Double, ByVal K As Double, ByVal r
As Double, ByVal q As Double, ByVal t As Double, ByVal sigma As
Double) As Double
Dim x_next As Double
Dim x_n As Double
Dim error_val As Double
Dim ctr As Integer
x_n = Seed
ctr = 0
Do
x_next = x_n - Black_Scholes(S, K, r, q, t, sigma) / Vega(S, K, r, q, t,
sigma)
error_val = x_next - x_n
x_n = x_next
ctr = ctr + 1
Loop Until (Abs(error_val) <= Precision Or ctr = 1000)
BlackScholesNewton = x_next
Can anyone tell me what this means?