Derivatives Analytics with Python - Yves Hilpisch - E-Book

Derivatives Analytics with Python E-Book

Yves Hilpisch

0,0
63,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Supercharge options analytics and hedging using the power of Python

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.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 421

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



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 officeJohn 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.

Library of Congress Cataloging-in-Publication DataHilpisch, Yves J. Derivatives analytics with Python : data analysis, models, simulation, calibration and hedging / Yves Hilpisch.—1 pages cm.—(The Wiley finance series) Includes bibliographical references and index. ISBN 978-1-119-03799-6 (hardback) 1. Derivative securities. 2. Hedging (Finance) 3. Python (Computer program language)I. Title. HG6024.A3H56 2015 332.64'5702855133—dc23 2015010191

A catalogue record for this book is available from the British Library.

ISBN 978-1-119-03799-6 (hardback) ISBN 978-1-119-03793-4 (ebk) ISBN 978-1-119-03800-9 (ebk) ISBN 978-1-119-03801-6 (obk)

Cover Design: Wiley Cover Images: Top image (c)iStock.com/agsandrew; Bottom image (c)iStock.com/stocksnapper

CONTENTS

Preface

Chapter 1: A Quick Tour

1.1 Market-Based Valuation

1.2 Structure of the Book

1.3 Why Python?

1.4 Further Reading

Notes

Part One: The Market

Chapter 2: What is Market-Based Valuation?

2.1 Options and their Value

2.2 Vanilla vs. Exotic Instruments

2.3 Risks Affecting Equity Derivatives

2.4 Hedging

2.5 Market-Based Valuation as a Process

Notes

Chapter 3: Market Stylized Facts

3.1 Introduction

3.2 Volatility, Correlation and Co.

3.3 Normal Returns as the Benchmark Case

3.4 Indices and Stocks

3.5 Option Markets

3.6 Short Rates

3.7 Conclusions

3.8 Python Scripts

Notes

Part Two: Theoretical Valuation

Chapter 4: Risk-Neutral Valuation

4.1 Introduction

4.2 Discrete-Time Uncertainty

4.3 Discrete Market Model

4.4 Central Results in Discrete Time

4.5 Continuous-Time Case

4.6 Conclusions

4.7 Proofs

Notes

Chapter 5: Complete Market Models

5.1 Introduction

5.2 Black-Scholes-Merton Model

5.3 Greeks in the BSM Model

5.4 Cox-Ross-Rubinstein Model

5.5 Conclusions

5.6 Proofs and Python Scripts

Notes

Chapter 6: Fourier-Based Option Pricing

6.1 Introduction

6.2 The Pricing Problem

6.3 Fourier Transforms

6.4 Fourier-Based Option Pricing

6.5 Numerical Evaluation

6.6 Applications

6.7 Conclusions

6.8 Python Scripts

Chapter 7: Valuation of American Options by Simulation

7.1 Introduction

7.2 Financial Model

7.3 American Option Valuation

7.4 Numerical Results

7.5 Conclusions

7.6 Python Scripts

Notes

Part Three: Market-Based Valuation

Chapter 8: A First Example of Market-Based Valuation

8.1 Introduction

8.2 Market Model

8.3 Valuation

8.4 Calibration

8.5 Simulation

8.6 Conclusions

8.7 Python Scripts

Notes

Chapter 9: General Model Framework

9.1 Introduction

9.2 The Framework

9.3 Features of the Framework

9.4 Zero-Coupon Bond Valuation

9.5 European Option Valuation

9.6 Conclusions

9.7 Proofs and Python Scripts

Note

Chapter 10: Monte Carlo Simulation

10.1 Introduction

10.2 Valuation of Zero-Coupon Bonds

10.3 Valuation of European Options

10.4 Valuation of American Options

10.5 Conclusions

10.6 Python Scripts

Notes

Chapter 11: Model Calibration

11.1 Introduction

11.2 General Considerations

11.3 Calibration of Short Rate Component

11.4 Calibration of Equity Component

11.5 Conclusions

11.6 Python Scripts for Cox-Ingersoll-Ross Model

Notes

Chapter 12: Simulation and Valuation in the General Model Framework

12.1 Introduction

12.2 Simulation of BCC97 Model

12.3 Valuation of Equity Options

12.4 Conclusions

12.5 Python Scripts

Notes

Chapter 13: Dynamic Hedging

13.1 Introduction

13.2 Hedging Study for BSM Model

13.3 Hedging Study for BCC97 Model

13.4 Conclusions

13.5 Python Scripts

Notes

Chapter 14: Executive Summary

Appendix A: Python in a Nutshell

A.1 Python Fundamentals

A.2 European Option Pricing

A.3 Selected Financial Topics

A.4 Advanced Python Topics

A.5 Rapid Financial Engineering

Notes

Bibliography

Index

EULA

List of Tables

Chapter 3

Table 3.1

Table 3.2

Chapter 5

Table 5.1

Chapter 7

Table 7.1

Table 7.2

Chapter 10

Table 10.1

Table 10.2

Table 10.3

Table 10.4

Table 10.5

Guide

Cover

Table of Contents

Preface

Pages

xvii

1

2

3

4

5

7

9

10

11

13

14

15

16

17

19

20

21

23

24

25

26

28

29

30

31

32

33

34

36

37

40

41

43

45

47

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

71

72

73

74

75

76

77

78

79

81

82

84

85

88

92

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

119

120

121

122

123

124

125

127

128

129

130

131

132

133

134

135

136

137

139

140

145

147

148

149

151

153

155

157

160

163

165

169

170

171

172

173

174

175

176

177

178

180

187

188

189

190

192

193

194

195

196

197

198

199

200

201

202

203

204

205

209

215

223

224

225

226

227

228

229

230

231

232

233

235

236

237

239

240

241

243

248

251

252

256

258

263

264

265

266

267

268

269

274

275

279

280

281

282

283

284

285

286

287

289

293

295

300

303

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

325

327

328

329

330

331

332

333

334

335

336

337

338

340

341

342

343

344

345

347

348

349

350

351

352

353

354

355

356

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 1A 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 Matlab

2

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 OneThe Market

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!