numerical methods in finance and...

30
Numerical Methods in Finance and Economics A MATLAB-Based Introduction Second Edition Paolo Brandimarte Politecnico di Torino Torino, Italy @XEliciENCE A JOHN WILEY & SONS, INC., PUBLICATION

Upload: dangbao

Post on 21-May-2018

240 views

Category:

Documents


2 download

TRANSCRIPT

Numerical Methods in Finance and Economics

A MATLAB-Based Introduction

Second Edition

Paolo Brandimarte Politecnico di Torino

Torino, Italy

@XEl ic iENCE A JOHN WILEY & SONS, INC., PUBLICATION

This Page Intentionally Left Blank

Numerical Methods in Finance and Economics

STATISTICS IN PRACTICE

Advisory Editor

Peter Bloomfield North Carolina State University, USA

Founding Editor

Vic Barnett Nottingham Trent University, UK

Statistics in Practice is an important international series of texts which provide detailed cov- erage of statistical concepts, methods and worked case studies in specific fields of investiga- tion and study.

With sound motivation and many worked practical examples, the books show in down-to- earth terms how to select and use an appropriate range of statistical techniques in a particular practical field within each title’s special topic area.

The books provide statistical support for professionals and research workers across a range of employment fields and research environments. Subject areas covered include medi- cine and pharmaceutics; industry, finance and commerce; public services; the earth and envi- ronmental sciences, and so on.

The books also provide support to students studying statistical courses applied to the above areas. The demand for graduates to be equipped for the work environment has led to such courses becoming increasingly prevalent at universities and colleges.

It is our aim to present judiciously chosen and well-written workbooks to meet everyday practical needs. Feedback of views from readers will be most valuable to monitor the success of this aim.

A complete list of titles in this series appears at the end of the volume.

Numerical Methods in Finance and Economics

A MATLAB-Based Introduction

Second Edition

Paolo Brandimarte Politecnico di Torino

Torino, Italy

@XEl ic iENCE A JOHN WILEY & SONS, INC., PUBLICATION

Copyright 0 2006 by John Wiley & Sons, Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey. Published simultaneously in Canada.

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, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 11 1 River Street, Hoboken, NJ 07030, (201) 748-601 1, fax (201) 748-6008, or online at http:l/www.wiley.com/go/permission.

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. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.

For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic format. For information about Wiley products, visit our web site at www.wiley.com.

Library of Congress Cataloging-in-Publication Data:

Brandimarte, Paolo.

Brandimarte.-2nd ed. Numerical methods in finance and economics : a MATLAB-based introduction / Paolo

p. cm. Rev. ed. of: Numerical methods in finance. 2002. Includes bibliographical references and index.

ISBN-10: 0-471-74503-0 (cloth) 1. Finance-Statistical methods. 2. Economics-Statistical methods. I. Brandimarte, Paolo.

HG176.5.B73 2006 332.0 1'5 1 d c 2 2 2006045787

ISBN-13: 978-0-47 1-74503-7 (Cloth)

Numerical methods in finance. 11. Title.

Printed in the United States of America.

10 9 8 7 6 5 4 3 2 1

This book is dedicated to Commander Straker, Lieutenant Ellis, and all S H A D 0 operatives. Thirty-five years ago they introduced m e t o the art of using both computers a n d gut feelings to make decisions.

This Page Intentionally Left Blank

Preface to the Second Edition

From the Preface to the First Edition

Part I Background

Contents

1 Motivation 1.1 Need for numerical methods 1.2 Need for numerical computing environments:

why MATLAB? 1.3 Need for theory

For further reading References

2 Financial Theory 2.1 Modeling uncertainty 2.2 Basic financial assets and related issues

2.2.1 Bonds 2.2.2 Stocks

xvii

xxiii

3 4

9 13 20 21

23 25 30 30 31

V i i

viii CONTENTS

2.2.3 Derivatives 2.2.4

Fixed-income securities: analysis and portfolio immunization 2.3.1

2.3.2 2.3.3

2.3.4

2.3.5 Critique

