Derivatives Analytics with Python: Data Analysis, Models, Simulation, Calibration and Hedging
3.5/5
()
About this ebook
Derivatives Analytics with Python shows you how to implement market-consistent valuation and hedging approaches using advanced financial models, efficient numerical techniques, and the powerful capabilities of the Python programming language. This unique guide offers detailed explanations of all theory, methods, and processes, giving you the background and tools necessary to value stock index options from a sound foundation. You'll find and use self-contained Python scripts and modules and learn how to apply Python to advanced data and derivatives analytics as you benefit from the 5,000+ lines of code that are provided to help you reproduce the results and graphics presented. Coverage includes market data analysis, risk-neutral valuation, Monte Carlo simulation, model calibration, valuation, and dynamic hedging, with models that exhibit stochastic volatility, jump components, stochastic short rates, and more. The companion website features all code and IPython Notebooks for immediate execution and automation.
Python is gaining ground in the derivatives analytics space, allowing institutions to quickly and efficiently deliver portfolio, trading, and risk management results. This book is the finance professional's guide to exploiting Python's capabilities for efficient and performing derivatives analytics.
- Reproduce major stylized facts of equity and options markets yourself
- Apply Fourier transform techniques and advanced Monte Carlo pricing
- Calibrate advanced option pricing models to market data
- Integrate advanced models and numeric methods to dynamically hedge options
Recent developments in the Python ecosystem enable analysts to implement analytics tasks as performing as with C or C++, but using only about one-tenth of the code or even less. Derivatives Analytics with Python — Data Analysis, Models, Simulation, Calibration and Hedging shows you what you need to know to supercharge your derivatives and risk analytics efforts.
Yves Hilpisch
Dr. Yves J. Hilpisch is the founder and CEO of The Python Quants (http://home.tpq.io), a group focusing on the use of open source technologies for financial data science, artificial intelligence, algorithmic trading, and computational finance. He is also the founder and CEO of The AI Machine (http://aimachine.io), a company focused on AI-powered algorithmic trading based on a proprietary strategy execution platform. Yves has a Diploma in Business Administration, a Ph.D. in Mathematical Finance, and is Adjunct Professor for Computational Finance. Yves is the author of five books (https://home.tpq.io/books): Artificial Intelligence in Finance (O’Reilly, forthcoming)Python for Algorithmic Trading (O’Reilly, forthcoming)Python for Finance (2018, 2nd ed., O’Reilly)Listed Volatility and Variance Derivatives (2017, Wiley Finance)Derivatives Analytics with Python (2015, Wiley Finance) Yves is the director of the first online training program leading to University Certificates in Python for Algorithmic Trading (https://home.tpq.io/certificates/pyalgo) and Computational Finance (https://home.tpq.io/certificates/compfin). He also lectures on computational finance, machine learning, and algorithmic trading at the CQF Program (http://cqf.com). Yves is the originator of the financial analytics library DX Analytics (http://dx-analytics.com) and organizes Meetup group events, conferences, and bootcamps about Python, artificial intelligence, and algorithmic trading in London (http://pqf.tpq.io), New York (http://aifat.tpq.io), Frankfurt, Berlin, and Paris. He has given keynote speeches at technology conferences in the United States, Europe, and Asia.
Other titles in Derivatives Analytics with Python Series (30)
Levy Processes in Credit Risk Rating: 0 out of 5 stars0 ratingsMarket Microstructure: Confronting Many Viewpoints Rating: 0 out of 5 stars0 ratingsIntroduction to Private Equity Rating: 0 out of 5 stars0 ratingsFourier Transform Methods in Finance Rating: 0 out of 5 stars0 ratingsExotic Options and Hybrids: A Guide to Structuring, Pricing and Trading Rating: 4 out of 5 stars4/5Electricity Markets: Pricing, Structures and Economics Rating: 3 out of 5 stars3/5The Art of Credit Derivatives: Demystifying the Black Swan Rating: 4 out of 5 stars4/5Swaps and Other Derivatives Rating: 0 out of 5 stars0 ratingsGlobal Private Banking and Wealth Management: The New Realities Rating: 0 out of 5 stars0 ratingsUnderstanding Islamic Finance Rating: 5 out of 5 stars5/5An Introduction to International Capital Markets: Products, Strategies, Participants Rating: 0 out of 5 stars0 ratingsCounterparty Credit Risk, Collateral and Funding: With Pricing Cases For All Asset Classes Rating: 0 out of 5 stars0 ratingsThe Handbook of Energy Trading Rating: 0 out of 5 stars0 ratingsCredit Derivatives: Trading, Investing, and Risk Management Rating: 0 out of 5 stars0 ratingsThe Mathematics of Derivatives Securities with Applications in MATLAB Rating: 0 out of 5 stars0 ratingsHandbook of Corporate Equity Derivatives and Equity Capital Markets Rating: 0 out of 5 stars0 ratingsThe Handbook of Insurance-Linked Securities Rating: 3 out of 5 stars3/5The Handbook of Convertible Bonds: Pricing, Strategies and Risk Management Rating: 0 out of 5 stars0 ratingsEssential Mathematics for Market Risk Management Rating: 5 out of 5 stars5/5A Workout in Computational Finance Rating: 0 out of 5 stars0 ratingsThe Trade Lifecycle: Behind the Scenes of the Trading Process Rating: 3 out of 5 stars3/5Financial Modelling in Practice: A Concise Guide for Intermediate and Advanced Level Rating: 4 out of 5 stars4/5Financial Engineering and Arbitrage in the Financial Markets Rating: 0 out of 5 stars0 ratingsModelling Single-name and Multi-name Credit Derivatives Rating: 0 out of 5 stars0 ratingsPractical Risk-Adjusted Performance Measurement Rating: 0 out of 5 stars0 ratingsUnderstanding Oil Prices: A Guide to What Drives the Price of Oil in Today's Markets Rating: 5 out of 5 stars5/5Paul Wilmott Introduces Quantitative Finance Rating: 5 out of 5 stars5/5Exotic Options Trading Rating: 5 out of 5 stars5/5Practical Portfolio Performance Measurement and Attribution Rating: 3 out of 5 stars3/5
Read more from Yves Hilpisch
Related to Derivatives Analytics with Python
Titles in the series (100)
Levy Processes in Credit Risk Rating: 0 out of 5 stars0 ratingsMarket Microstructure: Confronting Many Viewpoints Rating: 0 out of 5 stars0 ratingsIntroduction to Private Equity Rating: 0 out of 5 stars0 ratingsFourier Transform Methods in Finance Rating: 0 out of 5 stars0 ratingsExotic Options and Hybrids: A Guide to Structuring, Pricing and Trading Rating: 4 out of 5 stars4/5Electricity Markets: Pricing, Structures and Economics Rating: 3 out of 5 stars3/5The Art of Credit Derivatives: Demystifying the Black Swan Rating: 4 out of 5 stars4/5Swaps and Other Derivatives Rating: 0 out of 5 stars0 ratingsGlobal Private Banking and Wealth Management: The New Realities Rating: 0 out of 5 stars0 ratingsUnderstanding Islamic Finance Rating: 5 out of 5 stars5/5An Introduction to International Capital Markets: Products, Strategies, Participants Rating: 0 out of 5 stars0 ratingsCounterparty Credit Risk, Collateral and Funding: With Pricing Cases For All Asset Classes Rating: 0 out of 5 stars0 ratingsThe Handbook of Energy Trading Rating: 0 out of 5 stars0 ratingsCredit Derivatives: Trading, Investing, and Risk Management Rating: 0 out of 5 stars0 ratingsThe Mathematics of Derivatives Securities with Applications in MATLAB Rating: 0 out of 5 stars0 ratingsHandbook of Corporate Equity Derivatives and Equity Capital Markets Rating: 0 out of 5 stars0 ratingsThe Handbook of Insurance-Linked Securities Rating: 3 out of 5 stars3/5The Handbook of Convertible Bonds: Pricing, Strategies and Risk Management Rating: 0 out of 5 stars0 ratingsEssential Mathematics for Market Risk Management Rating: 5 out of 5 stars5/5A Workout in Computational Finance Rating: 0 out of 5 stars0 ratingsThe Trade Lifecycle: Behind the Scenes of the Trading Process Rating: 3 out of 5 stars3/5Financial Modelling in Practice: A Concise Guide for Intermediate and Advanced Level Rating: 4 out of 5 stars4/5Financial Engineering and Arbitrage in the Financial Markets Rating: 0 out of 5 stars0 ratingsModelling Single-name and Multi-name Credit Derivatives Rating: 0 out of 5 stars0 ratingsPractical Risk-Adjusted Performance Measurement Rating: 0 out of 5 stars0 ratingsUnderstanding Oil Prices: A Guide to What Drives the Price of Oil in Today's Markets Rating: 5 out of 5 stars5/5Paul Wilmott Introduces Quantitative Finance Rating: 5 out of 5 stars5/5Exotic Options Trading Rating: 5 out of 5 stars5/5Practical Portfolio Performance Measurement and Attribution Rating: 3 out of 5 stars3/5
Related ebooks
Professional Automated Trading: Theory and Practice Rating: 4 out of 5 stars4/5Hands-On AI Trading with Python, QuantConnect, and AWS Rating: 3 out of 5 stars3/5Big Data and Machine Learning in Quantitative Investment Rating: 0 out of 5 stars0 ratingsFourier Transform Methods in Finance Rating: 0 out of 5 stars0 ratingsThe Volatility Smile Rating: 0 out of 5 stars0 ratingsMachine Trading: Deploying Computer Algorithms to Conquer the Markets Rating: 4 out of 5 stars4/5The Quant Trader's Handbook: A Complete Guide to Algorithmic Trading Strategies and Techniques Rating: 5 out of 5 stars5/5Learning Quantitative Finance with R Rating: 4 out of 5 stars4/5Systemic Liquidity Risk and Bipolar Markets: Wealth Management in Today's Macro Risk On / Risk Off Financial Environment Rating: 0 out of 5 stars0 ratingsIntroduction to R for Quantitative Finance Rating: 4 out of 5 stars4/5Time Series with Python: How to Implement Time Series Analysis and Forecasting Using Python Rating: 3 out of 5 stars3/5Frequently Asked Questions in Quantitative Finance Rating: 3 out of 5 stars3/5Inside the Black Box: The Simple Truth About Quantitative Trading Rating: 4 out of 5 stars4/5Building Algorithmic Trading Systems: A Step-by-Step Guide Rating: 5 out of 5 stars5/5Quantitative Finance: Mastering Mathematical Models for Market Success Rating: 0 out of 5 stars0 ratingsNumerical Methods in Finance and Economics: A MATLAB-Based Introduction Rating: 0 out of 5 stars0 ratingsDerivatives Models on Models Rating: 3 out of 5 stars3/5Volatility: Practical Options Theory Rating: 0 out of 5 stars0 ratingsC# for Financial Markets Rating: 5 out of 5 stars5/5Financial Modeling Mastery: Building Robust Models for Market Success Rating: 5 out of 5 stars5/5Python for Finance Rating: 3 out of 5 stars3/5NumPy: Beginner's Guide - Third Edition Rating: 4 out of 5 stars4/5Algorithmic Trading: Winning Strategies and Their Rationale Rating: 3 out of 5 stars3/5Financial Markets and Trading: An Introduction to Market Microstructure and Trading Strategies Rating: 4 out of 5 stars4/5Mastering pandas for Finance Rating: 0 out of 5 stars0 ratingsExtreme Events: Robust Portfolio Construction in the Presence of Fat Tails Rating: 0 out of 5 stars0 ratingsAlpha Machines: Inside the AI-Driven Future of Finance Rating: 0 out of 5 stars0 ratingsStatistical Arbitrage: Exploiting Market Inefficiencies for Profit Rating: 0 out of 5 stars0 ratings
Investments & Securities For You
Principles: Life and Work Rating: 4 out of 5 stars4/5Investing For Beginners: Introduction to Investing, #1 Rating: 4 out of 5 stars4/5The Little Book of Common Sense Investing: The Only Way to Guarantee Your Fair Share of Stock Market Returns Rating: 4 out of 5 stars4/5Stock Investing For Dummies Rating: 5 out of 5 stars5/5Girls That Invest: Your Guide to Financial Independence through Shares and Stocks Rating: 5 out of 5 stars5/5Options Trading Crash Course: The #1 Beginner's Guide to Make Money with Trading Options in 7 Days or Less! Rating: 4 out of 5 stars4/5How to Invest: Masters on the Craft Rating: 4 out of 5 stars4/5Cryptocurrency Investing For Dummies Rating: 5 out of 5 stars5/5Buy Then Build: How Acquisition Entrepreneurs Outsmart the Startup Game Rating: 4 out of 5 stars4/5Just Keep Buying: Proven ways to save money and build your wealth Rating: 5 out of 5 stars5/5Technical Analysis For Dummies Rating: 5 out of 5 stars5/5Best Loser Wins: Why Normal Thinking Never Wins the Trading Game – written by a high-stake day trader Rating: 5 out of 5 stars5/5Day Trading For Dummies Rating: 4 out of 5 stars4/5Financial Statement Basics: From Confusion to Comfort in Under 100 Pages Rating: 4 out of 5 stars4/5Common Sense on Mutual Funds, Updated 10th Anniversary Edition Rating: 4 out of 5 stars4/5Stock Market Investing for Beginners & Dummies Rating: 5 out of 5 stars5/5Technical Analysis A Newbies' Guide: Trading Stocks with Simple Strategies Using Technical Analysis Rating: 4 out of 5 stars4/5Market Wizards: Interviews with Top Traders Rating: 4 out of 5 stars4/5Fundamental Analysis For Dummies Rating: 5 out of 5 stars5/5Cryptocurrency: Beginners Bible - How You Can Make Money Trading and Investing in Cryptocurrency Rating: 4 out of 5 stars4/5The Money Game Rating: 4 out of 5 stars4/5
Reviews for Derivatives Analytics with Python
2 ratings0 reviews
Book preview
Derivatives Analytics with Python - Yves Hilpisch
Preface
This book is an outgrowth of diverse activities of myself and colleagues of mine in the fields of financial engineering, computational finance and Python programming at our company The Python Quants GmbH on the one hand and of teaching mathematical finance at Saarland University on the other hand.
The book is targeted at practitioners, researchers and students interested in the market-based valuation of options from a practical perspective, i.e. the single numerical and technical implementation steps that make up such an effort. It is also for those who want to learn how Python can be used for derivatives analytics and financial engineering. However, apart from being primarily practical and implementation-oriented, the book also provides the necessary theoretical foundations and numerical tools.
My hope is that the book will contribute to the increasing acceptance of Python in the financial community, and in particular in the analytics space. If you are interested in getting the Python scripts and IPython Notebooks accompanying the book, you should visit http://wiley.quant-platform.com where you can register for the Quant Platform which allows browser-based, interactive and collaborative financial analytics. Further resources are found on the website http://derivatives-analytics-with-python.com. You should also check out the open source library DX Analytics under http://dx-analytics.com which implements the concepts and methods presented in the book in standardized, reusable fashion.
I thank my family—and in particular my wife Sandra—for their support and understanding that such a project requires many hours of solitude. I also want to thank my colleague Michael Schwed for his continuous help and support. In addition, I thank Alain Ledon and Riaz Ahmad for their comments and feedback. Discussions with participants of seminars and my lectures at Saarland University also helped the project significantly. Parts of this book have benefited from talks I have given at diverse Python and finance conferences over the years.
I dedicate this book to my lovely son Henry Nikolaus whose direct approach to living and clear view of the world I admire.
YVES HILPISCH
Saarland, February 2015
CHAPTER 1
A Quick Tour
1.1 Market-Based Valuation
This book is about the market-based valuation of (stock) index options. In the domain of derivatives analytics this is an important task which every major investment bank and buy-side decision maker in the financial market is concerned with on a daily basis. While theoretical valuation approaches develop a model, parametrize it and then derive values for options, the market-based approach works the other way round. Prices from liquidly traded options are taken as given (i.e. they are inputs instead of outputs) and one tries to parametrize a market model in a way that replicates the observed option prices as well as possible. This activity is generally referred to as model calibration. Being equipped with a calibrated model, one then proceeds with the task at hand, be it valuation, trading, investing, hedging or risk management. A bit more specifically, one might be interested in pricing and hedging an exotic derivative instrument with such a model—hoping that the results are in line with the overall market (i.e. arbitrage-free and even fair
) due to the previous calibration to more simple, vanilla instruments.
To accomplish a market-based valuation, four areas have to be covered:
market: knowledge about market realities is a conditio sine qua non for any sincere attempt to develop market-consistent models and to accomplish market-based valuation
theory: every valuation must be grounded on a sound market model, ensuring, for example, the absence of arbitrage opportunities and providing means to derive option values from observed quantities
numerics: one cannot hope to work with analytical results only; numerical techniques, like Monte Carlo simulation, are generally required in different steps of a market-based valuation process
technology: to implement numerical techniques efficiently, one is dependent on appropriate technology (hard- and software)
This book covers all of these areas in an integrated manner. It uses equity index options as the prime example for derivative instruments throughout. This, among others, allows to abstract from dividend related issues.
1.2 Structure of the Book
The book is divided into three parts. The first part is concerned with market-based valuation as a process and empirical findings about market realities. The second part covers a number of topics for the theoretical valuation of options and derivatives. It also develops tools much needed during a market-based valuation. The third part finally covers the major aspects related to a market-based valuation and also hedging strategies in such a context.
Part I The Market
comprises two chapters:
Chapter 2: this chapter contains a discussion of topics related to market-based valuation, like risks affecting the value of equity index options
Chapter 3: this chapter documents empirical and anecdotal facts about stocks, stock indices and in particular volatility (e.g. stochasticity, clustering, smiles) as well as about interest rates
Part II Theoretical Valuation
comprises four chapters:
Chapter 4: this chapter covers arbitrage pricing theory and risk-neutral valuation in discrete time (in some detail) and continuous time (on a higher level) according to the Harrison-Kreps-Pliska paradigm (cf. Harrison and Kreps (1979) and Harrison and Pliska (1981))
Chapter 5: the topic of this chapter is the complete market models of Black-Scholes-Merton (BSM, cf. Black and Scholes (1973), Merton (1973)) and Cox-Ross-Rubinstein (CRR, cf. Cox et al. (1979)) that are generally considered benchmarks for option valuation
Chapter 6: Fourier-based approaches allow us to derive semi-analytical valuation formulas for European options in market models more complex and realistic than the BSM/CRR models; this chapter introduces the two popular methods of Carr-Madan (cf. Carr and Madan (1999)) and Lewis (cf. Lewis (2001))
Chapter 7: the valuation of American options is more involved than with European options; this chapter analyzes the respective problem and introduces algorithms for American option valution via binomial trees and Monte Carlo simulation; at the center stands the Least-Squares Monte Carlo algorithm of Longstaff-Schwartz (cf. Longstaff and Schwartz (2001))
Finally, Part III Market-Based Valuation
has seven chapters:
Chapter 8: before going into details, this chapter illustrates the whole process of a market-based valuation effort in the simple, but nevertheless still useful, setting of Merton’s jump-diffusion model (cf. Merton (1976))
Chapter 9: this chapter introduces the general market model used henceforth, which is from Bakshi-Cao-Chen (cf. Bakshi et al. (1997)) and which accounts for stochastic volatility, jumps and stochastic short rates
Chapter 10: Monte Carlo simulation is generally the method of choice for the valuation of exotic/complex index options and derivatives; this chapter therefore discusses in some detail the discretization and simulation of the stochastic volatility model by Heston (cf. Heston (1993)) with constant as well as stochastic short rates according to Cox-Ingersoll-Ross (cf. Cox et al. (1985))
Chapter 11: model calibration stays at the center of market-based valuation; the chapter considers several general aspects associated with this topic and then proceeds with the numerical calibration of the general market model to real market data
Chapter 12: this chapter combines the results from the previous two to value European and American index options via Monte Carlo simulation in the calibrated general market model
Chapter 13: this chapter analyzes dynamic delta hedging strategies for American options by Monte Carlo simulation in different settings, from a simple one to the calibrated market model
Chapter 14: this brief chapter provides a concise summary of central aspects related to the market-based valuation of index options
In addition, the book has an Appendix with one chapter:
Appendix A: the appendix introduces some of the most important Python concepts and libraries in a nutshell; the selection of topics is clearly influenced by the requirements of the rest of the book; those not familiar with Python or looking for details should consult the more comprehensive treatment of all relevant topics by the same author (cf. Hilpisch (2014))
1.3 Why Python?
Although Python has established itself in the financial industry as a powerful programming language with an elaborate ecosystem of tools and libraries, it is still not often used for financial, derivatives or risk analytics purposes. Languages like C++, C, C#, VBA or Java and toolboxes like Matlab or domain-specific languages like R often dominate this area. However, we see a number of good reasons to choose Python even for computationally demanding analytics tasks; the following are the most important ones we want to mention, in no particular order, (see also chapter 1 in Hilpisch (2014)):
open source: Python and the majority of available libraries are completely open source; this allows an entry to this technology at no cost, something particularly important for students, academics or other individuals
syntax: Python programming is easy to learn, the code is quite compact and in general highly readable; at universities it is increasingly used as an introduction to programming in general; when it comes to numerical or financial algorithm implementation, the syntax is pretty close to the mathematics in general (e.g. due to code vectorization approaches)
multi-paradigm: Python is as good for procedural programming (which suffices for the purposes of this book) as well as at object-oriented programming (which is necessary in more complex/professional contexts); it also has some functional programming features to offer
interpreted: Python is an interpreted language which makes rapid prototyping and development in general a bit more convenient, especially for beginners; tools like IPython Notebook and libraries like pandas for time series analysis allow for efficient and productive interactive analytics workflows
libraries: nowadays, there is a wealth of powerful libraries available and the supply grows steadily; there is hardly a problem that cannot be easily tackled with an existing library, be it a numerical problem, a graphical one or a data-related problem
speed: a common prejudice with regard to interpreted languages—compared to compiled ones like C++ or C—is the slow speed of code execution; however, financial applications are more or less all about matrix and array manipulations and operations which can be done at the speed of C code with the essential Python library NumPy for array-based computing; other performance libraries, like Numba for dynamic code compiling, can also be used to improve performance
market: in the London area (mainly financial services) the number of Python developer contract offerings was 485 in the third quarter of 2012; the comparable figure in the same period 2013 was already 864;1 large financial institutions like Bank of America, Merrill Lynch and J.P. Morgan have millions of lines of Python code in production, mainly in risk management; Python is also really popular in the hedge fund industry
All in all, Python seems to be a good choice for our purposes. The cover story Python Takes a Bite
in the March 2010 issue of Wilmott magazine (cf. Lee (2010)) also illustrates that Python is gaining ground in the financial world. A modern introduction into Python for finance is given by Hilpisch (2014).
One of the easiest ways to get started with Python is to register on the Quant Platform which allows for browser-based, interactive and collaborative financial analytics and development (cf. http://quant-platform.com). This platform offers all you need to do efficient and productive financial analytics as well as financial application building with Python. It also provides, for instance, integration with R, the free software environment for statistical computing and graphics.
1.4 Further Reading
The book covers a great variety of aspects which comes at the cost of depth of exposition and analysis in some places. Our aim is to emphasize the red line and to guide the reader easily through the different topics. However, this inevitably leads to uncovered aspects, omitted proofs and unanswered questions. Fortunately, a number of good sources in book form are available which may be consulted on the different topics:
market: cf. Bittmann (2009) to learn about options fundamentals, the main microstructure elements of their markets and the specific lingo; Gatheral (2006) is a concise reference about option and volatility modeling in practice; Rebonato (2004) is a book that comprehensively covers option markets, their empirical specialities and the models used in theory and practice
theory: Pliska (1997) is a comprehensive source for discrete market models; the book by Delbaen and Schachermayer (2004) covers the general arbitrage theory in continuous time and is quite advanced; less advanced, but still comprehensive, treatments of arbitrage pricing are Björk (2004) for continuous processes based on Brownian motion and Cont and Tankov (2004a) for continuous processes with jumps; Wilmott et al. (1995) offers a detailed discussion of the seminal Black-Scholes-Merton model
numerics: Cherubini et al. (2009) is a book-length treatment of the Fourier-based option pricing approach; Glasserman (2004) is the standard textbook on Monte Carlo simulation in financial applications; Brandimarte (2006) covers a wide range of numerical techniques regularly applied in mathematical finance and offers implementation examples in Matlab2
implementation: probably the best introduction to Python for the purposes of this book is another book by same author (cf. Hilpisch (2014)) which is called Python for Finance; that book covers the main tools and libraries needed for this book, like IPython, NumPy, matplotlib, PyTables and pandas, in a detailed fashion and with a wealth of concrete financial examples; the excellent book by McKinney (2012) about data analysis with Python should also be consulted; good general introductions to Python from a scientific perspective are Haenel et al. (2013) and Langtangen (2009); Fletcher and Gardener (2009) provides an introduction to the language also from a financial perspective, but mainly from the angle of modeling, capturing and processing financial trades; London (2005) is a larger book that covers a great variety of financial models and topics and shows how to implement them in C++; in addition, there is a wealth of Python documentation available for free on the Internet.
This concludes the Quick Tour.
Notes
1. Source: www.itjobswatch.co.uk/contracts/london/python.do on 07. October 2014.
2. Python in combination with NumPy comes quite close to the syntax of Matlab such that translations are generally straightforward.
PART One
The Market
CHAPTER 2
What is Market-Based Valuation?
2.1 Options and their Value
An equity option represents the right to buy (call) or sell (put) a unit of the underlying stock at a prespecified price (strike) at a predetermined date (European option) or over a determined period of time (American option). Some options are settled in actual stocks; most options, like those on an index, are settled in cash. People or institutions selling options are called option writers. Those buying options are called option holders.
For a European call option on an index with strike 8,000 and index level of 8,200 at maturity, the option holder receives the difference 8, 200 − 8, 000 = 200 (e.g. in EUR or USD) from the option writer. If the index level is below the strike, say at 7,800, the option expires worthless and the writer does not have to pay anything. We can formalize this via the so-called inner value (or intrinsic value or payoff)—from the holder’s viewpoint—of the option
numbered Display Equationwhere T is the maturity date of the option, ST the index level at this date and K represents the strike price. We can now use Python for the first time and plot this inner value function.
A script could look like:
#
# European Call Option Inner Value Plot
# 02_MBV/inner_value_plot.py
#
# (c) Dr. Yves J. Hilpisch
# Derivatives Analytics with Python
#
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.family'] = 'serif'
# Option Strike
K = 8000
# Graphical Output
S = np.linspace(7000, 9000, 100) # index level values
h = np.maximum(S - K, 0) # inner values of call option
plt.figure()
plt.plot(S, h, lw=2.5) # plot inner values at maturity
plt.xlabel('index level $S_t$ at maturity')
plt.ylabel('inner value of European call option')
plt.grid(True)
The output of this script is shown in Figure 2.1.
Figure 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
Three scenarios have to be distinguished with regard to the so-called moneyness of an option:
in-the-money (ITM): a call (put) is in-the-money if S > K (S < K)
at-the-money (ATM): an option, call or put, is at-the-money if S ≈ K
out-of-the-money (OTM): a call (put) is out-of-the-money if S < K (S > K)
However, what influences the present value of such a call option today? Here are some factors:
initial index level: of course, it is important what the current index level is since this influences how probable it is that the index level exceeds the strike at maturity; if the index level is 7,900 it should be much more probable that the call option expires with positive value than if the level was at 7,500
volatility of the index: put simply, (annualized) volatility is a measure for the randomness of the index’s returns over a year; suppose the extreme case that the index is at 7,900 and there is no risk/no movement at all—then the index would not surpass the strike at maturity; however, if the index is at 7,900 and fluctuating strongly then there is a chance that the option will expire with positive value—and the bigger the fluctuations (the higher the volatility) the better from the option holder’s viewpoint
time-to-maturity: again suppose the index is at 7,900; if time-to-maturity is only one day then the probability of the option being valuable at maturity is much lower than if time-to-maturity was 1 month or even 1 year
interest rate: cash flows from a European option occur at maturity only which represents a future date; these cash flows have to be discounted to today to derive a present value
These heuristic insights are formalized in the seminal work of Black-Scholes-Merton (cf. Black and Scholes (1973) and Merton (1973)) who for the first time derived a closed option pricing formula for a parsimonious set of input parameters. Their formula says mainly the following
numbered Display EquationIn words, the fair present value of a European call option C*0 is given by their formula CBSM( · ) which takes as input parameters:
S0 the current index level
K the strike price of the option
T the maturity date (equals time-to-maturity viewed from the present date)
r the constant risk-less short rate
σ the volatility of the index, i.e. the standard deviation of the index level returns
The Black-Scholes-Merton formula can also be plotted and the result is shown in Figure 2.2.1 The present value of the option is always above the (undiscounted) inner value. The difference between the two is generally referred to as the time value of the option. In this sense, the option’s present value is composed of the inner value plus the time value. Time value is suggestive of the fact that the option still has time to get in-the-money or to get even more in-the-money.
Figure 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
Here is the Python script that generates Figure 2.2.
#
# European Call Option Value Plot
# 02_mbv/BSM_value_plot.py
#
# (c) Dr. Yves J. Hilpisch
# Derivatives Analytics with Python
#
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.family'] = 'serif'
# Import Valuation Function from Chapter 5
import sys
sys.path.append('05_com')
from BSM_option_valuation import BSM_call_value
# Model and Option Parameters
K = 8000 # strike price
T = 1.0 # time-to-maturity
r = 0.025 # constant, risk-less short rate
vol = 0.2 # constant volatility
# Sample Data Generation
S = np.linspace(4000, 12000, 150) # vector of index level values
h = np.maximum(S - K, 0) # inner value of option
C = [BSM_call_value(S0, K, 0, T, r, vol) for S0 in S]
# calculate call option values
# Graphical Output
plt.figure()
plt.plot(S, h, 'b-.', lw=2.5, label='inner value')
# plot inner value at maturity
plt.plot(S, C, 'r', lw=2.5, label='present value')
# plot option present value
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('index level $S_0$')
plt.ylabel('present value $C(t=0)$')
2.2 Vanilla vs. Exotic Instruments
Financial markets distinguish between plain vanilla or flow equity derivatives, like European call options written on an equity index, and exotic equity derivatives, like options on an equity index with Asian features, barriers and/or American exercise.2 In general, there exist liquid markets for plain vanilla products but not for exotic ones. In contrast, exotic derivatives are often tailored by financial institutions to specific client needs and are not traded at all (or only once
if you like).3
Nevertheless, financial institutions writing exotic equity options (so-called sell side) or clients buying these options (i.e. the buy side) must have a mechanism to derive fair values regularly and transparently. In addition, option writers must be able to hedge their exposure. In relation to exotic equity derivatives, sellers and buyers must often resort to numerical methods, like Monte Carlo simulation, to come up with fair values and appropriate hedging strategies.
Here we face for the first time what is meant by market in market-based valuation. The market is represented by liquidly traded vanilla instruments (for example, European or American call options) on the underlying in question. If I want to value a non-traded equity derivative in a market-based manner then I should include in this process the information available from the relevant vanilla options market. This requirement is based on a belief in efficient markets and the claim that the market is always right.
More formally, whatever model I use for the valuation and hedging of exotic equity derivatives, a minimum requirement is that the model reproduce the values of liquidly traded instruments sufficiently well. Two areas have to be considered carefully:
qualitative features: given the underlying of the derivative to be valued and the options on this underlying liquidly traded, what qualitative features should the model exhibit? for example, it would make sense to assume that an equity index will (positively) trend in the long term; however, this assumption is not appropriate if the underlying is an interest rate or volatility measure which tend to fluctuate around long-term equilibrium values
quantitative features: given the basic qualitative features of the model, there are in general infinitely many possibilities to parametrize it; while in physics there are often universal constants to rely on, this is hardly ever the case in finance; on the positive side, this allows parameters to be set in a way that best fits model prices to market-observed prices from vanilla instruments (a task called calibration and central in what follows)
In Chapter 3, we discuss a number of issues related to the question of what qualitative features an appropriate model should exhibit. Part II of the book then explains how to build such models theoretically. Part III of the book is mainly concerned with simulation, model calibration (i.e. parameter specification), valuation and hedging.
2.3 Risks Affecting Equity Derivatives
This section focuses on market risks affecting the price of derivative instruments as well as other risks that play a role in this context.
2.3.1 Market Risks
To come up with fair values for equity derivatives and sound hedging strategies, one has to consider first which market risks influence their values. Among the market risks that influence equity derivatives are:
price risk: this relates to uncertain changes in the underlying’s price, like index or stock price movements
volatility risk: volatility refers to the standard deviation of the underlying’s returns; however, volatility itself fluctuates over time, i.e. volatility is not constant but rather stochastic
jump or crash risk: the stock market crashes of 1987, 1998, 2001 and 2008 as well as implied volatilities of stock index options (see the next chapter) indicate that there is a significantly positive probability for large market drops; such discontinuities may break down, for example, otherwise sound dynamic hedging strategies
interest rate risk: although equity derivatives generally do not rely on interest rates or bonds directly4 their value is indirectly influenced by interest rates via risk-neutral discounting with the short rate
correlation risk: simply spoken, correlation measures the co-movement of two or more assets/quantities; correlation may change over time and become close to 1, i.e. perfect, among asset classes during times of stress
liquidity risk: dynamic and static hedging strategies depend on market liquidity; for example, if certain options are not liquidly traded a desired hedge may not be executable
default risk: in case of the default of a company represented in the underlying assets, stocks and/or bonds of this company depreciate in value (often to zero)
In what follows, the discussion addresses all market risks mentioned above, apart from default and liquidity risk. Default risk does not play a significant role since the discussion mainly focuses on benchmark indices where the possibility of default of a single company is generally negligible.5
Liquidity risk is more oriented towards the implementation of hedging programs and in that sense only
an important operational aspect depending on the specific market environment an option seller or buyer operates in. In addition, the focus of this book is mainly on stock index derivatives where liquidity risk seldom is a problem—index futures, for example, are among the most liquid instruments. Although an active area of research,6 a broadly accepted theoretical approach to incorporate liquidity in financial models is still missing. Cetin et al. (2004) point out:
From a financial engineering perspective, the need is paramount for a simple yet robust method that incorporates liquidity risk into arbitrage pricing theory.
They propose what they call the liquidity risk arbitrage pricing theory
with a stochastic supply curve for a security’s price as a function of trade size.7 As long as there is no solution to this, one has to keep in mind what The New York Times summarizes as follows:
"That failure [of risk models] suggests new frontiers for financial engineering and risk management, including trying to model the mechanics of panic and the patterns of human behavior.
‘What wasn’t recognized was the importance of a different species of risk—liquidity risk,’ said Stephen Figlewski, a professor of finance at the Leonard N. Stern School of Business at New York University.…"8
2.3.2 Other Risks
In addition to market risks, there are other sources of risk like, for instance, models and operations. Model risk refers to the risk that valuation and risk management finally rely on the specific model used. Even if your model addresses, say, volatility risk you may nevertheless address it in a harmful way—i.e. via the wrong model generating inappropriate hedging strategies. Operational risk refers to all aspects of implementing valuation and risk management processes as well as risks related to IT systems used. For example, knowledge of the right hedging program is surely of great importance—but the timely and correct execution of the program is at least equally important.
2.4 Hedging
Hedging describes the activity of minimizing or even eliminating risks resulting from option positions. Getting back to our previous example, an option writer who faces the risk of paying out 200 EUR to an option holder might want to set up a hedge program that pays her the exact amount in the exact case—leaving her with net debt of zero. The program should also pay 300 EUR or 100 EUR or whatever might be the amount due to writing the index option. In such a way, the writer would completely eliminate the risks attached to the short position in the option. In general, option writers do exactly this since as market participants they are not speculators but rather want to earn a steady income from their activities.
A hedge program can be either dynamic or static or a combination of both. Assume the equity index option of the example has time-to-maturity of 1 year. In order to hedge the option dynamically—in general with positions in the underlying—the writer sets up a hedge portfolio at the date of writing the option and then adjusts the portfolio frequently. A static hedge program—in general with positions in other options—would be set up at issuance and hold constant until maturity. More sophisticated hedge strategies generally combine both elements.
In general, there is neither a unique objective nor a unique set of principles for setting up hedge programs. For example, Gilbert et al. (2007) report three main objectives of variable annuities providers, i.e. life insurers, when implementing hedging programs:
accounting level
accounting volatility and
economic risks
This book focuses on economic risks only since accounting issues are highly dependent on the concrete reporting standards and may therefore vary from country to country. In that sense, the perspective of this book is cash flow driven and intentionally neglects accounting issues. The approach is that of arbitrage or risk-neutral pricing/hedging as comprehensively explained in Björk (2004) for models with continuous price processes and in Cont and Tankov (2004a) for models where price processes may jump.
Generally speaking, the main goal of a hedging program in economic or cash terms is to perfectly replicate the hedged derivative’s payoff and thus eliminate all risk. However, in practice this is seldom realized due to two main issues. The