Fast Implied Volatility Calculation in Python

Neetesh picture Neetesh · Apr 18, 2020 · Viewed 7.4k times · Source

I am looking for a library which i can use for faster way to calculate implied volatility in python. I have options data about 1+ million rows for which i want to calculate implied volatility. what would be the fastest way i can calculate IV's. I have tried using py_vollib but it doesnt support vectorization. It takes about 5 mins approx. to calculate. Are there any other libraries which can help in faster calculation. What do people use in real time volatility calculations where there are millions of rows coming in every second?

Answer

Eric Hulsinga picture Eric Hulsinga · Aug 24, 2020

If you change all calls to norm.cdf()-method into ndtr(), you will get a 2.4 time performance increase.

And if you change norm.pdf()-method into norm._pdf(), you will get another (huge) increase.

With both changes implemented, the example above dropped from 17.7 [s] down to 0.99 [s] on my machine.

You will loose error checking etc. but in this case you probably don't need all that.

See: https://github.com/scipy/scipy/issues/1914

ndtr() is in scipy.special