2.4.1 Utility theory 2.4.2 Mean-variance portfolio Optimization 2.4.3 M A T L A B functions to deal with mean-

variance portfolio optimization 2.4.4 Critical remarks 2.4.5 Alternative risk measures: Value at Risk

Modeling the dynamics of asset prices 2.5.1 2.5.2 Standard Wiener process 2.5.3 Stochastic integrals and stochastic

2.5.4 Ito’s lemma 2.5.5 Generalizations

2.6 Derivatives pricing 2.6.1 2.6.2 Black-Scholes model 2.6.3 Risk-neutral expectation and Feynman-

KaE formula 2.6.4 Black-Scholes model in M A T L A B 2.6.5 A f ew remarks o n Black-Scholes formula 2.6.6 Pricing American options Introduction to exotic and path-dependent options 2.7.1 Barrier options 2.7.2 Asian options 2.7.3 Lookback options

Asset pricing, portfolio optimization, and risk management

2.3

Basic theory of interest rates: compounding and present value Basic pricing of fixed-income securities Interest rate sensitivity and bond portfolio immunization M A T L A B functions to deal with fixed- income securities

2.4 Stock portfolio optimization

and quantile- based measures

From discrete t o continuous t ime 2.5

diflerential equations

Simple binomial model f o r option pricing

2.7

33

37

42

42 49

57

60 64 65 66 73

74 81

83 88 88 91

93 96

100 102 105 108

111 113 116 117 118 119 123 123

CONTENTS ix

2.8 An outlook on interest-rate derivatives 2.8.1 Modeling interest-rate dynamics 2.8.2

For further reading References

Incomplete markets and the market price of risk

Part 11 Numerical Methods

3 Basics of Numerical Analysis 3.1 Nature of numerical computation

3.1.1 Number representation, rounding, and

3.1.2 Error propagation, conditioning, and

3.1.3

Solving systems of linear equations 145 3.2.1 Vector and matrix norms 1463.2.2 3.2.3

3.2.4 Tridiagonal matrices 3.2.5

truncation

instability 141Order of convergence and computational complexity 143

3.2

Condition number for a matrix 149 Direct methods for solving systems of linear equations

Iterative methods for solving systems of linear equations

3.3.1 Ad hoc approximation 3.3.2 Elementary polynomial interpolation 3.3.3 Interpolation by cubic splines 3.3.4

3.3 Function approximation and interpolation

Theory of function approximation by least squares

3.4 Solving non-linear equations 3.4.1 Bisection method 3.4.2 Newton’s method 3.4.3 Optimization- based solution of non-linear

equations 3.4.4 Putting two things together: solving

a functional equation by a collocation method

124 126

127 130 131

137 138

138

154 159

160 173 177

183 1 79

188 191 192 195

198

204

x CONTENTS

3.4.5 Homotopy continuation methods 204 For further reading 206 References 207

4 Numerical Integration: Deterministic and Monte Carlo Methods 4.1 Deterministic quadrature

4.1.1 Classical interpolatory formulas 4.1.2 Gaussian quadrature 4.1.3 Extensions and product rules 4.1.4 Numerical integration in M A T L A B

4.2 Monte Carlo integration 4.3 Generating pseudorandom variates

4.3.1 Generating pseudorandom numbers 4.3.2 Inverse transform method 4.3.3 Acceptance-rejection method 4.3.4

Setting the number of replications

4.5.1 Antithetic sampling 4.5.2 Common random numbers 4.5.3 Control variates 4.5.4 Variance reduction b y conditioning 4.5.5 Stratified sampling 4.5.6 Importance sampling

4.6 Quasi-Monte Carlo simulation 4.6.1 Generating Halton low-discrepancy

sequences 4.6.2 Generating Sobol low-discrepancy

sequences For further reading References

Generating normal variates by the polar approach

4.4 4.5 Variance reduction techniques

5 Finite Diflerence Methods for Partial Digerential Equations 5.1 Introduction and classification of PDEs 5.2 Numerical solution by finite diflerence methods

5.2.1 Bad example of a finite diflerence scheme 295

