handbook in › download › 0002 › 6453 › ...10.3.1 local search and other metaheuristics 433...

30

Upload: others

Post on 05-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm
Page 2: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm
Page 3: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Handbook in Monte Carlo Simulation

Page 4: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Wiley Handbooks in

FINANCIAL ENGINEERING AND ECONOMETRICS Advisory Editor Ruey S. Tsay The University of Chicago Booth School of Business, USA

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

Page 5: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Handbook in Monte Carlo Simulation Applications in Financial Engineering, Risk Management, and Economics

PAOLO BRANDIMARTE Department of Mathematical Sciences Politecnico di Torino Torino, Italy

W I L E Y

Page 6: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Copyright © 2014 by John Wiley & Sons, Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey. All rights reserved. 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., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://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. Handbook in Monte Carlo simulation : applications in financial engineering, risk management, and economics /

Paolo Brandimarte. pages cm

Includes bibliographical references and index. ISBN 978-0-470-53111-2 (cloth) 1. Finance—Mathematical models. 2. Economics—Mathematical models. 3. Monte Carlo method. I. Title. HG106.B735 2014 330.01'518282—dc23 2013047832

Printed in the United States of America.

10 9 8 7 6 5 4 3 2 1

Page 7: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Preface xiii

Part I Overview and Motivation

1 Introduction to Monte Carlo Methods 3 1.1 Historical origin of Monte Carlo simulation 4 1.2 Monte Carlo simulation vs. Monte Carlo sampling 7 1.3 System dynamics and the mechanics of Monte Carlo simulation 10

1.3.1 Discrete-time models 10 1.3.2 Continuous-time models 13 1.3.3 Discrete-event models 16

1.4 Simulation and optimization 22 1.4.1 Nonconvex optimization 23 1.4.2 Stochastic optimization 26 1.4.3 Stochastic dynamic programming 28

1.5 Pitfalls in Monte Carlo simulation 30 1.5.1 Technical issues 31 1.5.2 Philosophical issues 33

1.6 Software tools for Monte Carlo simulation 35 1.7 Prerequisites 37

1.7.1 Mathematical background 37 1.7.2 Financial background 38 1.7.3 Technical background 38

For further reading 39 References 39

2 Numerical Integration Methods 41 2.1 Classical quadrature formulas 43

2.1.1 The rectangle rule 44 2.1.2 Interpolatory quadrature formulas 45 2.1.3 An alternative derivation 46

2.2 Gaussian quadrature 48 2.2.1 Theory of Gaussian quadrature: The role of orthogonal

polynomials 49 2.2.2 Gaussian quadrature in R 51

2.3 Extension to higher dimensions: Product rules 53 V

Contents

v

Page 8: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

vi CONTENTS

2.4 Alternative approaches for high-dimensional integration 55 2.4.1 Monte Carlo integration 56 2.4.2 Low-discrepancy sequences 59 2.4.3 Lattice methods 61

2.5 Relationship with moment matching 67 2.5.1 Binomial lattices 67 2.5.2 Scenario generation in stochastic programming 69

2.6 Numerical integration in R 69 For further reading 71 References 71

Part II Input Analysis: Modeling and Estimation

3 Stochastic Modeling in Finance and Economics 75 3.1 Introductory examples 77

3.1.1 Single-period portfolio optimization and modeling returns 78

3.1.2 Consumption-saving with uncertain labor income 81 3.1.3 Continuous-time models for asset prices and interest

rates 83 3.2 Some common probability distributions 86

3.2.1 Bernoulli, binomial, and geometric variables 88 3.2.2 Exponential and Poisson distributions 92 3.2.3 Normal and related distributions 98 3.2.4 Beta distribution 105 3.2.5 Gamma distribution 107 3.2.6 Empirical distributions 108

3.3 Multivariate distributions: Covariance and correlation 112 3.3.1 Multivariate distributions 113 3.3.2 Covariance and Pearson's correlation 118 3.3.3 R functions for covariance and correlation 122 3.3.4 Some typical multivariate distributions 124

3.4 Modeling dependence with copulas 128 3.4.1 Kendall's tau and Spearman's rho 134 3.4.2 Tail dependence 136

3.5 Linear regression models: A probabilistic view 137 3.6 Time series models 138

3.6.1 Moving-average processes 142 3.6.2 Autoregressive processes 147 3.6.3 ARMA and ARIMA processes 151 3.6.4 Vector autoregressive models 155 3.6.5 Modeling stochastic volatility 157

