+ All Categories
Home > Documents > Implied Volatility using Python's Pandas Library - Nag

Implied Volatility using Python's Pandas Library - Nag

Date post: 11-Feb-2022
Category:
Upload: others
View: 13 times
Download: 0 times
Share this document with a friend
26
Experts in numerical algorithms and HPC services Implied Volatility using Python’s Pandas Library Brian Spector Thalesians Meetup London 15 th January 2014
Transcript
Page 1: Implied Volatility using Python's Pandas Library - Nag

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

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

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

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

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

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

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

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

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

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

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

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

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

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

15 Numerical Excellence Commercial in Confidence

Implied Volatility – Different Curves?

Page 16: Implied Volatility using Python's Pandas Library - Nag

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

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

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

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

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

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

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

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

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

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?


Recommended