209 21 1 21 2 214 21 9 220 221 225 226 230 233

235 24 0 244 244 251 252 255 260 261 267

269

281 286 287

289 290 293

CONTENTS xi

5.2.2 Explicit and implicit methods for the heat equation 5.3.1

5.3.2

5.3.3

5.4 Solving the bidimensional heat equation 5.5 Convergence, consistency, and stability

For further reading References

Instability in a finite diflerence scheme 5.3

Solving the heat equation by an explicit method Solving the heat equation by a fu l ly implicit method Solving the heat equation by the Crank- Nicolson method

297

303

304

309

31 3

320 314

324 324

6 Convex Optimization 327 6.1 Classification of optimization problems 328

6.1.1 Finite- us. infinite-dimensional problems 328 6.1.2 Unconstrained us. constrained problems 333 6.1.3 Convex us. non-convex problems 333 6.1.4 Linear us. non-linear problems 335 6.1.5 Continuous us. discrete problems 337 6.1.6 Deterministic us. stochastic problems 337

6.2.1 Steepest descent method 339 6.2.2 The subgradient method 34 0 6.2.3 Newton and the trust region methods 34 1

method and simplex search 342

6.3 Methods for constrained optimization 34 6 6.3.1 Penalty function approach 34 6

6.3.3 Duality theory 357

6.2 Numerical methods for unconstrained optimization 338

6.2.4 No-derivatives algorithms: quasi-Newton

6.2.5 Unconstrained optimization in MATLAB 343

6.3.2 Kuhn-Tucker conditions 351

6.3.4 Kelley 's cutting plane algorithm 363 6.3.5 Active set method 365

6.4 Linear programming 366 6.4.1 Geometric and algebraic features of linear

programming 368 6.4.2 Simplex method 370

xi; CONTENTS

6.4.3 Duality in linear programming 6.4.4 Interior point methods

6.5.1 Linear programming in MATLAB 6.5.2 A trivial L P model for bond portfolio

management 6.5.3 Using quadratic programming to trace

evgicient portfolio frontier 6.5.4 Non-linear programming in MATLAB

6.5 Constrained optimization in MATLAB

6.6 Integrating simulation and optimization S6.1 Elements of convex analysis

S6.1.1 Convexity in optimization S6.1.2 Convex polyhedra and polytopes For further reading References

Part 111 Pricing Equity Options

7 Option Pricing by Binomial and Thnomial Lattices 7.1 Pricing by binomial lattices

7.1.1 Calibrating a binomial lattice 7.1.2

7.1.3

Pricing American options by binomial lattices

Putting two things together: pricing a pay-later option An improved implementation of binomial lattices

7.2

372 375 377 378

380

383 385 387 389 389 393 396 397

4 01 4 02 4 03

410

411 414

7.3 Pricing bidimensional options by binomial lattices 41 7 7.4 Pricing by trinomial lattices 422 7.5 Summary 425

For further reading 426 References 426

8 Option Pricing by Monte Carlo Methods 429 8.1 Path generation 430

8.1.2 Simulating hedging strategies 435 8.1.3 Brownian bridge 439

8.2 Pricing an exchange option 443

8.1.1 Simulating geometric Brownian motion 431

CONTENTS xiii

8.3 Pricing a down-and-out put option 8.3.1 Crude Monte Carlo 8.3.2 Conditional Monte Carlo 8.3.3 Importance sampling Pricing an arithmetic average Asian option 8.4.1 Control variates 8.4.2 Using Halton sequences Estimating Greeks by Monte Carlo sampling For further reading References

8.4

8.5

9 Option Pricing by Finite Diflerence Methods 9.1

9.2

Applying finite diflerence methods to the Black- Scholes equation Pricing a vanilla European option by an explicit method 9.2.1 Financial interpretation of the instability

of the explicit method 481 Pricing a vanilla European option by a fully implicit method Pricing a barrier option by the Crank-Nicolson method

For further reading References

9.3

9.4

9.5 Dealing with American options

Part I V Advanced Optimization Models and Methods