3.7 Stochastic differential equations 159 3.7.1 From discrete to continuous time 160

Page 9: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

CONTENTS vii

3.7.2 Standard Wiener process 163 3.7.3 Stochastic integration and Ito's lemma 167 3.7.4 Geometric Brownian motion 173 3.7.5 Generalizations 176

3.8 Dimensionality reduction 178 3.8.1 Principal component analysis (PCA) 179 3.8.2 Factor models 189

3.9 Risk-neutral derivative pricing 192 3.9.1 Option pricing in the binomial model 193 3.9.2 A continuous-time model for option pricing: The

Black-Scholes-Merton formula 196 3.9.3 Option pricing in incomplete markets 203

For further reading 205 References 206

4 Estimation and Fitting 209

4.2 Parameter estimation 219 4.2.1 Features of point estimators 221 4.2.2 The method of moments 222 4.2.3 The method of maximum likelihood 223 4.2.4 Distribution fitting in R 227

4.3 Checking the fit of hypothetical distributions 228 4.3.1 The chi-square test 229 4.3.2 The Kolmogorov-Smirnov test 231 4.3.3 Testing normality 232

4.4 Estimation of linear regression models by ordinary least squares 233 4.5 Fitting time series models 237 4.6 Subjective probability: The Bayesian view 239

4.6.1 Bayesian estimation 241 4.6.2 Bayesian learning and coin flipping 243

For further reading 248 References 249

Part III Sampling and Path Generation

5 Random Variate Generation 253 5.1 The structure of a Monte Carlo simulation 254 5.2 Generating pseudorandom numbers 256

5.2.1 Linear congruential generators 256 5.2.2 Desirable properties of random number generators 260

4.1 Basic inferential statistics in R 2114.1.1 Confidence intervals 2114.1.2 Hypothesis testing 2144.1.3 Correlation testing 218

Page 10: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

viii CONTENTS

5.2.3 General structure of random number generators 264 5.2.4 Random number generators in R 266

5.3 The inverse transform method 267 5.4 The acceptance-rejection method 269 5.5 Generating normal variates 276

5.5.1 Sampling the standard normal distribution 276 5.5.2 Sampling a multivariate normal distribution 278

5.6 Other ad hoc methods 282 5.7 Sampling from copulas 283 For further reading 286 References 287

6 Sample Path Generation for Continuous-Time Models 289 6.1 Issues in path generation 290

6.1.1 Euler vs. Milstein schemes 293 6.1.2 Predictor-corrector methods 295

6.2 Simulating geometric Brownian motion 297 6.2.1 An application: Pricing a vanilla call option 299 6.2.2 Multidimensional GBM 301 6.2.3 The Brownian bridge 304

6.3 Sample paths of short-term interest rates 308 6.3.1 The Vasicek short-rate model 310 6.3.2 The Cox-Ingersoll-Ross short-rate model 312

6.4 Dealing with stochastic volatility 315 6.5 Dealing with jumps 316 For further reading 319 References 320

Part IV Output Analysis and Efficiency Improvement

7 Output Analysis 325 7.1 Pitfalls in output analysis 327

7.1.1 Bias and dependence issues: A financial example 330 7.2 Setting the number of replications 334 7.3 A world beyond averages 335 7.4 Good and bad news 337 For further reading 338 References 338

8 Variance Reduction Methods 341 8.1 Antithetic sampling 342 8.2 Common random numbers 348 8.3 Control variates 349 8.4 Conditional Monte Carlo 353

Page 11: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

CONTENTS ix

8.5 Stratified sampling 357 8.6 Importance sampling 364

8.6.1 Importance sampling and rare events 370 8.6.2 A digression: Moment and cumulant generating

functions 373 8.6.3 Exponential tilting 374

For further reading 376 References 377

9 Low-Discrepancy Sequences 379 9.1 Low-discrepancy sequences 380 9.2 Halton sequences 382 9.3 Sobol low-discrepancy sequences 387

9.3.1 Sobol sequences and the algebra of polynomials 389 9.4 Randomized and scrambled low-discrepancy sequences 393 9.5 Sample path generation with low-discrepancy sequences 395 For further reading 399 References 400

Part V Miscellaneous Applications

10 Optimization 405 10.1 Classification of optimization problems 407 10.2 Optimization model building 421

10.2.1 Mean-variance portfolio optimization 421 10.2.2 Modeling with logical decision variables: Optimal

