S. Fletcher & C. Gardner
Book Details
Price
|
2.00 USD |
---|---|
Pages
| 246 p |
File Size
|
3,802 KB |
File Type
|
PDF format |
ISBN
| 978-0-470-98784-1 |
Copyright
| 2009 John Wiley & Sons Ltd |
Chapter-by-chapter this book gradually presents a practical body of working code referred to
as PPF or the ppf package, that implements a minimal but extensible Python-based financia
engineering system.
Chapter 2 looks at the overall topology of the ppf package, its dependencies and how to
build, install and test it (newcomers to Python may be served by looking ahead to Appendix
A where a quick tutorial on Python basics is offered).
Chapter 3 considers the topic of implementing Python extension modules in C++ with an
emphasis on fostering interoperability with existing C++ financia engineering systems and, in
particular, how certain functionality present in ppf in fact is underlied by C++ in this fashion.
Chapter 4 lays the groundwork for later chapters (concerned with pricing using techniques
from numerical analysis) in that it presents those mathematical algorithms and tools that arise
over and over again in computational quantitative analysis, including:
(1) (pseudo) random number generation;
(2) estimation of the standard normal cumulative distribution function;
(3) a variety of interpolation schemes;
(4) root-findin algorithms;
(5) various operations for linear algebra;
(6) generalised linear least-squares data fitting
(7) stable calculation techniques for computing quadratic and cubic roots; and
(8) calculation of the expectation of a function of a random variable.
Chapter 5 looks at how the ppf represents common market information such as discountfactor
functions and volatility surfaces.
Chapter 6 is entirely concerned with looking at the data structures used in the ppf for
representing financia structures: ‘fl ws’, ‘legs’, ‘exercise opportunities’, ‘trades’ and the like.
Chapter 7 details the concepts and classes that govern the interactions between the trade
representations and pricing models in the ppf package.
Chapter 8 offers an implementation of a fully functional Hull–White model in Python,
where the characteristic features of the model are assembled from (in as much as is possible)
functionally orthogonal components.
Chapter 9 present two general numerical pricing frameworks invariant over pricing models:
one lattice based, the other Monte-Carlo based.
Chapter 10 applies the pricing frameworks and the Hull–White model developed in the
preceding chapters to pricing financia structures, specificall , Bermudan swaptions and target
redemption notes.
Chapter 11, while keeping things tractable, introduces the idea of and practical techniques
for C++/Python ‘Hybrid Systems’ against the backdrop of existing derivative security pricing
and risk management systems in C++.
Chapter 12 gives concrete examples of implementing COM servers in Python and utilising
the functionality so exposed in the context of Microsoft Excel.
In the appendices section, Appendix A offers newcomers to Python a brief tutorial. Appendix
B provides a primer for the use of the C++ Boost.Python library for fostering interoperability
between C++ and Python. Appendix C covers the mathematics of the Hull–White model and
Appendix D the mathematics of a simple regression scheme for determining the early exercise
premium of a callable structure when pricing using Monte-Carlo techniques.
Table of Contents
1 Welcome to Python 1
1.1 Why Python? 1
1.1.1 Python is a general-purpose high-level programming language 1
1.1.2 Python integrates well with data analysis, visualisation and GUI toolkits 2
1.1.3 Python ‘plays well with others’ 2
1.2 Common misconceptions about Python 2
1.3 Roadmap for this book 3
2 The PPF Package 5
2.1 PPF topology 5
2.2 Unit testing 6
2.2.1 doctest 6
2.2.2 PyUnit 7
2.3 Building and installing PPF 7
2.3.1 Prerequisites and dependencies 7
2.3.2 Building the C++ extension modules 8
2.3.3 Installing the PPF package 9
2.3.4 Testing a PPF installation 9
3 Extending Python from C++ 11
3.1 Boost.Date Time types 11
3.1.1 Examples 12
3.2 Boost.MultiArray and special functions 17
3.3 NumPy arrays 19
3.3.1 Accessing array data in C++ 19
3.3.2 Examples 23
4 Basic Mathematical Tools 27
4.1 Random number generation 27
4.2 N (.) 28
4.3 Interpolation 29
4.3.1 Linear interpolation 31
4.3.2 Loglinear interpolation 32
4.3.3 Linear on zero interpolation 32
4.3.4 Cubic spline interpolation 33
4.4 Root findin 35
4.4.1 Bisection method 35
4.4.2 Newton–Raphson method 36
4.5 Linear algebra 38
4.5.1 Matrix multiplication 38
4.5.2 Matrix inversion 38
4.5.3 Matrix pseudo-inverse 39
4.5.4 Solving linear systems 39
4.5.5 Solving tridiagonal systems 39
4.5.6 Solving upper diagonal systems 40
4.5.7 Singular value decomposition 42
4.6 Generalised linear least squares 44
4.7 Quadratic and cubic roots 46
4.8 Integration 49
4.8.1 Piecewise constant polynomial fittin 49
4.8.2 Piecewise polynomial integration 51
4.8.3 Semi-analytic conditional expectations 57
5 Market: Curves and Surfaces 63
5.1 Curves 63
5.2 Surfaces 64
5.3 Environment 65
6 Data Model 69
6.1 Observables 69
6.1.1 LIBOR 70
6.1.2 Swap rate 74
6.2 Flows 79
6.3 Adjuvants 82
6.4 Legs 84
6.5 Exercises 85
6.6 Trades 87
6.7 Trade utilities 88
7 Timeline: Events and Controller 93
7.1 Events 93
7.2 Timeline 94
7.3 Controller 97
8 The Hull–White Model 99
8.1 A component-based design 99
8.1.1 Requestor 100
8.1.2 State 101
8.1.3 Filler 104
8.1.4 Rollback 108
8.1.5 Evolve 112
8.1.6 Exercise 115
8.2 The model and model factories 118
8.3 Concluding remarks 121
9 Pricing using Numerical Methods 123
9.1 A lattice pricing framework 123
9.2 A Monte-Carlo pricing framework 128
9.2.1 Pricing non-callable trades 129
9.2.2 Pricing callable trades 131
9.3 Concluding remarks 142
10 Pricing Financial Structures in Hull–White 145
10.1 Pricing a Bermudan 145
10.2 Pricing a TARN 152
10.3 Concluding remarks 157
11 Hybrid Python/C++ Pricing Systems 159
11.1 nth imm of year revisited 159
11.2 Exercising nth imm of year from C++ 161
12 Python Excel Integration 165
12.1 Black–scholes COM server 165
12.1.1 VBS client 167
12.1.2 VBA client 167
12.2 Numerical pricing with PPF in Excel 168
12.2.1 Common utilities 168
12.2.2 Market server 169
12.2.3 Trade server 176
12.2.4 Pricer server 187
Appendices 191
A Python 193
A.1 Python interpreter modes 193
A.1.1 Interactive mode 193
A.1.2 Batch mode 193
A.2 Basic Python 194
A.2.1 Simple expressions 194
A.2.2 Built-in data types 195
A.2.3 Control fl w statements 197
A.2.4 Functions 200
A.2.5 Classes 201
A.2.6 Modules and packages 203
A.3 Conclusion 205
B Boost.Python 207
B.1 Hello world 207
B.2 Classes, constructors and methods 207
B.3 Inheritance 209
B.4 Python operators 212
B.5 Functions 212
B.6 Enums 214
B.7 Embedding 214
B.8 Conclusion 216
C Hull–White Model Mathematics 217
D Pickup Value Regression 219
Bibliography 221
Index 223