10 Dynamic Programming 10-1 The shortest path problem 10.2 Sequential decision processes

10.2.1 The optimality principle and solving the functional equation

10.3 Solving stochastic decision problems by dynamic programming

10.4 American option pricing by Monte Carlo simulation 10.4.1 A M A T L A B implementation of the least

squares approach

44 6 44 6 44 7 450 4 54 4 55 458 468 4 72 4 73

4 75

4 75

4 78

482

485 486 4 91 4 91

4 95 496 500

501

504

51 1

51 7

xiv CONTENTS

10.4.2 Some remarks and alternative approaches For further reading References

11 Linear Stochastic Programming Models with Recourse 11.1 Linear stochastic programming models 11.2 Multistage stochastic programming models for

portfolio management 11.2.1 Split-variable model formulation 11.2.2 Compact model formulation 11.2.3 Asset and liability management with

11.3 Scenario generation for multistage stochastic programming 11.3.1 Sampling for scenario tree generation 11.3.2 Arbitrage free scenario generation

1 1.4 L-shaped method for two-stage linear stochastic programming

11.5 A comparison with dynamic programming For further reading References

transaction costs

12 Non- Convex Optimization 12.1 Mixed-integer programming models

12.1.1 Modeling with logical variables 12.1.2 Mixed-integer portfolio optimization

12.2 Fixed-mix model based on global optimization 12.3 Branch and bound methods for non-convex

optimization 12.3.1 LP-based branch and bound for MILP

models 12.4 Heuristic methods for non-convex optimization

For further reading References

models

51 9 521 522

525 526

530 532 54 0

544

54 6 54 7 550

555 558 559 560

563 564 565

571 576

578

584 591 597 598

CONTENTS xv

Part V Appendices

Appendix A Introduction to MATLAB Programming 603 A.l MATLAB environment 603

A.3 MATLAB programming 61 6

Appendix B Refresher on Probability Theory and Statistics 623

A.2 MATLAB graphics 614

B.l Sample space, events, and probability B.2 Random variables, expectation, and variance

B.2.1 Common continuous random variables B.3 Jointly distributed random variables B.4 Independence, covariance, and conditional

expectation B.5 Parameter estimation B. 6 Linear regression

For further reading References

Appendix C Introduction to AMPL C. 1 Running optimization models in AMPL C.2 Mean variance eficient portfolios in AMPL C.3 The knapsack model in AMPL C.4 Cash pow matching

For further reading References

Index

623 625 628 632

633 637 642 64 5 64 5

64 7 64 8 64 9 652 655 655 656

657

This Page Intentionally Left Blank

Preface to the Second J

Edition

After the publication of the first edition of the book, about five years ago, I have received a fair number of messages from readers, both students and practitioners, around the world. The recurring keyword, and the most im- portant thing to me, was useful. The book had, and has, no ambition of being a very advanced research book. The basic motivation behind this sec- ond edition is the same behind the first one: providing the newcomer with an easy, but solid, entry point to computational finance, without too much sophisticated mathematics and avoiding the burden of difficult C++ code, also covering relatively non-standard optimization topics such as stochastic and integer programming. See also the excerpt from the preface to the first edition. However, there are a few new things here:

0 a slightly revised title;

0 completely revised organization of chapters;

0 significantly increased number of pages.

The title mentions both Finance and Economics, rather than just Finance. To avoid any misunderstanding, it should be made quite clear that this is essen- tially a book for students and practitioners working in Finance. Nevertheless, it can be useful to Ph.D. students in Economics as well, as a complement to more specific and advanced textbooks. In the last four years, I have been giving a course on numerical methods within a Ph.D. program in Economics, and I typically use other available excellent textbooks covering advanced al- gorithms’ or offering well-thought MATLAB toolboxes2 which can be used to solve a wide array of problems in Economics. From the point of view of my students in such a course, the present book has many deficiencies: For instance, it does not cover ordinary differential equations and it does not deal with computing equilibria or rational expectations models; furthermore, practically all of the examples deal with option pricing or portfolio manage- ment. Nevertheless, given my experience, I believe that they can benefit from a more detailed and elementary treatment of the basics, supported by simple examples. Moreover, I believe that students in Economics should also get