portfolio tracking 422 10.2.3 A scenario-based model for the newsvendor problem 425 10.2.4 Fixed-mix asset allocation 426 10.2.5 Asset pricing 427 10.2.6 Parameter estimation and model calibration 430

10.3 Monte Carlo methods for global optimization 432 10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm optimization 441

10.4 Direct search and simulation-based optimization methods 444 10.4.1 Simplex search 445 10.4.2 Metamodeling 446

10.5 Stochastic programming models 448 10.5.1 Two-stage stochastic linear programming with recourse 448 10.5.2 A multistage model for portfolio management 452 10.5.3 Scenario generation and stability in stochastic programming 457

10.6 Stochastic dynamic programming 469

Page 12: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

CONTENTS x

10.6.1 The shortest path problem 470 10.6.2 The functional equation of dynamic programming 473 10.6.3 Infinite-horizon stochastic optimization 477 10.6.4 Stochastic programming with recourse vs. dynamic

programming 478 10.7 Numerical dynamic programming 480

10.7.1 Approximating the value function: A deterministic example 480

10.7.2 Value iteration for infinite-horizon problems 484 10.7.3 A numerical approach to consumption-saving 493

10.8 Approximate dynamic programming 506 10.8.1 A basic version of ADP 507 10.8.2 Post-decision state variables in ADP 510 10.8.3 Q-learning for a simple MDP 513

For further reading 519 References 520

11 Option Pricing 525 11.1 European-style multidimensional options in the BSM world 526 11.2 European-style path-dependent options in the BSM world 532

11.2.1 Pricing a barrier option 532 11.2.2 Pricing an arithmetic average Asian option 539

11.3 Pricing options with early exercise features 546 11.3.1 Sources of bias in pricing options with early exercise

features 548 11.3.2 The scenario tree approach 549 11.3.3 The regression-based approach 552

11.4 A look outside the BSM world: Equity options under the Heston model 560

11.5 Pricing interest rate derivatives 563 11.5.1 Pricing bonds and bond options under the Vasicek

model 565 11.5.2 Pricing a zero-coupon bond under the CIR model 567

For further reading 569 References 569

12 Sensitivity Estimation 573 12.1 Estimating option greeks by finite differences 575 12.2 Estimating option greeks by pathwise derivatives 581 12.3 Estimating option greeks by the likelihood ratio method 585 For further reading 589 References 590

13 Risk Measurement and Management 591 13.1 What is a risk measure? 593 13.2 Quantile-based risk measures: Value-at-risk 595

x

Page 13: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

CONTENTS xi

13.3 Issues in Monte Carlo estimation of V@R 601 13.4 Variance reduction methods for V@R 607 13.5 Mean-risk models in stochastic programming 613 13.6 Simulating delta hedging strategies 619 13.7 The interplay of financial and nonfinancial risks 625 For further reading 626 References 627

14 Markov Chain Monte Carlo and Bayesian Statistics 629 14.1 Acceptance-rejection sampling in Bayesian statistics 630 14.2 An introduction to Markov chains 631 14.3 The Metropolis-Hastings algorithm 636

14.3.1 The Gibbs sampler 640 14.4 A re-examination of simulated annealing 643 For further reading 646 References 647

Index 649

Page 14: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm
Page 15: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Preface

The aim of this book is to provide a wide class of readers with a low- to in-termediate-level treatment of Monte Carlo methods for applications in finance and economics. The target audience consists of students and junior practitioners with a quantitative background, and it includes not only students in economics and finance, but also in mathematics, statistics, and engineering. In fact, this is the kind of audience I typically deal with in my courses. Not all of these read-ers have a strong background in either statistics, financial economics, or econo-metrics, which is why I have also included some basic material on stochastic modeling in the early chapters, which is typically skipped in higher level books. Clearly, this is not meant as a substitute for a proper treatment, which can be found in the references listed at the end of each chapter. Some level of mathe-matical maturity is assumed, but the prerequisites are rather low and boil down to the essentials of probability and statistics, as well as some basic programming skills.1 Advanced readers may skip the introductory chapters on modeling and estimation, which are also included as a reminder that no Monte Carlo method, however sophisticated, will yield useful results if the input model is flawed. In-deed, the power and flexibility of such methods may lure us into a false sense of security, making us forget some of their inherent limitations.

