Derivative Analytics With Python
Derivative Analytics With Python
Analytics
with Python
For other titles in the Wiley Finance series
please see www.wiley.com/finance
Derivatives
Analytics
with Python
Data Analysis, Models, Simulation,
Calibration and Hedging
YVES HILPISCH
This edition first published 2015
© 2015 John Wiley & Sons Ltd
Registered office
John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United
Kingdom
For details of our global editorial offices, for customer services and for information about how to apply
for permission to reuse the copyright material in this book please see our website at www.wiley.com.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or
otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior
permission of the publisher.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material
included with standard print versions of this book may not be included in e-books or in
print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version
you purchased, you may download this material at http://booksupport.wiley.com. For more information
about Wiley products, visit www.wiley.com.
Designations used by companies to distinguish their products are often claimed as trademarks. All
brand names and product names used in this book are trade names, service marks, trademarks or
registered trademarks of their respective owners. The publisher is not associated with any product or
vendor mentioned in this book.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts
in preparing this book, they make no representations or warranties with respect to the accuracy or
completeness of the contents of this book and specifically disclaim any implied warranties of
merchantability or fitness for a particular purpose. It is sold on the understanding that the publisher is
not engaged in rendering professional services and neither the publisher nor the author shall be liable
for damages arising herefrom. If professional advice or other expert assistance is required, the services
of a competent professional should be sought.
A catalogue record for this book is available from the British Library.
List of Tables xi
Preface xvii
CHAPTER 1
A Quick Tour 1
1.1 Market-Based Valuation 1
1.2 Structure of the Book 2
1.3 Why Python? 3
1.4 Further Reading 4
PART ONE
The Market
CHAPTER 2
What is Market-Based Valuation? 9
2.1 Options and their Value 9
2.2 Vanilla vs. Exotic Instruments 13
2.3 Risks Affecting Equity Derivatives 14
2.3.1 Market Risks 14
2.3.2 Other Risks 15
2.4 Hedging 16
2.5 Market-Based Valuation as a Process 17
CHAPTER 3
Market Stylized Facts 19
3.1 Introduction 19
3.2 Volatility, Correlation and Co. 19
3.3 Normal Returns as the Benchmark Case 21
v
vi CONTENTS
PART TWO
Theoretical Valuation
CHAPTER 4
Risk-Neutral Valuation 49
4.1 Introduction 49
4.2 Discrete-Time Uncertainty 50
4.3 Discrete Market Model 54
4.3.1 Primitives 54
4.3.2 Basic Definitions 55
4.4 Central Results in Discrete Time 57
4.5 Continuous-Time Case 61
4.6 Conclusions 66
4.7 Proofs 66
4.7.1 Proof of Lemma 1 66
4.7.2 Proof of Proposition 1 67
4.7.3 Proof of Theorem 1 68
CHAPTER 5
Complete Market Models 71
5.1 Introduction 71
5.2 Black-Scholes-Merton Model 72
5.2.1 Market Model 72
5.2.2 The Fundamental PDE 72
5.2.3 European Options 74
5.3 Greeks in the BSM Model 76
5.4 Cox-Ross-Rubinstein Model 81
5.5 Conclustions 84
5.6 Proofs and Python Scripts 84
5.6.1 Itô’s Lemma 84
Contents vii
CHAPTER 6
Fourier-Based Option Pricing 95
6.1 Introduction 95
6.2 The Pricing Problem 96
6.3 Fourier Transforms 97
6.4 Fourier-Based Option Pricing 98
6.4.1 Lewis (2001) Approach 98
6.4.2 Carr-Madan (1999) Approach 101
6.5 Numerical Evaluation 103
6.5.1 Fourier Series 103
6.5.2 Fast Fourier Transform 105
6.6 Applications 107
6.6.1 Black-Scholes-Merton (1973) Model 107
6.6.2 Merton (1976) Model 108
6.6.3 Discrete Market Model 110
6.7 Conclusions 114
6.8 Python Scripts 114
6.8.1 BSM Call Valuation via Fourier Approach 114
6.8.2 Fourier Series 119
6.8.3 Roots of Unity 120
6.8.4 Convolution 121
6.8.5 Module with Parameters 122
6.8.6 Call Value by Convolution 123
6.8.7 Option Pricing by Convolution 123
6.8.8 Option Pricing by DFT 124
6.8.9 Speed Test of DFT 125
CHAPTER 7
Valuation of American Options by Simulation 127
7.1 Introduction 127
7.2 Financial Model 128
7.3 American Option Valuation 128
7.3.1 Problem Formulations 128
7.3.2 Valuation Algorithms 130
7.4 Numerical Results 132
7.4.1 American Put Option 132
7.4.2 American Short Condor Spread 135
7.5 Conclusions 136
7.6 Python Scripts 137
7.6.1 Binomial Valuation 137
7.6.2 Monte Carlo Valuation with LSM 139
7.6.3 Primal and Dual LSM Algorithms 140
viii CONTENTS
PART THREE
Market-Based Valuation
CHAPTER 8
A First Example of Market-Based Valuation 147
8.1 Introduction 147
8.2 Market Model 147
8.3 Valuation 148
8.4 Calibration 149
8.5 Simulation 149
8.6 Conclusions 155
8.7 Python Scripts 155
8.7.1 Valuation by Numerical Integration 155
8.7.2 Valuation by FFT 157
8.7.3 Calibration to Three Maturities 160
8.7.4 Calibration to Short Maturity 163
8.7.5 Valuation by MCS 165
CHAPTER 9
General Model Framework 169
9.1 Introduction 169
9.2 The Framework 169
9.3 Features of the Framework 170
9.4 Zero-Coupon Bond Valuation 172
9.5 European Option Valuation 173
9.5.1 PDE Approach 173
9.5.2 Transform Methods 175
9.5.3 Monte Carlo Simulation 176
9.6 Conclusions 177
9.7 Proofs and Python Scripts 177
9.7.1 Itô’s Lemma 177
9.7.2 Python Script for Bond Valuation 178
9.7.3 Python Script for European Call Valuation 180
CHAPTER 10
Monte Carlo Simulation 187
10.1 Introduction 187
10.2 Valuation of Zero-Coupon Bonds 188
10.3 Valuation of European Options 192
10.4 Valuation of American Options 196
10.4.1 Numerical Results 198
10.4.2 Higher Accuracy vs. Lower Speed 201
10.5 Conclusions 203
10.6 Python Scripts 204
10.6.1 General Zero-Coupon Bond Valuation 204
10.6.2 CIR85 Simulation and Valuation 205
Contents ix
CHAPTER 11
Model Calibration 223
11.1 Introduction 223
11.2 General Considerations 223
11.2.1 Why Calibration at All? 224
11.2.2 Which Role Do Different Model Components Play? 226
11.2.3 What Objective Function? 227
11.2.4 What Market Data? 228
11.2.5 What Optimization Algorithm? 229
11.3 Calibration of Short Rate Component 230
11.3.1 Theoretical Foundations 230
11.3.2 Calibration to Euribor Rates 231
11.4 Calibration of Equity Component 233
11.4.1 Valuation via Fourier Transform Method 235
11.4.2 Calibration to EURO STOXX 50 Option Quotes 236
11.4.3 Calibration of H93 Model 236
11.4.4 Calibration of Jump Component 237
11.4.5 Complete Calibration of BCC97 Model 239
11.4.6 Calibration to Implied Volatilities 240
11.5 Conclusions 243
11.6 Python Scripts for Cox-Ingersoll-Ross Model 243
11.6.1 Calibration of CIR85 243
11.6.2 Calibration of H93 Stochastic Volatility Model 248
11.6.3 Comparison of Implied Volatilities 251
11.6.4 Calibration of Jump-Diffusion Part of BCC97 252
11.6.5 Calibration of Complete Model of BCC97 256
11.6.6 Calibration of BCC97 Model to Implied Volatilities 258
CHAPTER 12
Simulation and Valuation in the General Model Framework 263
12.1 Introduction 263
12.2 Simulation of BCC97 Model 263
12.3 Valuation of Equity Options 266
12.3.1 European Options 266
12.3.2 American Options 268
12.4 Conclusions 268
12.5 Python Scripts 269
12.5.1 Simulating the BCC97 Model 269
12.5.2 Valuation of European Call Options by MCS 274
12.5.3 Valuation of American Call Options by MCS 275
x CONTENTS
CHAPTER 13
Dynamic Hedging 279
13.1 Introduction 279
13.2 Hedging Study for BSM Model 280
13.3 Hedging Study for BCC97 Model 285
13.4 Conclusions 289
13.5 Python Scripts 289
13.5.1 LSM Delta Hedging in BSM (Single Path) 289
13.5.2 LSM Delta Hedging in BSM (Multiple Paths) 293
13.5.3 LSM Algorithm for American Put in BCC97 295
13.5.4 LSM Delta Hedging in BCC97 (Single Path) 300
CHAPTER 14
Executive Summary 303
APPENDIX A
Python in a Nutshell 305
A.1 Python Fundamentals 305
A.1.1 Installing Python Packages 305
A.1.2 First Steps with Python 306
A.1.3 Array Operations 310
A.1.4 Random Numbers 313
A.1.5 Plotting 314
A.2 European Option Pricing 316
A.2.1 Black-Scholes-Merton Approach 316
A.2.2 Cox-Ross-Rubinstein Approach 318
A.2.3 Monte Carlo Approach 323
A.3 Selected Financial Topics 325
A.3.1 Approximation 325
A.3.2 Optimization 328
A.3.3 Numerical Integration 329
A.4 Advanced Python Topics 330
A.4.1 Classes and Objects 330
A.4.2 Basic Input-Output Operations 332
A.4.3 Interacting with Spreadsheets 334
A.5 Rapid Financial Engineering 336
Bibliography 341
Index 347
List of Tables
3.1 Option bid/ask spreads for call options on stocks of the DJIA index 31
3.2 Option bid/ask spreads for put options on stocks of the DJIA index 32
5.1 Valuation results from the CRR binomial algorithm for the European call
option; upper panel index level process, lower panel option value process 82
7.1 Valuation results from the LSM and DUAL algorithms for the American put
option from 25 different simulation runs with base case parametrization 134
7.2 Valuation results from the LSM and DUAL algorithms for the Short Condor
Spread from 25 different simulation runs with base case parametrization 135
10.1 Valuation results for European call and put options in H93 model for
parametrizations from Medvedev and Scaillet (2010) and M0 = 50,
I = 100,000. Performance yardsticks are PY1 = 0.025 and PY1 = 0.015. 195
10.2 Valuation results for European call and put options in H93 model for
parametrizations from Medvedev and Scaillet (2010) and M0 = 50,
I = 100,000. Performance yardsticks are PY1 = 0.025 and PY1 = 0.015. 197
10.3 Valuation results for American put options in H93 and CIR85 model for
parametrizations from Medvedev and Scaillet (2010). Performance yardsticks
are PY1 = 0.025 and PY1 = 0.015 200
10.4 Valuation results for American put options in H93 and CIR85 model for
parametrizations from Medvedev and Scaillet (2010). Performance yardsticks
are PY1 = 0.025 and PY1 = 0.015. 202
10.5 Valuation results for American put options in H93 and CIR85 model for
parametrizations from Medvedev and Scaillet (2010). Performance yardsticks
are PY1 = 0.01 and PY1 = 0.01 203
xi
List of Figures
2.1 Inner value of a European call option on a stock index with strike of 8,000
dependent on the index level at maturity 10
2.2 Black-Scholes-Merton value of a European call option on a stock index with
K = 9000, T = 1.0, r = 0.025 and 𝜎 = 0.2 dependent on the initial index
level S0 ; for comparison, the undiscounted inner value is also shown 12
3.1 A single simulated path for the geometric Brownian motion over a 10-year
period with daily log returns 22
3.2 Histogram of the daily log returns (bars) and for comparison the probability
density function of the normal distribution with the sample mean and
volatility (line) 22
3.3 Quantile-quantile plot of the daily log returns of the geometric Brownian
motion 23
3.4 Realized volatility for the simulated path of the geometric Brownian motion 24
3.5 Rolling mean log return (252 days), rolling volatility (252 days) and rolling
correlation between both (252 days) for geometric Brownian motion; dashed
lines are averages over the whole period shown 25
3.6 DAX index level quotes and daily log returns over the period from 01.
October 2004 to 30. September 2014 27
3.7 Histogram of the daily log returns of the DAX over the period from 01.
October 2004 to 30. September 2014 (bars) and for comparison the
probability density function of the normal distribution with the sample mean
and volatility (line) 27
3.8 Quantile-quantile plot of the daily log returns of the DAX over the period
from 01. October 2004 to 30. September 2014 28
3.9 Realized volatility for the DAX over the period from 01. October 2004 to 30.
September 2014 29
3.10 Rolling mean log return (252 days), rolling volatility (252 days) and rolling
correlation between both (252 days); dashed lines are averages over the
whole period shown 30
3.11 Implied volatilities from European call options on the EURO STOXX 50 on
30. September 2014 33
3.12 Daily quotes of 1 week Euribor and daily log changes over the period from
01. January 1999 to 30. September 2014 34
3.13 Histogram of daily log changes in 1 week Euribor in comparison to a normal
distribution with same mean and standard deviation (line) 35
3.14 Quantile-quantile plot of the daily log changes in the 1 week Euribor 35
xiii