lK.L. Judd, Numerical Methods in Economics, MIT Press, 1998. 2M. J. Miranda and P.L. Fackler, Applied Computational Economics and Finance, MIT Press, 2002.

xvii

xviii PREFACE

at least acquainted with topics from Operations Research, such as stochastic programming and integer programming. Hence, the “and economic^" part of the title suggests potential use of the book as a complement, and by no means as a substitute.

The book has been reorganized in order to ease its use within standard courses on numerical methods for financial engineering. In the first edition, optimiza- tion applications were dealt with extensively, in chapters preceding those re- lated to option pricing. This was a result of my personal background, which is mainly Computer Science and Operations Research, but it did not fit very well with the common use of a book on computational finance. In the present edition, advanced optimization applications are left to the last chapters, so they do not get into the way of most financial engineering students. The book consists of twelve chapters and three appendices.

0 Chapter 1 provides the reader with motivations for the use of numerical methods, and for the use of MATLAB as well.

0 Chapter 2 is an overview of financial theory. It is aimed at students in Engineering, Mathematics, or Operations Research, who may be inter- ested in the book, but have little or no financial background.

0 Chapter 3 is devoted to the basics of classical numerical methods. In some sense, this is complementary to chapter 2 and it is aimed at peo- ple with a background in Economics, who typically are not exposed to numerical analysis. To keep the book to a reasonable size, a few clas- sical topics were omitted because of their limited role in the following chapters. In particular, I do not cover computation of eigenvalues and eigenvectors and ordinary differential equations.

0 Chapter 4 is devoted to numerical integration, both by quadrature for- mulas and Monte Carlo methods. In the first edition, quadrature for- mulas were dealt with in the chapter on numerical analysis, and Monte Carlo was the subject of a separate chapter. I preferred giving a unified treatment of these two approaches, as this helps understanding their re- spective strengths and weaknesses, both for option pricing and scenario generation in stochastic optimization. Regarding Monte Carlo as a tool for integration rather than simulation is also helpful to properly frame the application of low-discrepancy sequences (which is also known un- der the more appealing name of quasi-Monte Carlo simulation). There is some new material on Gaussian quadrature, an extensive treatment of variance reduction methods, and some application to vanilla options to illustrate simple but concrete applications immediately, leaving more complex cases to chapter 8.

0 Chapter 5 deals with basic finite difference schemes for partial differ- ential equations. The main theme is solving the heat equation, which

PREFACE xix

is the prototype example of the class of parabolic equations, to which Black-Scholes equation belongs. In this simplified framework we may understand the difference between explicit and implicit methods, as well as the issues related to convergence and numerical stability. With re- spect to the first edition, I have added an outline of the Alternating Direction Implicit method to solve the two-dimensional heat equation, which is useful background for pricing multidimensional options.

a Chapter 6 deals with finite-dimensional (static) optimization. This chapter can be safely skipped by students interested in the option pric- ing applications described in chapters 7, 8, and 9. However, it may be useful to students in Economics. It is also necessary background for the relatively advanced optimization models and methods which are covered in chapters 10, 11, and 12.

0 Chapter 7 is a new chapter which is devoted to binomial and trinomial lattices, which were not treated extensively in the first edition. The main issues here are proper implementation and memory management.

a Chapter 8 is naturally linked to chapter 4 and deals with more advanced applications of Monte Carlo and low-discrepancy sequences to exotic options, such as barrier and Asian options. We also deal briefly with the estimation of option sensitivities (the Greeks) by Monte Carlo methods. Emphasis is on European-style options; pricing American options by Monte Carlo methods is a more advanced topic which must be analyzed within an appropriate framework, which is done in chapter 10.

a Chapter 9 applies the background of chapter 5 to option pricing by finite difference methods.