Option pricing is certainly a relevant application domain for the techniques we discuss in the book, but this is not meant to be a book on financial engineer-ing. I have also included a significant amount of material on optimization in its many guises, as well as a chapter related to computational Bayesian statistics. I have favored a wide scope over a deeply technical treatment, for which there are already some really excellent and more demanding books. Many of them, however, do not quite help the reader to really "feel" what she is learning, as no ready-to-use code is offered. In order to allow anyone to run the code, play with it, and hopefully come up with some variations on the theme, I have cho-sen to develop code in R. Readers familiar with my previous book written in MATLAB might wonder whether I have changed my mind. I did not: I never use R in research or consulting, but I use it a lot for teaching. When I started writing the book, I was less than impressed by the lack of an adequate develop-ment environment, and some design choices of the language itself left me a bit puzzled. As an example, the * operator in MATLAB multiplies matrices row by column; whenever you want to work elementwise, you use the . operator, which has a clear and uniform meaning when applied to other operators. On the

*In case of need, the mathematical prerequisites are covered in my other book: Quantitative Methods: An Introduction for Business Management. Wiley, 2011.

x i i i

Page 16: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

xiv PREFACE

contrary, the operator * works elementwise in R, and row-by-column matrix product is accomplished by the somewhat baroque operator %*%. Furthermore, having to desperately google every time you have to understand a command, because documentation is a bit poor and you have to make your way in a mess of packages, may be quite frustrating at times. I have also found that some op-timization functions are less accurate and less clever in dealing with limit cases than the corresponding MATLAB functions. Having said that, while working on the book, I have started to appreciate R much more. Also my teaching ex-perience with R has certainly been fun and rewarding. A free tool with such a potential as R is certainly most welcome, and R developers must be praised for offering all of this. Hopefully, the reader will find R code useful as a starting point for further experimentation. I did not assemble R code into a package, as this would be extremely misleading: I had no plan to develop an integrated and reliable set of functions. I just use R code to illustrate ideas in concrete terms and to encourage active learning. When appropriate, I have pointed out some programming practices that may help in reducing the computational burden, but as a general rule I have tried to emphasize clarity over efficiency. I have also avoided writing an introduction to R programming, as there are many freely available tutorials (and a few good books2). A reader with some programming experience in any language should be able to make her way through the code, which has been commented on when necessary. My assumption is that a reader, when stumbling upon an unknown function, will take advantage of the online help and the example I provide in order to understand its use and potentiality. Typically, R library functions are equipped with optional parameters that can be put to good use, but for the sake of conciseness I have refrained from a full description of function inputs.

Book structure

The book is organized in five parts.

1. Part I, Overview and Motivation, consists of two chapters. Chapter 1 provides an introduction to Monte Carlo methods and applications. The different classes of dynamic models that are encountered in simulation are outlined, and due emphasis is placed on pitfalls and limitations of Monte Carlo methods. Chapter 2 deals with numerical integration meth-ods. Numerical integration is quite relevant, as it provided most of the historical motivation to develop Monte Carlo methods; furthermore, there are cases in which one is much better off using good quadrature formu-las than throwing random numbers around. Finally, framing Monte Carlo methods within numerical integration provides the necessary discipline to understand and properly use low-discrepancy sequences, sometimes referred to as quasi-Monte Carlo methods.

2Unfortunately, I have also run into very bad books using R; hopefully, this one will not con-tribute to the list.

Page 17: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

PREFACE XV

2. Part II, Input Analysis: Modeling and Estimation, is specifically aimed at students and newcomers, as it includes two introductory chapters dealing with stochastic model building (Chapter 3) and model fitting (Chapter 4). Essentially, in this part of the book we are concerned with the modeling of inputs of a Monte Carlo simulation. Many advanced books on Monte Carlo methods for finance skip and take for granted these concepts. I have preferred to offer a limited treatment for the sake of unfamiliar readers, such as students in engineering or practitioners without an econometrics background. Needless to say, space does not allow for a deep treatment, but I believe that it is important to build at least a framework for further study. In order to make this part useful to intermediate readers, too, I have taken each topic as an excuse for a further illustration of R functionalities. Furthermore, some more advanced sections may be useful to students in economics and finance as well, such as those on stochastic calculus, copulas, and Bayesian statistics.

3. Part III, Sampling and Path Generation, is more technical and consists of two chapters. In Chapter 5 we deal with pseudorandom number and variate generation. While it is certainly true that in common practice one takes advantage of reliable generators provided by software tools like R, and there is no need for an overly deep treatment, some basic knowledge is needed in order to select generators and to manage simulation runs properly. We also outline scenario generation using copulas. In Chapter 6 we deal with sample path generation for continuous-time models based on stochastic differential equations. This is an essential tool for any financial engineer and is at the heart of many derivative pricing methods. It is important to point out that this is also relevant for risk managers, insurers, and some economists as well.

