Implied volatility calculation method
Author: Partha
Creation Date: 9/23/2019 7:17 AM
profile picture

Partha

#1
Hi Eugene, Cone

Fidelity users can get option prices directly in WL pro and since you have the Black Scholes formula already coded in, it might be useful to provide a method to compute the implied volatility by back solving for volatility.....

profile picture

Eugene

#2
I'm not familiar with IV formulas but if you have interest in it you could try to come up with such method in your own Strategy code. See this for example, looks pretty complete:

What is an efficient method to find implied volatility?
profile picture

Partha

#3
Eugene

Thanks as always ...this is a good start point...I will try to work off it and if I get it to work, I will share my code....
profile picture

Cone

#4
Here's a quick-n-dirty something I came up with.. seems to work. Requires Community.Components.

Instructions:
1. Assumes that you have Fidelity data. Option format: -SYMyyMMdd[P/C]strike
2. Click on the underlying symbol and adjust parameters
3. If your data provider cannot request real option data, then enter it manually for double actualOptionPrice (about line 42) and comment out the previous DataSeries optionPr statement.

CODE:
Please log in to see this code.
profile picture

Cone

#5
Hmmm, seems to only work for Calls.. need to fix a bug for Puts.

--- update ---
Fixed above now.
profile picture

Partha

#6
thanks Cone let me try your solution...many thanks
profile picture

Partha

#7
Hi Cone

I tested on Disney stock for the Oct 18 135 Call and 130 Put and there seems to be issue...maybe the algorithm is finding some other root...In both cases it shows the IV as -1...

profile picture

Cone

#8
Fixed above. I added a correction for a dividend paid in the future before expiry too (script only works for Fidelity Wealth-Lab Pro).

I found one case that didn't make sense at first: -PFE191018P40 - the Pfizer Oct 40 Put.
PFE Strike: 40
-PFE191018P40
Days to Exp: 23
Synth Price: 4.11
Real Price: 3.15
Hist Vol: 18.9
Hit limit <- This means that changing implied volatility isn't sufficiently affecting pricing
Impl Vol: 17.7

In this case, PFE closed yesterday at 35.90 - that gives the 40 Put AT LEAST a value of $4.10, however the actual price is returned to be $3.15. Digging into it, that's because this option last traded on 9/13/2019 - when PFE was trading closer to $37. Consequently, in this case you cannot really calculate the implied volatility "today" because you don't have a recent price.

The procedure could be modified to find the implied volatility on the last day the option traded, but let's call it "good for now" ;)
profile picture

Partha

#9
Cone it is perfectly possible for IV to be less than HV and pro option traders who mostly sell options like to sell when IV is higher...so even if the price was same in this case $37, IV can be than HV...and that is when there is a risk on the sell side if the underlying were to move quickly in the opposite direction...thanks for your help
profile picture

Partha

#10
Hi Cone,

I made a little modification to your code to search for options at diffrerent strike price expressed as a % of the EOD closing price...it works great and I am going to use this to find options for entire data sets...one issue I have is that when ever it does not find a symbol, it throws an exception...now when I press enter or click OK the msg goes away and code continues...However since I want to do this over many stocks it becomes tedious to press ENTER all the time...can you suggest some code to take care of this small issue

CODE:
Please log in to see this code.


In the code above I have commented the code that I am not able to get to work (Line 64 and three lines below)

//// This part of the code does not seem to work


attached is the run time message I get whenever it does not find a symbol in Fidelity...how do I get rid of the message and continue with code?
profile picture

Cone

#11
You have to request a valid strike. There is no 222 Oct Put for AAPL, only 220 or 225, etc.

Don't slide the "slider", instead click it and enter a strike increment that will always return a valid strike for the stock that you're testing. AAPL, for example, only strikes every $5, whereas QQQ does every $1. Especially after recent splits, stocks may strike every $2.50 or another decimal value.

Incidentally, the code chooses the strike just above the last-trade price. You can modify "double strike = ... " as you like.
profile picture

Eugene

#12
Hint: If it's a modal Windows error dialog, you could strike Ctrl-C to copy the underlying error message and Ctrl-V to paste it when replying (a standard Windows shortcut).

In fact this is a known issue, frequently encountered when backtesting options. You could find its background and some workarounds on the Open Issues list in our Wiki and on the forum:

Error: "Invalid Benchmark Buy and Hold Symbol: XAO"
Prevent strategy from displaying message boxes on exception
Invalid Benchmark Buy and Hold Symbol messagebox
And even here: How to code "nearest term ATM call option"?

btw, nice code.
profile picture

Partha

#13
"Database provider by MS123 (Eugene)" solved it :-)
profile picture

Eugene

#14
If you installed it as a workaround following an observation from this thread, then it's really amusing. :) But whatever works for you is fine with me!
profile picture

Partha

#15
I did not have the guts to put the AutoIT script on my workstation ;-)
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).