a Chapter 10 deals with numerical dynamic programming. The main rea- son for including this chapter is pricing American options by Monte Carlo simulation, which was not covered in the first edition but is gain- ing more and more importance. I have decided to deal with this topic within an appropriate framework, which is dynamic stochastic optimiza- tion. In this chapter we just cover the essentials, which means discrete- time and finite-horizon dynamic programs. Nevertheless, we try to offer a reasonably firm understanding of these topics, both because of their importance in Economics and because understanding dynamic program- ming is helpful in understanding stochastic programming with recourse, which is the subject of the next chapter.

a Chapter 11 deals with linear stochastic programming models with re- course. This is becoming a standard topic for people in Operations Research, whereas people in Economics are much more familiar with dynamic programming. There are good reasons for this state of the matter, but from a methodological point of view I believe that it is very

xx PREFACE

important to compare this approach with dynamic programming; from a practical point of view, stochastic programming has an interesting po- tential both for dynamic portfolio management and for option hedging in incomplete markets.

Chapter 12 also deals with the relatively exotic topic of non-convex opti- mization. The main aim here is introducing mixed-integer programming, which can be used for portfolio management when practically relevant constraints call for the introduction of logical decision variables. We also deal, very shortly, with global optimization, i.e., continuous non-convex optimization, which is important when we leave the comfortable domain of easy optimization problems (i.e., minimizing convex cost functions or maximizing concave utility functions). We also outline heuristic prin- ciples such as local search and genetic algorithms. They are useful to integrate simulation and optimization and are often used in computa- tional economics.

Finally, we offer three appendices on MATLAB, probability and statis- tics, and AMPL. The appendix on MATLAB should be used by the unfamiliar reader to get herself going, but the best way to learn MAT- LAB is by trying and using the online help when needed. The appendix on probability and statistics is just a refresher which is offered for the sake of convenience. The third appendix on AMPL is new, and it reflects the increased role of algebraic languages to describe complex optimiza- tion models. AMPL is a modeling system offering access to a wide array of optimization solvers. The choice of AMPL is just based on personal taste (and the fact that a demo version is available on the web). In fact, GAMS is probably much more common for economic applications, but the concepts are actually the same. This appendix is only required for chapters 11 and 12.

Finally, there are many more pages in this second edition: more than 600 pages, whereas the first edition had about 400. Actually, I had a choice: either including many more topics, such as interest-rate derivatives, or offering a more extended and improved coverage of what was already included in the first edition. While there is indeed some new material, I preferred the second option. Actually, the original plan of the book included two more chapters on interest-rate derivatives, as many readers complained about this lack in the first edition. While writing this increasingly long second edition, I switched to plan B, and interest-rate derivatives are just outlined in the second chapter to point out their peculiarities with respect to stock options. In fact, when planning this new edition, many reviewers warned that there was little hope to cover interest-rate derivatives thoroughly in a limited amount of pages. They require a deeper understanding of risk-neutral pricing, interest rate modeling, and market practice. I do believe that the many readers interested in this

PREFACE xxi

topic can use this book to build a solid basis in numerical methods, which is helpful to tackle the more advanced texts on interest-rate derivatives.

Interest-rate derivatives are not the only significant omission. I could also mention implied lattices and financial econometrics. But since there are excel- lent books covering those topics and I see this one just as an entry point or a complement, I felt that it was more important to give a concrete understand- ing of the basics, including some less familiar topics. This is also why I prefer using MATLAB, rather than C++ or Visual Basic. While there is no doubt that C++ has many merits for developing professional code, both in terms of efficiency and object orientation, it is way too complex for newcomers. Fur- thermore, the heavy burden it places on the reader tends to overshadow the underlying concepts, which are the real subject of the book. Visual Basic would be a very convenient choice: It is widespread, and it does not require yet another license, since it is included in software tools that almost everyone has available. Such a choice would probably increase my royalties as well. Nevertheless, MATLAB code can exploit a wide and reliable library of nu- merical functions and it is much more compact. To the very least, it can be considered a good language for fast prototyping. These considerations, as well as the introduction of new MATLAB toolboxes aimed a t financial applications, are the reasons why I am sticking to my original choice. The increasing number of books using MATLAB seems to confirm that it was a good one.