4. Part IV, Output Analysis and Efficiency Improvement, looks at the fi-nal step of the simulation process. Monte Carlo methods are extremely powerful and flexible; yet, their output may not be quite reliable, and an unreasonable computational effort may be called for, unless suitable countermeasures are taken. Chapter 7 covers very simple, and possibly overlooked, concepts related to confidence intervals. Counterexamples are used to point out the danger of forgetting some underlying assump-tions. Chapter 8 deals with variance reduction strategies that are essential in many financial engineering and risk management applications; indeed, the techniques illustrated here are applied in later chapters, too. Chapter 9 deals with low-discrepancy sequences, which are sometimes gathered un-der the quasi-Monte Carlo nickname. Actually, there is nothing stochas-tic in low-discrepancy sequences, which should be regarded as determin-istic numerical integration strategies. For a certain range of problem di-mensionality, they are a good alternative to pseudorandom sampling.

5. Part IV, Miscellaneous Applications, includes five more or less interre-lated chapters dealing with:

Page 18: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

xvi PREFACE

• The interplay between optimization and Monte Carlo methods, includ-ing stochastic methods for deterministic global optimization, scenario generation for stochastic programming with recourse, and stochastic dynamic programming (Chapter 10)

- Option pricing, with an emphasis on variance reduction methods (Chap-ter 11)

• Obtaining sensitivity of performance measures with Monte Carlo sim-ulation (Chapter 12)

• Risk measurement and management, with an emphasis on value-at-risk and related risk measures for financial risk management (Chapter 13)

• Markov chain Monte Carlo (MCMC) methods, which are relevant for different applications, most notably computational Bayesian statistics (Chapter 14)

There are some logical precedences among these final chapters, but they need not be read in a strict sequential order. Chapter 14 is independent of the others, and the only link is represented by the possibility of regarding simulated annealing, a stochastic approach for both global and combina-torial optimization, as an MCMC method. Stochastic dynamic program-ming, dealt with in Chapter 10, is needed to understand American-style option pricing in Chapter 11. Measuring option price sensitivity is used as a motivating example in Chapter 12, but the methods outlined there have a much more general applicability, as they can also be used within optimization procedures. Finally, there is certainly a natural link between option pricing and the risk management examples discussed in Chapter 13.

Supplements and R code

The code has been organized in two files per chapter. The first one contains all of the function definitions and the reference to required packages, if any; this file should be sourced before running the scripts, which are included as chunks of code in a second file. An archive including all of the R code will be posted on a webpage. My current URL is

* http://staff.polito.it/paolo.brandimarte/ A hopefully short list of errata will be posted there as well. One of the many

corollaries of Murphy's law states that my URL is going to change shortly after publication of the book. An up-to-date link will be maintained on the Wiley webpage:

• http://www.wiley.com/ For comments, suggestions, and criticisms, all of which are quite welcome,

my e-mail address is

Page 19: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

PREFACE xvii

[email protected]

PAOLO BRANDIMARTE

Turin, February 2014

Page 20: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm
Page 21: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Part One

Overview and Motivation

Page 22: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm
Page 23: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

Chapter O n e

Introduction to Monte Carlo Methods

The term Monte Carlo is typically associated with the process of modeling and simulating a system affected by randomness: Several random scenarios are gen-erated, and relevant statistics are gathered in order to assess, e.g., the perfor-mance of a decision policy or the value of an asset. Stated as such, it sounds like a fairly easy task from a conceptual point of view, even though some pro-gramming craft might be needed. Although it is certainly true that Monte Carlo methods are extremely flexible and valuable tools, quite often the last resort ap-proach for overly complicated problems impervious to a more mathematically elegant treatment, it is also true that running a bad Monte Carlo simulation is very easy as well. There are several reasons why this may happen:

• We are using a wrong model of uncertainty:

- Because we are using an unrealistic probability distribution

- Or because we are missing some link among the underlying risk factors

- Or because some unknown parameters have been poorly estimated - Or because the very nature of uncertainty in our problem does not lend

itself to a stochastic representation

• The output estimates are not reliable enough, i.e., the estimator variance is so large that a much larger sample size is required.

• There is a systematic error in the estimates, which could be low or high biased.

• The way we generate sample paths, possibly discretizing a continuous-time model, induces a non-negligible error.

