Hello all,
First-time post, so please excuse my mistakes. I've hit an issue that I haven't managed to solve by searching through previous questions--so I am finally turning to the experts!
I have a spreadsheet that performs two functions: 1. calculating Black-Scholes option prices from a given volatility input; 2. backing-out implied volatility from the market option price. The first is performed entirely within Excel. The second--the volatility calculations--are performed using a simple Newton Raphson iterative UDF (below) in VBA.
The formula to call the UDF is:
=IFERROR(IVolCall(Spot Price, Strike Price, Risk-Free Rate, Dividend Yield, Days to Expiry, Market Option Price),"N/A").
All inputs are contained within the spreadsheet itself.
The issue I am having is that this formula recalculates on any change to the worksheet. I initially thought it was just hiding and unhiding rows, but a simple test script to insert a number into a blank cell also causes Excel to run through each UDF. To the best of my understanding, the UDFs shouldn't be volatile and so I am not sure why this is occurring.
Any help would be much appreciated!
Thanks,
Matt
IVolCall code (Dims excluded):
First-time post, so please excuse my mistakes. I've hit an issue that I haven't managed to solve by searching through previous questions--so I am finally turning to the experts!
I have a spreadsheet that performs two functions: 1. calculating Black-Scholes option prices from a given volatility input; 2. backing-out implied volatility from the market option price. The first is performed entirely within Excel. The second--the volatility calculations--are performed using a simple Newton Raphson iterative UDF (below) in VBA.
The formula to call the UDF is:
=IFERROR(IVolCall(Spot Price, Strike Price, Risk-Free Rate, Dividend Yield, Days to Expiry, Market Option Price),"N/A").
All inputs are contained within the spreadsheet itself.
The issue I am having is that this formula recalculates on any change to the worksheet. I initially thought it was just hiding and unhiding rows, but a simple test script to insert a number into a blank cell also causes Excel to run through each UDF. To the best of my understanding, the UDFs shouldn't be volatile and so I am not sure why this is occurring.
Any help would be much appreciated!
Thanks,
Matt
IVolCall code (Dims excluded):
Code:
Function IVolCall(S, X, r, q, days, Price)
'The initial implied volatility estimation is hard-coded for simplicity.
Guess = 0.15
'Tolerance for iteration
Difference = 0.05
'365 trading days are used
t = days / 365
ert = Exp(-r * t)
eqt = Exp(-q * t)
'Loop to 1000 or until the minimum difference is met.
For I = 1 To 1000
d1 = ((Log(S / X) + (r - q + 0.5 * Guess ^ 2) * t) / (Guess * Sqr(t))) 'Calculate d1 in B.S.
d2 = d1 - Guess * Sqr(t) 'Calculate d2 in B.S.
nd1 = Application.NormSDist(d1)
nd2 = Application.NormSDist(d2)
Value = (S * eqt * nd1 - X * ert * nd2) 'B.S. call
Vega = S * eqt * Sqr(t) * Application.NormDist(d1, 0, 1, False) 'B.S. vega
Guess = ((Price - Value + Vega * Guess) / (Vega)) 'Refined volatility estimate
If Abs(Value - Price) < Difference Then Exit For 'Iteration criteria
Next
IVolCall = Guess
End Function