Acknowledgments. I have received much appreciated feedback and encour- agement from readers of the first edition of the book. Some pointed out typos, errors, and inaccuracies. Offering apologies for possible omissions, I would like to thank I-Jung Hsiao, Sandra Hui, Byunggyoo Kim, Scott Lyden, Alexander Reisz, Ayumu Satoh, and Aldo Tagliani.

Supplements. As with the first edition, I plan to keep a web page containing the (hopefully short) list of errata and the (hopefully long) list of supplements, as well as the MATLAB code described in the book. My current URL is:

http://staff.polito.it/paolo.brandimarte

For comments, suggestions, and criticisms, my e-mail address is

paolo. brandimarteQpolito. it

One of the many corollaries of Murphy’s law says that my URL is going to change shortly after publication of the book. An up-to-date link will be maintained both on Wiley Web page:

ht tp : //www . wile y . com/mat hemat i cs and on The Mathworks’ web page:

http : //www . mathworks. com/support/books/

PAOLO BRANDIMARTE Turin, March 2006

This Page Intentionally Left Blank

From the Preface to the First Edition

Crossroads are hardly, if ever, points of arrival; but neither are they points of departure. In some sense, crossroads may be disappointing, indeed. You are tired of driving, you are not a t home yet, and by Murphy’s law there is a far- from-negligible probability of taking the wrong turn. In this book, different paths cross, involving finance, numerical analysis, optimization theory, prob- ability theory, Monte Carlo simulation, and partial differential equations. It is not a point of departure, because although the prerequisites are fairly low, some level of mathematical maturity on the part of the reader is assumed. It is not a point of arrival, as many relevant issues have been omitted, such as hedging exotic options and interest-rate derivatives.

The book stems from lectures I give in a Master’s course on numerical methods for finance, aimed at graduate students in Economics, and in an optimization course aimed at students in Industrial Engineering. Hence, this is not a research monograph; it is a textbook for students. On the one hand, students in Economics usually have little background in numerical methods and lack the ability to translate algorithmic concepts into a working program; on the other hand, students in Engineering do not see the potential application of quantitative methods to finance clearly.

Although there is an increasing literature on high-level mathematics applied to financial engineering, and a few books illustrating how cookbook recipes may be applied to a wide variety of problems through use of a spreadsheet, I believe there is some need for an intermediate-level book, both interesting to practitioners and suitable for self-study. I believe that students should:

Acquire reasonably strong foundations in order to appreciate the issues behind the application of numerical methods

Be able to translate and check ideas quickly in a computational envi- ronment

Gain confidence in their ability to apply methods, even by carrying out the apparently pointless task of using relatively sophisticated tools to pricing a vanilla European option

Be encouraged to pursue further study by tackling more advanced sub- jects, from both practical and theoretical perspectives

The material covered in the book has been selected with these aims in mind. Of course, personal tastes are admittedly reflected, and this has something to

mi;;

xxiv PREFACE

do with my Operations Research background. I am afraid the book will not please statisticians, as no econometric model is developed; however, there is a wide and excellent literature on those topics, and I tried to come up with a complementary text book.

The text is interspersed with MATLAB snapshots and pieces of code, to make the material as lively as possible and of immediate use. MATLAB is a flexible high-level computing environment which allows us to implement non- trivial algorithms with a few lines of code. It has also been chosen because of its increasing potential for specific financial applications.

It may be argued that the book is more successful at raising questions than at giving answers. This is a necessary evil, given the space available to cover such a wide array of topics. But if, after reading this book, students will want to read others, my job will have been accomplished. This was meant to be a crossroads, after all.

PS1. Despite all of my effort, the book is likely to contain some errors and typos. I will maintain a list of errata, which will be updated, based on reader feedback. Any comment or suggestion on the book will also be appreciated. My e-mail address is: paolo. brandimarteOpolito. it.

PS2. The list of errata will be posted on a Web page which will also include additional material and MATLAB programs. The current URL is

http://staff.polito.it/paolo.brandimarte