• We are using poor random variate generators. • There is some possibly subtle bug in the computer program implementing

the method.

Some of these issues are technical and can be addressed by the techniques that we will explore in this book, but others are more conceptual in nature and point out a few intrinsic and inescapable limitations of Monte Carlo methods; it is wise not to forget them, while exploring the richness and power of the approach.

3

Page 24: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

4 CHAPTER 1 Introduction to Monte Carlo Methods

The best countermeasure, in order to avoid the aforementioned pitfalls, is to build reasonably strong theoretical foundations and to gain a deep under-standing of the Monte Carlo approach and its variants. To that end, a good first step is to frame Monte Carlo methods as a numerical integration tool. Indeed, while the term simulation sounds more exciting, the term Monte Carlo sampling is often used. The latter is more appropriate when we deal with Monte Carlo sampling as a tool for numerical integration or statistical computing. Granted, the idea of simulating financial markets is somewhat more appealing than the idea of computing a multidimensional integral. However, a more conceptual framework helps in understanding powerful methods for reducing, or avoiding altogether, the difficulties related to the variance of random estimators. Some of these methods, such as low-discrepancy sequences and Gaussian quadrature, are actually deterministic in nature, but their understanding needs a view inte-grating numerical integration and statistical sampling.

In this introductory chapter, we consider first the historical roots of Monte Carlo; we will see in Section 1.1 that some early Monte Carlo methods were actually aimed at solving deterministic problems. Then, in Section 1.2 we com-pare Monte Carlo sampling and Monte Carlo simulation, showing their deep relationship. Typical simulations deal with dynamic systems evolving in time, and there are three essential kinds of dynamic models:

• Continuous-time models • Discrete-time models • Discrete-event models

These model classes are introduced in Section 1.3, where we also illustrate how their nature affects the mechanics of Monte Carlo simulation. In this book, a rather relevant role is played by applications involving optimization. This may sound odd to readers who associate simulation with performance evaluation; on the contrary, there is a multiway interaction between optimization and Monte Carlo methods, which is outlined in Section 1.4.

In this book we illustrate a rather wide range of applications, which may suggest the idea that Monte Carlo methods are almost a panacea. Unfortunately, this power may hide many pitfalls and dangers. In Section 1.5 we aim at making the reader aware of some of these traps. Finally, in Section 1.6 we list a few software tools that are commonly used to implement Monte Carlo simulations, justifying the choice of R as the language of this book, and in Section 1.7 we list prerequisites and references for readers who may need a refresher on some background material.

1.1 Historical origin of Monte Carlo simulation

Monte Carlo methods involve random sampling, but the actual aim is to estimate a deterministic quantity. Indeed, a well-known and early use of Monte Carlo-

Page 25: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

1.1 Historical origin of Monte Carlo simulation 5

FIGURE 1.1 An illustration of Buffon's needle.

like methods is Buffon's needle approach to estimate ir.1 The idea, illustrated in Fig. 1.1, is to randomly throw n times a needle of length I on a floor consisting of wood strips of width t > I, and to observe the number of times h that the needle crosses the border between two strips. Let X be the distance from the center of the needle to the closest border; X is a uniform random variable on the range [0, t/2], and its probability density function is 2/t on that interval and 0 outside.2 By a similar token, let 9 be the acute angle between the needle and that border; this is another uniformly distributed variable, on the range [0, n/2], with density 2/7r on that support. Using elementary trigonometry, it is easy to see that the needle will cross a border when

