implied volatility using python's pandas library - nag
TRANSCRIPT
Experts in numerical algorithms and HPC services
Implied Volatility using Pythonβs Pandas Library
Brian Spector
Thalesians Meetup London
15th January 2014
2 Numerical Excellence Commercial in Confidence
Overview
β’ Motivation
β’ Python
β’ Pandas
β’ Implied Volatility
β Timings in python
β Different Volatility Curves
β Fitting data points
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
4 Numerical Excellence Commercial in Confidence
Python
β’ Why use python?
β Cheap
β Easy to learn
β Powerful
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.β
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
β ???
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!
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)
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
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)
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
12 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ We can observe the following in the market:
β’ πΆ π0, πΎ, π, π, π, π = πΆ
β’ But what is ?
β’ ππππ β πΆπ΅π π0, πΎ, π, ππππ, π, π = ππππππ‘ πππππ
13 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ We can observe the following in the market:
β’ πΆ π0, πΎ, π, π, π, π = πΆ
β’ But what is ?
β’ ππππ β πΆπ΅π π0, πΎ, π, ππππ, π, π = ππππππ‘ πππππ
β’ Does ππππexist?
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)
15 Numerical Excellence Commercial in Confidence
Implied Volatility β Different Curves?
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
17 Numerical Excellence Commercial in Confidence
Implied Volatility
β’ Reasons for skews/smiles?
β Risk Preferences
β Fat tailed distributions
18 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM
fsolve + NAG BSM
nag4py
NAG C
19 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM
nag4py
NAG C
20 Numerical Excellence Commercial in Confidence
Implied Volatility Timings
Method Timing
fsolve + python BSM ~180 seconds
fsolve + NAG BSM ~15 seconds
nag4py
NAG C
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
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
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
β’ππͺ
ππ= πΊ β π» β π΅β²(π π)
24 Numerical Excellence Commercial in Confidence
Fitting Data Points
β’ In our script we had k = l = 3β¦
β What if we try different values?
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?
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