An up-to-date link will be maintained on Wiley Web page:

http://www.wiley.com/mathematics

PS3. And if (what a shame ...) you are wondering who Commander Straker is, take a look at the following Web sites:

http://www.ufoseries.com

http://www.isoshado.org

PAOLO BRANDIMARTE Turin, June 2001

Part I ~~

Background

This Page Intentionally Left Blank

Mo tiva t io n

Cornnion wisdom would probably associate the ideas of numerical methods aiid number crunching to problems in science and engineering, rather than finance. This irit.uit.ive view is contradicted by the relatively large number of books and scicritific journals devoted to computational finance; even more so, hy thc fact, that, these methods are not confined to academia, but are actually usrd i n real life. As a result, there has been a steady increase in the number of academic programs devoted to quantitative finance, both a t Master’s and Pt1.D. level, and they usually include a course on numerical methods. Fur- thermore, riiany people with a quantitative or numerical analysis background have started working in finance, including engineers, mathematicians, and physicists.

Indeed, as the tern1 financial engineering may suggest, computational fi- nance is a field where different cultures meet. Hence, a wide array of students and practitioners, with diverse background, will hopefully be interested in a book on riurrirrical methods for finance. On t,he one hand, this is good news for the author. On the other one, the first difficult task is to get evcryonc on coniriion ground as far as financial theory and the basics of numerical aiialysis are concerned; if treatment is too brief, there is a significant risk of losing a considerable subset of readers along the way; if it is too detailed, aiiot,her subset will be considerably bored. The aim of the first three chapters is t,o “synchronize” readers with a background in Finance and readers with it scient.ific background, including students in Engineering, Mathematics, and Physics. In chapter 2, we will give the second subset of readers an overview of coiicept,s in finance, with an emphasis on asset pricing and portfolio man-

3

4 MOT/VAT/ON

agement. The first subset of readers will find a reasonably self-contained treatment on classical topics of numerical analysis in chapter 3.

In this introductory chapter we want to give a preview of the problems we will deal with, along with some motivation. The reader who is unfamiliar with some topics just outlined here should not be worried, as they are not taken for granted and will be treated thoroughly in the next chapters. We want to make three points:

1. In financial engineering we need numerical methods (section 1.1).

2. We need sophisticated and user-friendly numerical computing environ- ments, such as MATLAB' (section 1.2), even if this does not prevent at all the use of (relatively) low-level languages such as Fortran or C++ or spreadsheets such as Microsoft Excel.

3. Whatever software tool we select, we need a reasonably strong theoreti- cal background, as we must often select among competing methods and many things may go wrong with them (section 1.3).

1.1 NEED FOR NUMERICAL METHODS

Probably, the best-known result in financial engineering is the Black-Scholes formula to price options on stocks.2 Options are a class of derivatives, i.e., financial assets whose value depends on another asset, called the underlying. The underlying can also be a non-financial asset, such as a commodity, or an arbitrary quantity representing a risk factor to someone, such as weather, so that setting up a market to transfer risks makes sense. Options are contracts with very specific rules for issuing, trading, and accounting. For instance, a European-style call option on a stock gives the holder the right, but not the obligation, of buying a given stock a t a given time (maturity, denoted by T ) , for a prespecified price (the strike price, denoted by K ) . Similarly, a put option gives the right to sell the underlying asset at a predetermined strike price. In European-style derivatives, the right specified in the contract can only be exercised a t maturity T ; in American-style derivatives, one can exercise her right at any time before T , which in this case plays the role of the expiration date of the option.

In the case of a European-style call option, if the asset price at maturity is S ( T ) , then the payoff is max{S(T) - K , 0). The rationale here is that, under idealized assumptions on financial markets, the option holder could purchase

'MATLAB is a registered trademark of The Mathworks, Inc. For more information, see http://vvv.mathvorks.com. 2The formula was published by Fisher Black and Myron Scholes in 1973. A similar research line had been pursued by Robert Merton, and in fact Scholes and Merton were awarded the Nobel prize in Economics in 1997. By that time, unfortunately, Fisher Black was deceased.