The Option-Graph Project Option-Graph.com

The FindIV Visual Basic Function

   When the "Find IV" button is pressed, we need a function to find the Implied Volatility based on all the inputs except the IV.

That is what the code below does. Copy and paste it into the OptionCalcs module, below the words "end function" of the optionvalue() function.

Note: the Black-Scholes optionvalue() function we already added finds the option price based on all inputs except the option price, so we don't need anything more to use the code that will be behind the "Find Price" button.

Function findIV(ByVal stockprice As Single, ByVal strikeprice As Single, ByVal timeremain As Single, ByVal interestrate As Single, ByVal dividend As Single, ByVal optval As Double, ByVal opttype As String) As Single

'uses a brute force method to find the IV that matches an option price

Dim callval, putval, result As Single

If opttype.Contains("Call") Then
For iv = 0.0001 To 9 Step 0.0001 'changes the volatility .01% per run, from .01% to 900%
callval = optionvalue(stockprice, strikeprice, timeremain, interestrate, iv, dividend,opttype)
If callval > optval Then 'this way works better for calls
result = Math.Round(iv * 100, 2) 'returns IV to 2 decimals
Exit For
End If
Next
End If

If opttype.Contains("Put") Then
For iv = 0.0001 To 9 Step 0.0001
putval = optionvalue(stockprice, strikeprice, timeremain, interestrate, iv, dividend,opttype)
If putval + 0.01 > optval Then
result = Math.Round(iv * 100, 2)
Exit For
End If
Next
End If

Return result

End Function

Save your project.

     

Home Page Downloads
Previous Step: The Black-Scholes Function
Next Step: The EquityOption Class

Copyright 2017 option-info.com Privacy Policy

Questions, corrections, suggestions, comments to: this contact

Want to learn options, find strategies? Visit www.option-info.com