implied volatility using python's pandas library - nag
TRANSCRIPT
![Page 1: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/1.jpg)
Experts in numerical algorithms and HPC services
Implied Volatility using Pythonβs Pandas Library
Brian Spector
Thalesians Meetup London
15th January 2014
![Page 2: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/2.jpg)
2 Numerical Excellence Commercial in Confidence
Overview
β’ Motivation
β’ Python
β’ Pandas
β’ Implied Volatility
β Timings in python
β Different Volatility Curves
β Fitting data points
![Page 3: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/3.jpg)
3 Numerical Excellence Commercial in Confidence
Python
β’ Dynamically typed language
β’ Uses white spaces (as oppose to brackets) for control statements.
β’ Has grown in popularity:
β’ http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
Programming Language
2014 2009 2004 1999
Python Ranking 8 6 11 22
![Page 4: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/4.jpg)
4 Numerical Excellence Commercial in Confidence
Python
β’ Why use python?
β Cheap
β Easy to learn
β Powerful
![Page 5: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/5.jpg)
5 Numerical Excellence Commercial in Confidence
Python
β’ Why use python?
β Cheap
β Easy to learn
β Powerful
β’ Why use python over R?
β βI would rather do math in a programming language than programming in a math language.β
![Page 6: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/6.jpg)
6 Numerical Excellence Commercial in Confidence
Python
β’ What python has:
β Many built-in powerful packages
β OO programming
β’ Classes
β’ Base + Derived Classes
β Plotting
β’ What python does not have:
β Operator Overloading
β Multiple constructors
β Speed
β Pointers
β ???
![Page 7: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/7.jpg)
7 Numerical Excellence Commercial in Confidence
Numpy
β’ Has made numerical computing much easier in recent years.
β’ Numpy matrices / arrays
β’ Numpy.linalg
β’ Behind many of these functions are LAPACK + BLAS!
![Page 8: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/8.jpg)
8 Numerical Excellence Commercial in Confidence
Scipy
β’ Special functions (scipy.special)
β’ Integration (scipy.integrate)
β’ Optimization (scipy.optimize)
β’ Interpolation (scipy.interpolate)
β’ Fourier Transforms (scipy.fftpack)
β’ Signal Processing (scipy.signal)
β’ Linear Algebra (scipy.linalg)
β’ Sparse Eigenvalue Problems with ARPACK
β’ Compressed Sparse Graph Routines scipy.sparse.csgraph
β’ Spatial data structures and algorithms (scipy.spatial)
β’ Statistics (scipy.stats)
β’ Multidimensional image processing (scipy.ndimage)
![Page 9: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/9.jpg)
9 Numerical Excellence Commercial in Confidence
nag4py
β’ Built on top of NAG C Library + Documentation
β’ 1600 NAG functions easily accessible from python
β’ 25 examples programs to help users call NAG functions
from nag4py.c05 import c05ayc
from nag4py.util import NagError,Nag_Comm
![Page 10: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/10.jpg)
10 Numerical Excellence Commercial in Confidence
Pandas
β’ Data Analysis Package
β’ Many nice built in functions
β’ Common tools:
β Series / DataFrame
β Reading + Writing CSVs
β Indexing, missing data, reshaping
β Common time series functionality
(Examples)
![Page 11: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/11.jpg)
11 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ Black Scholes Formula for pricing a call/put option is a function of 6 variables:
β πΆ π0, πΎ, π, π, π, π = π0π π1 β πΎπβπππ π2
β’ Where
β π1,2 =1
π πππ
π
πΎ+ π π Β±
π2
2
β π π₯ = Standard Normal CDF
![Page 12: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/12.jpg)
12 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ We can observe the following in the market:
β’ πΆ π0, πΎ, π, π, π, π = πΆ
β’ But what is ?
β’ ππππ β πΆπ΅π π0, πΎ, π, ππππ, π, π = ππππππ‘ πππππ
![Page 13: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/13.jpg)
13 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ We can observe the following in the market:
β’ πΆ π0, πΎ, π, π, π, π = πΆ
β’ But what is ?
β’ ππππ β πΆπ΅π π0, πΎ, π, ππππ, π, π = ππππππ‘ πππππ
β’ Does ππππexist?
![Page 14: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/14.jpg)
14 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ We can observe the following in the market:
β’ πΆ π0, πΎ, π, π, π, π = πΆ
β’ But what is ?
β’ ππππ β πΆπ΅π π0, πΎ, π, ππππ, π, π = ππππππ‘ πππππ
β’ Does ππππexist?
β Yes
(Examples)
![Page 15: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/15.jpg)
15 Numerical Excellence Commercial in Confidence
Implied Volatility β Different Curves?
![Page 16: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/16.jpg)
16 Numerical Excellence Commercial in Confidence
Implied Volatility β Different Curves?
β’ No hyphen or letter present = Composite A = AMEX American Stock Exchange B = BOX Boston Stock Exchange - Options E = CBOE Chicago Board Options Exchange I = BATS J = NASDAQ OMX BX O = NASDAQ OMX P = NYSE Arca X = PHLX Philadelphia Stock Exchange Y = C2 Exchange 4 = Miami Options Exchange 8 = ISE International Securities Exchange
![Page 17: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/17.jpg)
17 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ Reasons for skews/smiles?
β Risk Preferences
β Fat tailed distributions
![Page 18: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/18.jpg)
18 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM
fsolve + NAG BSM
nag4py
NAG C
![Page 19: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/19.jpg)
19 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM
nag4py
NAG C
![Page 20: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/20.jpg)
20 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM ~15 seconds
nag4py
NAG C
![Page 21: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/21.jpg)
21 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM ~15 seconds
nag4py ~10 seconds
NAG C
![Page 22: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/22.jpg)
22 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM ~15 seconds
nag4py ~10 seconds
NAG C ~.29 seconds
![Page 23: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/23.jpg)
23 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM ~15 seconds
nag4py ~10 seconds
NAG C ~.29 seconds
β’ Derivatives? β’ We have the derivative, vega
β’ππͺ
ππ= πΊ β π» β π΅β²(π π)
![Page 24: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/24.jpg)
24 Numerical Excellence Commercial in Confidence
Fitting Data Points
β’ In our script we had k = l = 3β¦
β What if we try different values?
![Page 25: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/25.jpg)
25 Numerical Excellence Commercial in Confidence
Fitting Data Points
β’ In our script we had k = l = 3β¦
β What if we try different values?
β’ Poor results, can we do better?
![Page 26: Implied Volatility using Python's Pandas Library - Nag](https://reader031.vdocuments.net/reader031/viewer/2022021211/620650df8c2f7b1730069185/html5/thumbnails/26.jpg)
26 Numerical Excellence Commercial in Confidence
Thank You
Questions?
β’ Further reading see:
β’ http://pandas.pydata.org/
β’ http://www.nag.co.uk/python.asp
β’ http://blog.nag.com/2013/10/implied-volatility-using-pythons-pandas.html