Modeling Derivatives Applications in Matlab, C++, and Excel

NJ • New York • London • San Francisco • Toronto • Sydney Tokyo • Singapore • Hong Kong • Cape Town • Madrid Paris • Milan • Munich • Amsterdam . and Excel Justin London An Imprint of PEARSON EDUCATION Upper Saddle River.Modeling Derivatives Applications in Matlab. C++.

Vice President.A. I.V. Corporate and GovernmentSales. Justin. Inc. No part of this book may be reproduced. Printed in the United States of America First Printing December.4. ISBN 0-13-196259-0 (hardback : alk. Publishing as FT Press Upper Saddle River.S. de C. 2. Ltd. Limited.382-3419.. For sales outside the U. o Pearson Education—Japan Pearson Education Malaysia. All rights reserved.L692E45 2006 Pricing Models in Matlab. Ltd. Pearson Education Singapore. Pearson Educati` n de Mexico. Library of Congress Cataloging-in-Publication Data London. paper) 1. without permission in writing from the publisher. 1-800. please contact U. p. Pearson Education North Asia. For more information. Ltd. New Jersey 07458 FT Press offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. Modeling Credit Derivatives. C++. HF5548. in any form or by any means. 2006 ISBN: 0-13-196259-0 Pearson Education LTD. and Excel. Pte. Pte. corpsales@pearsontechgroup.5’7–dc22 2006023492 . please contact International Sales at international@pearsoned. 1968Modeling Derivatives Applications in Matlab.S. and Excel / Justin London. S. Pearson Education Australia PTY. cm. Ltd. Company and product names mentioned herein are the trademarks or registered trademarks of their respective owners. Editor-in-Chief: Tim Moore Executive Editor: Jim Boyd Editorial Assistant: Susie Abraham Development Editor: Russ Hall Associate Editor-in-Chief and Director of Marketing: Amy Neidlinger Cover Designer: Chuti Prasertsith Managing Editor: Gina Kanouse Senior Project Editor: Lori Lyons Copy Editor: Water Crest Publishing Indexer: Christine Karpeles Compositor: Lori Hughes Manufacturing Buyer: Dan Uhrig © 2007 by Pearson Education. Pearson Education Canada. Title.

and my sister. Milton and Evelyn London. .v To the memory of my grandparents. Joanna. Leon and Leslie. my parents.


13 Bermudan Swaption Pricing in Matlab Endnotes xv xix xxi 1 2 3 6 7 10 11 11 12 14 14 15 18 20 24 25 28 30 33 43 45 50 61 65 vii .5 Bond and Swap Duration. and DV01 Hedging Bond Portfolios 1.7 Bootstrap Method 1.11 Swap Pricing in Matlab Using Term Structure Analysis 1.8 Bootstrapping in Matlab 1.6 Term Structure of Rates 1.10 General Swap Pricing in Matlab Description 1.3 Computing Treasury Bill Prices and Yields in Matlab 1.C ONTENTS Preface Acknowledgments About the Author 1 SWAPS AND FIXED INCOME INSTRUMENTS 1.1 Eurodollar Futures 1.4 Hedging Debt Positions Hedging a Future 91-Day T-Bill Investment with T-Bill Call Short Hedge: Managing the Maturity Gap Maturity Gap and the Carrying Cost Model Managing the Maturity Gap with Eurodollar Put Short Hedge: Hedging a Variable-Rate Loan 1.9 Bootstrapping in Excel 1. Modified Duration.2 Treasury Bills and Bonds Hedging with T-Bill Futures Long Futures Hedge: Hedging Synthetic Futures on 182-Day T-Bill 1.12 Swap Valuation in C++ 1.

6 Matlab Fixed-Income Toolkit for MBS Valuation 3.9 Planned Amortization Classes (PACS) 3.4 Prepayment Risk and Average Life of MBS 3.5 MBS Pricing Using Monte Carlo in C++ 3.and Interest-Only Strips 3. and Roncalli Method e Mashal and Zeevi Method 2.2 Numerical Example of Prepayment Model 3.10 Principal.3 MBS Pricing and Quoting 3.4 Calibrating Copulae Exact Maximum Likelihood Method (EML) The Inference Functions for Margins Method (IFM) The Canonical Maximum Likelihood Method (CML) 2.12 Dynamic Hedging of MBS The Multivariable Density Estimation Method Endnotes 4 COLLATERALIZED DEBT OBLIGATIONS 4.11 Interest Rate Risk 3.1 Definition and Basic Properties of Copula Functions 2.8 CMO Implementation in C++ 3.6 Using Copulas in Excel Endnotes 3 MORTGAGE-BACKED SECURITIES 3.3 Archimedean Copulae 2. Durrelman.1 Prepayment Models 3.7 Collateralized Mortgage Obligations (CMOs) 3. Riboulet.2 Classes of Copula Functions Multivariate Gaussian Copula Multivariate Student’s T Copula 2.5 Numerical Results for Calibrating Real-Market Data Bouy` .viii Contents 2 COPULA FUNCTIONS 2.1 Structure of CDOs Cash Flow CDOs Market Value CDOs Balance Sheet Cash Flows CDOs Arbitrage CDOs Arbitrage Market Value CDOs 67 67 69 69 71 73 74 74 76 76 77 77 82 86 87 91 93 95 98 100 111 126 131 137 146 149 151 151 153 160 163 164 165 166 166 166 166 . Nikeghbali.

4 4.8 CDS Day Counting Conventions General Valuation of Credit Default Swaps Hazard Rate Function Poisson and Cox Processes Valuation Using a Deterministic Intensity Model Hazard Rate Function Calibration Credit Curve Construction and Calibration 167 167 167 169 171 171 177 179 181 181 186 186 187 188 189 193 196 197 197 199 208 216 216 218 220 223 224 226 226 228 229 232 235 248 4.12 CDO Tranche Pricing Pricing Equation Simulation Algorithm CDO Pricing in Matlab CDO Pricing in C++ CDO2 Pricing Fast Loss Calculation for CDOs and CDO2 s Fast Algorithm for Computing CDO Tranche Loss in Matlab Endnotes 5 CREDIT DERIVATIVES 5.3 5.3 4.10 4.7 4.5 5.5 .9 4.7 5.6 5.8 4.2 5.1 Credit Default Swaps 5.Contents ix Arbitrage Cash Flow CDOs Credit Enhancement in Cash Flow Transactions Credit Enhancement in Market Value Transactions: Advance Rates and the Over-Collateralization Test Minimum Net Worth Test Transaction Characteristics 4.11 4.4 5.6 4.2 Synthetic CDOs Fully Funded Synthetic CDOs Partially and Unfunded Funded Synthetic CDOs Balance Sheet Management with CDS The Distribution of Default Losses on a Portfolio CDO Equity Tranche CDO Equity Tranche Performance The CDO Embedded Option The Price of Equity Using Moody’s Binomial Expansion Technique to Structure Synthetic CDOs Correlation Risk of CDO Tranches 4.

11 5.8 Historical Burn Analysis 6.9 5.12 Credit Basket Default Swaps Pricing Generation of Correlated Default Stopping Times Sampling from Elliptical Copulae The Distribution of Default Arrival Times Basket CDS Pricing Algorithm Credit Basket Pricing in Matlab Credit Basket Pricing in C++ Credit Linked Notes (CLNs) CLNs with Collateralized Loan or Bond Obligations (CLOs or CBOs) Pricing Tranched Credit Linked Notes Regulatory Capital Endnotes 249 250 250 252 252 255 264 291 295 296 296 297 299 300 303 303 306 308 309 310 310 311 312 312 313 316 318 328 330 333 334 336 336 337 340 341 342 6 WEATHER DERIVATIVES 6.4 Parameter Estimation 6.1 Weather Derivatives Market 6.10 Pricing Weather Options in C++ Endnotes 7 ENERGY AND POWER DERIVATIVES 7.6 Mean-Reversion Parameter Estimation 6.9 Time-Series Weather Forecasting 6.2 Weather Contracts CME Weather Futures 6.10 5.1 Electricity Markets 7.3 Modeling Temperature Noise Process Mean-Reversion 6.5 Volatility Estimation 6.x Contents 5.2 Electricity Pricing Models Modeling the Price Process One-Factor Model Estimating the Deterministic Component Estimation of the Stochastic Process for the One-Factor Models Two-Factor Model .7 Pricing Weather Derivatives Model Framework Pricing a Heating Degree Day Option 6.

13 7.Contents xi 7.6 7. Downswings.12 7.10 7.16 Swing Options The Longstaff-Schwartz Algorithm for American and Bermudan Options The LSM Algorithm Extension of Longstaff-Schwartz to Swing Options General Case: Upswings.8 7.4 7.14 7.11 7.3 7.15 7.9 7.5 7. and Penalty Functions Swing Option Pricing in Matlab LSM Simulation Results Upper and Lower Boundaries Exercise Strategies The Threshold of Early Exercise Interplay Between Early Exercise and Option Value Pricing of Energy Commodity Derivatives Cross-Commodity Spread Options Model 1 Model 2 Model 3 Jump Diffusion Pricing Models Model 1a: Affine Mean-Reverting Jump-Diffusion Process Model 1b Model 2a: Time-Varying Drift Component Model 2b: Time-Varying Version of Model 1b Stochastic Volatility Pricing Models Model 3a: Two-Factor Jump-Diffusion Affine Process with Stochastic Volatility Model Parameter Estimation ML-CCF Estimators ML-MCCF Estimators Spectral GMM Estimators Simulation Parameter Estimation in Matlab Energy Commodity Models Natural Gas Natural Gas Markets Natural Gas Spot Prices Gas Pricing Models One-Factor Model Two-Factor Model Calibration 344 345 346 348 351 352 352 354 356 358 360 362 362 364 365 366 368 368 369 370 372 372 372 373 375 376 379 383 385 385 387 387 389 390 390 391 393 .7 7.

6 Model Calibration 8.5 The PJ Model—Overview 8.4 Fundamentals-Based Models 8.9 Results 8.4 Commercial Real Estate-Backed Securitization (CREBS)—Singapore’s Experience 9.2 Motivations for Asset-Backed Securitization 9.xii Contents 7.8 Option Valuation Methodology Splitting the (Finite) Difference: Daily Strike and Monthly Strike Options Matlab Implementation for a Monthly Strike Option Spark Spread Options Matlab Implementation of Spark Spread Option Valuation 8.1 Introduction 9.3 Concepts of Securitizing Real Estate Cash Flows 9.18 One-Factor Model Calibration Two-Factor Model Calibration Natural Gas Pricing in Matlab Natural Gas and Electricity Swaps Generator End User Endnotes 393 394 398 398 400 401 402 8 PRICING POWER DERIVATIVES: THEORY AND MATLAB IMPLEMENTATION 8.7 Using the Calibrated Model to Price Options Daily Strike Options Monthly Strike Options Spark Spread Options 8.1 Introduction 8.10 Summary Endnotes References 9 COMMERCIAL REAL ESTATE ASSET-BACKED SECURITIES 9.2 Power Markets 8.3 Traditional Valuation Approaches Are Problematic for Power 8.17 7.5 Structure of a Typical CREBS A CREBS Case by Visor Limited 407 407 409 410 413 415 419 423 423 423 424 424 424 426 434 434 439 443 443 445 447 447 449 450 452 456 457 .

3 Black-Karasinski Trees in Matlab A.4 HJM Pricing in Matlab Description Syntax Arguments Examples Creating an HJM Volatility and Pricing Model A.8 9.10 Pricing of CREBS Swaps and Swaptions The Cash Flow Swap Structure for CREBS Valuation of CREBS Using a Swap Framework Basic Swap Valuation Framework Pricing of Credit Risks for CREBS Using the Proposed Swap Model Modeling Default Risks in the CREBS Swap Numerical Analysis of Default Risks for a Typical CREBS Monte Carlo Simulation Process Input Parameters Analysis of Results Matlab Code for the Numerical Analysis Summary Endnotes 459 459 459 460 460 461 461 463 463 464 465 467 470 470 473 473 478 486 490 492 493 493 493 494 497 500 501 503 543 555 A INTEREST RATE TREE MODELING IN MATLAB A.6 Two-Factor HJM Model Implementation in Matlab Endnotes B CHAPTER 7 CODE REFERENCES INDEX .5 Matlab Excel Link Example A.7 9.Contents xiii 9.9 9.2 Hull-White Trees in Matlab A.6 9.1 BDT Modeling in Matlab A.


C++. C++. Craig Pirrong. the implementation of these models in C++ and Matlab (two widely used languages for implementing and building derivatives models) has made programming skills in these languages important for practitioners to have. the use of Excel is also important as many trading desks use Excel as a front-end trading application. Examples using actual real-time Bloomberg data show how these models work in practice. The best way to learn is to follow the examples and run the code. The chapters cover the following topics: • Chapter 1: Swaps and fixed income securities • Chapter 2: Copulas and copula methodologies • Chapter 3: Mortgage-backed securities • Chapter 4: Collateralized-debt obligations • Chapter 5: Credit derivatives • Chapter 6: Weather derivatives • Chapter 7: Energy and power derivatives • Chapter 8: Also covers model implementations for energy derivatives using Matlab. The purpose of the book is to teach readers how to properly develop and implement derivatives applications so that they can adapt the code for their own use as they develop their own applications. professor of finance and director of the Global Energy Management Institute at the University of Houston. hundreds of financial institutions now market these complex instruments and employ thousands of financial and technical professionals needed to model them accurately and effectively. and Excel is the first book to cover in detail important derivatives pricing models for credit derivatives (for example. Modeling Derivatives Applications in Matlab. and Excel. fixed income securities. asset-backed securities (ABSs). xv . the theory underlying the models. In addition. and increasingly important weather. power. collateralized-debt obligations (CDOs). Moreover. as well as the code implementations. mortgagebacked securities (MBSs). credit default swaps and credit-linked notes). and Excel. swaps. C++.P REFACE Given the explosive growth in new financial derivatives such as credit derivatives. and energy derivatives using Matlab. Readers will benefit from both the mathematical derivations of the models. Throughout this book. numerous examples are given using Matlab. but is written and based on the proprietary work of its author.

professor in the Department of Real Estate Finance at the National University of Singapore. a matrix manipulation language. The work of Picone (2004) is discussed in the chapter on collateralized-debt obligations. but it also incorporates important work contributions from leading practitioners in the industry. a two-dimensional alternating implicit difference (ADI) finite difference scheme for pricing energy derivatives. Craig Pirrong discusses the Pirrong-Jermayakan model. the book does provide some discussions and helpful tips for building efficient models. although some two-dimensional arrays are used as well. the work of Galiani (2003) is discussed in the chapter on copulas and credit derivatives.ftpress. Tien-Foo Sing discusses using Monte Carlo to price asset-based securities. Tien-Foo Sing. memory allocation for data structures is always an issue when developing a model that requires use and storage of multi-dimensional data. trading. For instance. a single number is treated as a 1 x 1 array. The valuable work for energy derivatives of Doerr (2002).com/title/0131962590).) Efficiency and modularity are important design goals in building robust object-oriented code. for instance. and Xu (2004) is given. the predefined array sizes may turn out not to be large enough. and hedging using C++. However. e. For instance. Matlab.xvi Preface • Chapter 9: Commercial real-estate backed securities (a type of asset-backed security). In Chapter 8. which is written and is based on the proprietary work of its author. not only does this book cover complex derivatives models and provide all of the code (which can be downloaded using a secure ID code from the companion Web site at www. The work of Johnson (2004) is discussed in the chapters on fixed-income instruments and mortgage-backed securities. The emphasis throughout the book has been to provide working implementations for the reader to adapt. Moreover. Data can be added or removed from an object and the object will dynamically expand or reduce the amount of memory space as needed. is not the most efficient way to allocate memory since it is fixed in size. numerous individuals named in the acknowledgments contributed useful code throughout the book. and Excel. the C++ code provided could perhaps be more modular as with some of the routines in building interest rate trees. The book does not focus on design patterns or best coding practices (these issues may be discussed in subsequent editions of the book. . In some cases in this book. In Chapter 9. use of array template classes (that can handle multiple dimensions) and vectors (of vectors) in the Standard Template Library in C++ are more efficient because they are dynamic and only use as much memory as is needed. Matlab.. On the other hand. Thus. The book emphasizes how to implement and code complex models for pricing. provides automatic memory allocation of memory as data is used if no array sizes are predefined. the work and models developed and written by various leading practitioners and experts for certain topics are provided and incorporated throughout the book. In order to provide different perspectives to readers and provide as much useful information as possible.g. All data in Matlab are treated as matrix objects. A lot of memory may be unutilized and wasted if you do not know how large the structure needs to be to store the actual data. Xiang (2004). Such structures are used in the book. Use of a predefined two-dimensional array. Although two-dimensional arrays are easy to define.

ftpress. build. You will need a valid email address and the access code that is printed inside the envelope located at the back of the book. Any corrections will be posted on the Web site. All rights reserved. If you have any questions about online registration or downloading the code. SUPPLEMENTAL F ILES ON THE W EB SITE To download the code in this and follow the on-screen instructions.Preface xvii While every effort has been made to catch all typos and errors in the book. To register online. you must first register online.ftpress. go to www. inevitably in a book of this length and complexity. please send us an inquiry via the Contact Us page at http://www. NOTE: The code files are Copyrighted © 2006 by Justin London and the contributors thereof. Unauthorized reproduction or distribution is prohibited. there may still be a few. this book will give you the foundation to develop. Hopefully. .com/about/contact us/. and test your own models while saving you a great deal of development time through use of pre-tested robust code.


ACKNOWLEDGMENTS Special thanks to the following people for their code and work contributions to this book: Ahsan Amin Sean Campbell Francis Diebold Uwe Doerr Stefano Galiani Michael Gibson Stafford Johnson Jochen Meyer Dominic Picone Craig Pirrong Eduardo Schwartz Tien Foo Sing Liuren Wu Lei Xiong James Xu xix .


He has analyzed and managed bank corporate loan portfolios using credit derivatives in the Asset Portfolio Group of a large bank in Chicago.A.A BOUT THE AUTHOR Justin London has developed fixed-income and equity models for trading companies and his own quantitative consulting firm. respectively.S. and mathematics.A. computer science. xxi . in applied economics. and an M. A graduate of the University of Michigan. London is the founder of a global online trading and financial technology company. in economics and mathematics. in financial engineering. an M. as well as advised several banks in their implementation of derivative trading systems. Illinois. London holds a B.

Sign up to vote on this title
UsefulNot useful