X < - sin (9. ~ 2

The probability of this event is found by integrating the joint density of the random variables X and 0 over the relevant domain. Assuming independence, the joint density is just the product of the two marginals. Therefore, we have to compute a double integral as follows:

rn/2 p(l/2) sin 0 * 2/ ^tt/2 9j / / —dxde = — sin ode = —.

Jo Jo to to Jo to If we want to estimate 7r, we can use a sample estimate of this probability, i.e., the ratio of h over n:

h ^ 21 ^ _2ln n t7T th

^ h e estimation of 7r by Monte Carlo methods will also be used as an illustration of variance reduction strategies in Chapter 8. 2

In Chapter 3 we offer a refresher on common probability distributions, among other things.

Page 26: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

6 CHAPTER 1 Introduction to Monte Carlo Methods

estPi <- function(N){ x <- 2 *runif(N)-1 y <- 2 *runif (N)-1 h <- sum(xA2+yA2<=1) return(4*h/N)

R programming notes:

1. A function is created by the f u n c t i o n keyword, followed by the input arguments, and assigned to a variable.

2. run if is a typical R function, featuring the r prefix, for generating a random sample of given size from a selected distribution. In the following, we will meet similar functions, like rexp and rnorm, to sample from an exponential and a normal distribution, respectively.

3. The expression sum(xA2+yA2<=l) illustrates an interesting feature of R to get rid of for loops: It returns a vector of elements with values FALSE or TRUE, which are interpreted in the sum as 0/1, respectively.

FIGURE 1 .2 Using R to estimate 7T.

We see that the original p rob lem is purely determinist ic, but w e use Mon te Car lo sampl ing as an est imation tool.

A slightly more practical approach, taking advantage of R, is il lustrated in the code of Fig. 1.2. T h e idea is shooting n r andom bullets on the square [—1,1] x [—1,1] and evaluating the f ract ion h/n of points fal l ing inside the unit circle x2 + y2 = 1. Since the ratio be tween the area of the circle and the area of the square is 7r/4, w e have

. 4 h 7r = — .

n

Running the code, 3 w e obtain

> set.seed(55555) > estPi (1000) [1] 3.132 > estPi (1000) [1] 3.14 > estPi (1000) [1] 3.084 > estPi (1000000) [1] 3.141388

3 Later, we will understand in more detail what is accomplished by the command set.seed(55555). For now, it is enough to say that we always use this function to set the state of pseudorandom number generators to a given value, so that the reader can replicate the experiments and obtain the same results. There is nothing special in the argument 55555, apart from the fact that 5 is the author's favorite number.

Page 27: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

1.2 Monte Carlo simulation vs. Monte Carlo sampling 7

> P i [1] 3.141593

Clearly, a huge sample size is needed to obtain a fairly accurate estimate, and this is certainly not the smartest way to estimate ir.

In more recent times, in the period between 1930 and 1950, Monte Carlo methods were used by the likes of Enrico Fermi, Stanislaw Ulam, and John von Neumann to solve problems related to physics. Indeed, such methods were used in the 1950s when the hydrogen bomb was developed at the Los Alamos laboratories. It was then that the term Monte Carlo was coined after the well-known gambling house. Then, luckily enough, the idea moved to other domains, including operations research and economics. At present, Monte Carlo methods are extremely widespread in many domains, including risk management and financial engineering.

1.2 Monte Carlo simulation vs. Monte Carlo sampling

The terms simulation and sampling are both used with reference to Monte Carlo methods. Indeed, there is no 100% sharp line separating the two concepts, and a couple of examples are the best way to get the point.

Example 1.1 Shortfall probability in wealth management

Consider an investor who allocates her wealth W0 to n risky financial assets, such as stock, bonds, derivatives, and whatnot. At time t = 0, the asset price of asset i, i = 1 , . . . , n, is PP, and the (integer) number of shares of assets i in the portfolio is hi. Therefore, the initial wealth

n

W,o = i=1

The portfolio is held up to time t = T, and the price of asset i at the end of this investment horizon depends on a set of underlying risk factors, such as the term structure of interest rates, spreads due to credit risk, inflation, oil price, the overall state of the economy, etc. Let X be a vector random variable, with joint density / x ( x ) , representing these factors. If we assume that the price of each asset at time T is given by a function of the underlying factors,

then the terminal wealth is a function of X, n

WT = Y^hiPT(X), i=1

Page 28: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

8 CHAPTER 1 Introduction to Monte Carlo Methods

which is itself a random variable. On the one hand, we are interested in the expected value of Wt- However, since risk is a quite relevant issue, we might also be interested in the shortfall probability with respect to a target wealth H :

P{WT < H}.

Whatever the case, we are lead to the expected value of some function

y 5 ( x ) / x ( x ) d x . ( i . i )

If we choose <?(X) = 11 Y we obtain the expected value of future wealth; if we choose the indicator function of the event {WT < H}, i.e.,

n n i - J 1 ' i f w t < H , g(X) = 1{Wt<h} = jQ otherw.s^

then we obtain the shortfall probability. Other risk measures can be selected and will be discussed in Chapter 13. Evaluating the multidi-mensional integral in Eq. (1.1) is quite difficult, even when we know the analytical form of the involved functions. As we shall see, by using Monte Carlo we may draw a sample of m observations k = 1 , . . . , m, and estimate the quantities of interest. We are using random sampling as a tool for numerical integration.

In the example above, no simulation is involved at all, assuming that we are able to sample directly the random variable X given its density. In other cases, we may have to cope with a more complicated dynamic model that describes the dynamics of the underlying risk factors over the time interval [0, T]. In such a case, we may not be able to sample risk factors directly, and we have to generate a set of sample paths. Dynamic models may be represented by continuous-time stochastic differential equations4 or by relatively simple discrete-time processes as in the following example.

:P Example 1,2 An autoregressive process

Time series models are quite often used in financial econometrics to describe the evolution of a quantity of interest over time. A simple

4Stochastic differential equations are introduced in Section 3.7, and approaches for sample path generation are described in Chapter 6.

Page 29: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

1.2 Monte Carlo simulation vs. Monte Carlo sampling 9

example of this class of models is an autoregressive (AR) process of order 1 like

Xt = Xt-1+eu (1.2)

where X0 is given and et is the driving stochastic process, i.e., a se-quence of random variables et, t — 1,2,3, In the simplest mod-els, this noise term consists of a sequence of mutually independent and identically distributed normal random variables. We use the no-tation X ~ |\|(/i, a2) to state that X is a normal random variable with expected value /x and variance a 2 . Unfolding the recursion, we im-mediately see that

t Xt = Xo +

T= 1

which implies

The process described by Eq. (1.2) is very easy to analyze, but it is not the most general AR process of order 1. A more general example is

Xt = ii + aXt-i + eu

whose properties critically depend on the coefficient a (see Example 1.4). In other cases, we may have a system of such equations, with mutually correlated random driving factors and a more complicated structure, preventing us from obtaining the probability distribution of the variable of interest in an explicit form. In such a case, we may have to simulate the dynamical system.

On the basis of the above examples, we may argue that the term sampling could be reserved to those cases in which there is no dynamics to be simulated over time, whereas simulation entails the generation of sample paths. We may need to generate sample paths because the dynamical model is complicated and prevents an analytical solution, or because it is important to check the underly-ing variables over time. For instance, when pricing a European-style option,5

we just need to sample the underlying variable at the option maturity. In the easy case of geometric Brownian motion (GBM for short) this boils down to sampling a lognormal random variable, but we have to resort to sample path generation when we step outside that safe and comforting domain, and we enter the realm populated by stochastic volatilities and price jumps. On the contrary, when we are pricing an American-style option, featuring early exercise oppor-tunities, we need a whole sample path, whatever price model we adopt.

5See Section 3.9 and Chapter 11.

Page 30: Handbook in › download › 0002 › 6453 › ...10.3.1 Local search and other metaheuristics 433 10.3.2 Simulated annealing 435 10.3.3 Genetic algorithms 439 10.3.4 Particle swarm

10 CHAPTER 1 Introduction to Monte Carlo Methods

As is usually the case, also the above distinction is not so clear-cut. In both settings we are actually evaluating a possibly high-dimensional integral of a function, in order to estimate a probability or an expectation. The function may be given in analytical form, or it may be defined by a possibly complicated black box, requiring several lines of code to be evaluated. Conceptually, there is no difference. Indeed, numerical integration plays such a pivotal role for a full appreciation of Monte Carlo methods that we will devote the whole of Chapter 2 to it.

1.3 System dynamics and the mechanics of Monte Carlo simulation

When we have to describe the dynamic evolution of a system over time, we typically resort to one of the following model classes:

• Discrete-time models - Continuous-time models • Discrete-event models

From a technical point of view, as usual, the distinction is not sharp. For in-stance, even if we choose a continuous-time model, we have to discretize it in some way for the sake of computational feasibility. This implies that we ac-tually simulate a discrete-time approximation, but given the issues involved in sample path generation, which involves nontrivial concepts related to the nu-merical solution of stochastic differential equations, it is better to stick to the classification above. It is also possible to create somewhat hybrid models, such as stochastic processes including both a diffusion component, which is contin-uous, and jumps, which are related to discrete-event dynamics.

1 . 3 . 1 DISCRETE-TIME MODELS

In discrete-time models we assume that the time horizon [0, T] is discretized in time intervals (time buckets) of width St. In principle, nothing forbids nonuni-form time steps, which may actually be required when dealing with certain financial derivatives; nevertheless, we usually stick to the uniform case for the sake of simplicity. The system is actually observed only at time instants of the form

kSt, fc = 0 , l , . . . , M ,

where T = M St. What happens between two discrete-time instants is not relevant. Typically, we forget about the time bucket size St, which could be a day, a week, or a month, and we use discrete-time subscripts, like t = 0 , 1 , 2 , . . . , directly.