ebook img

Computational finance using C and C# PDF

372 Pages·2008·1.504 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computational finance using C and C#

Computational Finance Using C and C# George Levy AMSTERDAM•BOSTON•HEIDELBERG•LONDON•NEWYORK OXFORD•PARIS•SANDIEGO•SANFRANCISCO•SINGAPORE SYDNEY•TOKYO AcademicPressisanimprintofElsevier CoverimagecourtesyofiStockphoto AcademicPressisanimprintofElsevier 30CorporateDrive,Suite400,Burlington,MA01803,USA 525BStreet,Suite1900,SanDiego,California92101-4495,USA 84Theobald’sRoad,LondonWC1X8RR,UK Copyright©2008,ElsevierLtd.Allrightsreserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopy, recording, or any information storageandretrievalsystem,withoutpermissioninwritingfromthepublisher. PermissionsmaybesoughtdirectlyfromElsevier’sScience&TechnologyRights DepartmentinOxford,UK:phone:(+44)1865843830,fax:(+44)1865853333, E-mail:[email protected] viatheElsevierhomepage(http://elsevier.com),byselecting“Support&Contact” then“CopyrightandPermission”andthen“ObtainingPermissions.” LibraryofCongressCataloging-in-PublicationData Levy,George. ComputationalFinanceUsingCandC#/GeorgeLevy. p.cm.–(Quantitativefinance) Includesbibliographicalreferencesandindex. ISBN-13:978-0-7506-6919-1(alk.paper)1.Finance-Mathematicalmodels.I.Title. HG106.L4842008 332.0285’5133-dc22 2008000470 BritishLibraryCataloguing-in-PublicationData AcataloguerecordforthisbookisavailablefromtheBritishLibrary. ForinformationonallAcademicPresspublications visitourWebsiteatwww.books.elsevier.com PrintedintheUnitedStatesofAmerica 08 09 10 11 9 8 7 6 5 4 3 2 1 Contents 1 Overviewoffinancialderivatives 1 2 Introductiontostochasticprocesses 5 2.1 Brownianmotion 5 2.2 ABrownianmodelofassetpricemovements 9 2.3 Ito’sformula(orlemma) 10 2.4 Girsanov’stheorem 12 2.5 Ito’slemmaformultiassetgeometricBrownianmotion 13 2.6 Itoproductandquotientrulesintwodimensions 15 2.7 Itoproductinndimensions 18 2.8 TheBrownianbridge 19 2.9 Time-transformedBrownianmotion 21 2.10 Ornstein–Uhlenbeckprocess 24 2.11 TheOrnstein–Uhlenbeckbridge 27 2.12 Otherusefulresults 31 2.13 Selectedproblems 33 3 Generationofrandomvariates 37 3.1 Introduction 37 3.2 Pseudo-randomandquasi-randomsequences 38 3.3 Generationofmultivariatedistributions:independentvariates 41 3.4 Generationofmultivariatedistributions:correlatedvariates 47 4 Europeanoptions 59 4.1 Introduction 59 4.2 Pricingderivativesusingamartingalemeasure 59 4.3 Putcallparity 60 4.4 VanillaoptionsandtheBlack–Scholesmodel 62 4.5 Barrieroptions 85 5 SingleassetAmericanoptions 97 5.1 Introduction 97 5.2 ApproximationsforvanillaAmericanoptions 97 5.3 Latticemethodsforvanillaoptions 114 5.4 Gridmethodsforvanillaoptions 135 5.5 PricingAmericanoptionsusingastochasticlattice 172 6 Multiassetoptions 181 6.1 Introduction 181 6.2 ThemultiassetBlack–Scholesequation 181 6.3 MultidimensionalMonteCarlomethods 183 6.4 Introductiontomultidimensionallatticemethods 185 6.5 Twoassetoptions 190 6.6 Threeassetoptions 201 6.7 Fourassetoptions 205 7 Otherfinancialderivatives 209 7.1 Introduction 209 7.2 Interestratederivatives 209 7.3 Foreignexchangederivatives 228 7.4 Creditderivatives 232 7.5 Equityderivatives 237 8 C#portfoliopricingapplication 245 8.1 Introduction 245 8.2 Storingandretrievingthemarketdata 254 8.3 ThePricingUtilsclassandtheAnalytics_MathLib 262 8.4 Equitydealclasses 267 8.5 FXdealclasses 280 AppendixA: TheGreeksforvanillaEuropeanoptions 289 A.1 Introduction 289 A.2 Gamma 290 A.3 Delta 291 A.4 Theta 292 A.5 Rho 293 A.6 Vega 294 AppendixB: Barrieroptionintegrals 295 B.1 Thedownandoutcall 295 B.2 Theupandoutcall 298 AppendixC: Standardstatisticalresults 303 C.1 Thelawoflargenumbers 303 C.2 Thecentrallimittheorem 303 C.3 Thevarianceandcovarianceofrandomvariables 305 C.4 Conditionalmeanandcovarianceofnormaldistributions 310 C.5 Momentgeneratingfunctions 311 AppendixD: Statisticaldistributionfunctions 313 D.1 Thenormal(Gaussian)distribution 313 D.2 Thelognormaldistribution 315 D.3 TheStudent’st distribution 317 D.4 Thegeneralerrordistribution 319 AppendixE: Mathematicalreference 321 E.1 Standardintegrals 321 E.2 Gammafunction 321 E.3 Thecumulativenormaldistributionfunction 322 E.4 Arithmeticandgeometricprogressions 323 AppendixF: Black–Scholesfinite-differenceschemes 325 F.1 Thegeneralcase 325 F.2 Thelogtransformationandauniformgrid 325 AppendixG: TheBrownianbridge:alternativederivation 329 AppendixH: Brownianmotion:moreresults 333 H.1 SomeresultsconcerningBrownianmotion 333 H.2 ProofofEq.(H.1.2) 334 H.3 ProofofEq.(H.1.4) 335 H.4 ProofofEq.(H.1.5) 335 H.5 ProofofEq.(H.1.6) 335 H.6 ProofofEq.(H.1.7) 338 H.7 ProofofEq.(H.1.8) 338 H.8 ProofofEq.(H.1.9) 338 H.9 ProofofEq.(H.1.10) 339 AppendixI: TheFeynman–Kacformula 341 AppendixJ: Answerstoproblems 343 J.1 Problem1 343 J.2 Problem2 344 J.3 Problem3 345 J.4 Problem4 346 J.5 Problem5 346 J.6 Problem6 347 J.7 Problem7 348 J.8 Problem8 350 J.9 Problem9 350 J.10 Problem10 352 J.11 Problem11 354 References 355 Index 361 1 Overview of financial derivatives A financial derivative is a contract between two counterparties (here referred to as A and B) which derives its value from the state of underlying financial quantities.Wecanfurtherdividederivativesintothosethatcarryafutureoblig- ation and those that don’t. In the financial world a derivative which gives the ownertherightbutnottheobligationtoparticipateinagivenfinancialcontract is called an option. We will now illustrate this using both a Foreign Exchange ForwardcontractandaForeignExchangeoption. Foreign Exchange Forward—a contract with an obligation In a Foreign Exchange Forward contract a certain amount of foreign currency will be bought (or sold) at a future date using a prearranged foreign exchange rate. For instance, counterparty A may own a Foreign Exchange Forward which, inoneyear’stime,contractuallyobligesAtopurchasefromB thesumof$200 for£100.Attheendofoneyearseveralthingsmayhavehappened. (i) Thevalueofthepoundmayhavedecreasedwithrespecttothedollar (ii) Thevalueofthepoundmayhaveincreasedwithrespecttothedollar (iii) CounterpartyB mayrefusetohonorthecontract—B mayhavegonebust, etc. (iv) CounterpartyAmayrefusetohonorthecontract—Amayhavegonebust, etc. Wewillnowconsiderevents(i)–(iv)fromA’sperspective. Firstly,if(i)occursthenAwillbeabletoobtain$200forlessthanthecurrent market rate, say £120. In this case the $200 can be bought for £100 and then immediatelysoldfor£120,givingaprofitof£20.However,thisprofitcanonly berealizedifB honorsthecontract—thatis,event(iii)doesnothappen. Secondly, when (ii) occurs then A is obliged to purchase $200 for more than thecurrentmarketrate,say£90.Inthiscasethe$200areboughtfor£100but couldhavebeenboughtforonly£90,givingalossof£10. Theprobabilityofevents(iii)and(iv)occurringarerelatedtotheCreditRisk associated with counterparty B. The value of the contract to A is not affected by (iv), although A may be sued if both (ii) and (iv) occur. Counterparty A shouldonlybeconcernedwiththepossibilityofevents(i)and(iii)occurring— thatis,theprobabilitythatthecontractisworthapositiveamountinoneyear 2 ComputationalFinanceUsingCandC# and the probability that B will honor the contract (which is one minus the probabilitythatevent(iii)willhappen). From B’s point of view the important Credit Risk is when both (ii) and (iv) occur—thatis,whenthecontracthaspositivevaluebutcounterpartyAdefaults. Foreign Exchange option—a contract without an obligation A Foreign Exchange option is similar to the Foreign Exchange Forward, the difference being that if event (ii) occurs then A is not obliged to buy dollars at an unfavorable exchange rate. To have this flexibility A needs to buy a For- eignExchangeoptionfromB,whichherecanberegardedasinsuranceagainst unexpectedexchangeratefluctuations. For instance, counterparty A may own a Foreign Exchange option which, in oneyear,contractuallyallowsAtopurchasefromB thesumof$200for£100. Asbefore,attheendofoneyearthefollowingmayhavehappened: (i) Thevalueofthepoundmayhavedecreasedwithrespecttothedollar (ii) Thevalueofthepoundmayhaveincreasedwithrespecttothedollar (iii) CounterpartyB mayrefusetohonorthecontract—B mayhavegonebust, etc. (iv) CounterpartyAmayhavegonebust,etc. Wewillnowconsiderevents(i)–(iv)fromA’sperspective. Firstly,if(i)occursthenAwillbeabletoobtain$200forlessthanthecurrent market rate, say £120. In this case the $200 can be bought for £100 and then immediatelysoldfor£120,givingaprofitof£20.However,thisprofitcanonly berealizedifB honorsthecontract—thatis,event(iii)doesnothappen. Secondly, when (ii) occurs then A will decide not to purchase $200 for more thanthecurrentmarketrate;inthiscasetheoptionisworthless. We can thus see that A is still concerned with the Credit Risk when events (i)and(iii)occursimultaneously. The Credit Risk from counterparty B’s point of view is different. B has sold to A a Foreign Exchange option, which matures in one year, and has already received the money—the current fair price for the option. Counterparty B has no Credit Risk associated with A. This is because if event (iv) occurs, and A goes bust, it doesn’t matter to B since the money for the option has already been received. On the other hand, if event (iii) occurs B may be sued by A but B stillhasnoCreditRiskassociatedwithA. This book considers the valuation of financial derivatives that carry obliga- tionsandalsofinancialoptions. Chapters 1–7 deal with both the theory of stochastic processes and the pric- ing of financial instruments. In Chapter 8 this information is then applied to a C# portfolio valuer. The application is easy to use (the portfolios and current market rates are defined in text files) and can also be extended to include new tradetypes. Overviewoffinancialderivatives 3 The book has been written so that (as far as possible) financial mathematics resultsarederivedfromfirstprinciples. Finally, the appendices contain various information, which we hope the readerwillfinduseful. 2 Introduction to stochastic processes 2.1 Brownian motion BrownianmotionisnamedafterthebotanistRobertBrownwhousedamicro- scopetostudythefertilizationmechanismoffloweringplants.Hefirstobserved the random motion of pollen particles (obtained from the American species Clarkiapulchella)suspendedinwater,andwrote: Thefovillaorgranulesfillthewholeorbiculardiskbutdonotextendtothe projectingangles.Theyarenotsphaericalbutoblongornearlycylindrical, and the particles have manifest motion. This motion is only visible to my lenswhichmagnifies370times.Themotionisobscureyetcertain... RobertBrown,12thJune1827;seeRamsbottom(1932) ItappearsthatBrownconsideredthismotionnomorethanacuriosity(hebe- lieved that the particles were alive) and continued undistracted with his botan- ical research. The full significance of his observations only became apparent about eighty years later when it was shown (Einstein, 1905) that the motion is caused by the collisions that occur between the pollen grains and the water molecules. In 1908 Perrin (1909) was finally able to confirm Einstein’s predic- tions experimentally. His work was made possible by the development of the ultramicroscopebyRichardZsigmondyandHenrySiedentopfin1903.Hewas able to work out from his experimental results and Einstein’s formula the size of the water molecule and a precise value for Avogadro’s number. His work established the physical theory of Brownian motion and ended the skepticism abouttheexistenceofatomsandmoleculesasactualphysicalentities.Manyof the fundamental properties of Brownian motion were discovered by Paul Levy (Levy, 1939, 1948), and the first mathematically rigorous treatment was pro- vided by Norbert Wiener (Wiener, 1923, 1924). Karatzas and Shreve (1991) is an excellent textbook on the theoretical properties of Brownian motion, while Shreve,Chalasani,andJha(1997)providesmuchusefulinformationconcerning theuseofBrownianprocesseswithinfinance. Brownian motion is also called a random walk, a Wiener process, or some- times(morepoetically)thedrunkard’swalk.Wewillnowpresentthethreefun- damentalpropertiesofBrownianmotion. 6 ComputationalFinanceUsingCandC# 2.1.1 The properties of Brownian motion In formal terms a process W = (W :t (cid:2) 0) is (one-dimensional) Brownian t motionif: (i) W iscontinuous,andW =0, t 0 (ii) W ∼N(0,t), t (iii) TheincrementdWt =Wt+dt−Wt isnormallydistributedasdWt ∼N(0,dt), soE[dW ] = 0andVar[dW ] = dt.TheincrementdW isalsoindependent t t t ofthehistoryoftheprocessuptotimet. From(iii)wecanfurtherstatethat,sincetheincrementsdW areindependent t ofpastvaluesW ,aBrownianprocessisalsoaMarkovprocess.Inadditionwe t shallnowshowthataBrownianprocessisalsoamartingaleprocess. In a martingale process Pt,t (cid:2) 0, the conditional expectation E[Pt+dt|Ft] = P , where F is called the filtration generated by the process and contains the t t information learned by observing the process up to time t. Since for Brownian motionwehave (cid:2) (cid:3) E[Wt+dt|Ft]=E (Wt+dt −Wt)+Wt|Ft =E[Wt+dt −Wt]+Wt =E[dW ]+W =W t t t where we have used the fact that E[dWt] =0. Since E[Wt+dt|Ft] = Wt the BrownianmotionW isamartingaleprocess. Using property (iii) we can also derive an expression for the covariance of Brownian motion. The independent increment requirement means that for the ntimes0 (cid:3)t < t < t <··· < t <∞therandomvariablesW −W ,W − 0 1 2 n t1 t0 t2 W ,...,W −W areindependent.So t1 tn tn−1 Cov[W −W ,W −W ]=0, i (cid:4)=j (2.1.1) ti ti−1 tj tj−1 WewillshowthatCov[W ,W ]=s ∧t. s t Proof. UsingW =0,andassumingt (cid:2)s wehave t0 (cid:2) (cid:3) Cov[W −W ,W −W ]=Cov[W ,W ]=Cov W ,W +(W −W ) s t0 t t0 s t s s t s FromAppendixC.3.2wehave (cid:2) (cid:3) Cov W ,W +(W −W ) =Cov[W ,W ]+Cov[W ,W −W ] s s t s s s s t s =Var[W ]+Cov[W ,W −W ] s s t s Therefore Cov[W ,W ]=s +Cov[W ,W −W ] s t s t s Now Cov[W ,W −W ]=Cov[W −W ,W −W ]=0 s t s s t0 t s wherewehaveusedEq.(2.1.1)withn=2,t =s andt =t. 1 2

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.