# Local Volatility calculation in Python

I am trying to price Local Volatility in Python using Dupire (Finite Difference Method).

I have following set of information

Spot: 770.05, Strike: 850, Type: 'C', rfr: 0.0066, time to maturity = 25/365 days, IV: 0.19468.

In order to solve using FDM we need to find

I have used following code in python, can you please let me know what is missing here.

deltat = 0.00071 delta = 1.5

dc_by_dt = ((bsm_price('c',0.1946811865981668,770.05,850,0.0066,25.55/365)+deltat,0)) -(bsm_price('c',0.1946811865981668,770.05,850,0.0066,deltat-(25.55/365),0))) / (2 * delta)

dc2_by_dk2 = ((bsm_price('c',0.1946811865981668,770.05,(850-delta),0.0066,25.55/365,0)) - 2 * (bsm_price('c',0.1946811865981668,770.05,850,0.0066,25.55/365,0)) + (bsm_price('c',0.1946811865981668,770.05,(850 + delta),0.0066,25.55/365,0))) / (delta*delta)

local = np.sqrt((dc_by_dt)/(0.5*(850*850)*dc2_by_dk2))

• From which library do you get bsm_price? Apr 29, 2019 at 15:17
• @Sanjay, Thanks for your reply. bsm_price is function I have defined to price options using black scholes formula. In that case you need scipy and numpy. But, my real concern is about local volatility using dupire formula can you please help me with any real life example where you have worked on to get local volatility based on Implied Volatility as an input. Thanks
Apr 30, 2019 at 2:05

Unfortunately not written in Python, but in R. If you have experience with R this real life example posted on an underground quant blog has step by step what you may be looking for: (Scroll down to conclusion)

https://quantipy.wordpress.com/2017/08/21/implementation-of-dupires-formula-for-local-volatilities/

(I do not take credit for this persons work), but it's intuition has helped me greatly when I was tackling a similar volatility model problem.

I hope it helps.

• Hi Vincent, Thanks for your reply, I did look at his work and I really appreciate that he has put lots of effort to do that. I am more keen to do it in python so I guess I need to figure out my own way.