ebook img

Financial Modelling in Python (The Wiley Finance Series) PDF

246 Pages·2009·3.71 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 Financial Modelling in Python (The Wiley Finance Series)

Financial Modelling in Python ForothertitlesintheWileyFinanceSeries pleaseseewww.wiley.com/financ Financial Modelling in Python S. Fletcher & C. Gardner A John Wiley and Sons, Ltd., Publication Disclaimer: This eBook does not include ancillary media that was packaged with the printed version of the book. Thiseditionfirs published2009 (cid:1)C 2009JohnWiley&SonsLtd Registeredoffic JohnWiley&SonsLtd,TheAtrium,SouthernGate,Chichester,WestSussex,PO198SQ,UnitedKingdom Fordetailsofourglobaleditorialoffices forcustomerservicesandforinformationabouthowtoapplyfor permission to reuse the copyright material in this book please see our website at www.wiley.com. Therightoftheauthortobeidentifie astheauthorofthisworkhasbeenassertedinaccordancewiththe Copyright,DesignsandPatentsAct1988. Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,in anyformorbyanymeans,electronic,mechanical,photocopying,recordingorotherwise,exceptaspermittedbythe UKCopyright,DesignsandPatentsAct1988,withoutthepriorpermissionofthepublisher. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmaynotbe availableinelectronicbooks. Designationsusedbycompaniestodistinguishtheirproductsareoftenclaimedastrademarks.Allbrandnamesand productnamesusedinthisbookaretradenames,servicemarks,trademarksorregisteredtrademarksoftheir respectiveowners.Thepublisherisnotassociatedwithanyproductorvendormentionedinthisbook.This publicationisdesignedtoprovideaccurateandauthoritativeinformationinregardtothesubjectmattercovered.It issoldontheunderstandingthatthepublisherisnotengagedinrenderingprofessionalservices.Ifprofessional adviceorotherexpertassistanceisrequired,theservicesofacompetentprofessionalshouldbesought. LibraryofCongressCataloging-in-PublicationData Fletcher,Shayne. FinancialmodelinginPython/ShayneFletcherandChristopherGardner. p.cm.—(Wileyfinanc series) Includesbibliographicalreferencesandindex. ISBN978-0-470-98784-1(cloth:alk.paper) 1.Finance—Mathematicalmodels—Computerprograms. 2.Python(Computerprogramlanguage) I.Gardner,Christopher. II.Title. HG106.F592009 (cid:2) 332.02855133—dc22 2009019336 ISBN 978-0-470-98784-1 AcataloguerecordforthisbookisavailablefromtheBritishLibrary. Typesetin10/12ptTimesbyAptaraInc.,NewDelhi,India PrintedinGreatBritainbyAntonyRoweLtd,Chippenham,Wiltshire Contents 1 WelcometoPython 1 1.1 WhyPython? 1 1.1.1 Pythonisageneral-purposehigh-levelprogramminglanguage 1 1.1.2 Pythonintegrateswellwithdataanalysis,visualisationand GUItoolkits 2 1.1.3 Python‘playswellwithothers’ 2 1.2 CommonmisconceptionsaboutPython 2 1.3 Roadmapforthisbook 3 2 ThePPFPackage 5 2.1 PPFtopology 5 2.2 Unittesting 6 2.2.1 doctest 6 2.2.2 PyUnit 7 2.3 BuildingandinstallingPPF 7 2.3.1 Prerequisitesanddependencies 7 2.3.2 BuildingtheC++extensionmodules 8 2.3.3 InstallingthePPFpackage 9 2.3.4 TestingaPPFinstallation 9 3 ExtendingPythonfromC++ 11 3.1 Boost.Date Timetypes 11 3.1.1 Examples 12 3.2 Boost.MultiArrayandspecialfunctions 17 3.3 NumPyarrays 19 3.3.1 AccessingarraydatainC++ 19 3.3.2 Examples 23 4 BasicMathematicalTools 27 4.1 Randomnumbergeneration 27 4.2 N(.) 28 4.3 Interpolation 29 4.3.1 Linearinterpolation 31 vi Contents 4.3.2 Loglinearinterpolation 32 4.3.3 Linearonzerointerpolation 32 4.3.4 Cubicsplineinterpolation 33 4.4 Rootfindin 35 4.4.1 Bisectionmethod 35 4.4.2 Newton–Raphsonmethod 36 4.5 Linearalgebra 38 4.5.1 Matrixmultiplication 38 4.5.2 Matrixinversion 38 4.5.3 Matrixpseudo-inverse 39 4.5.4 Solvinglinearsystems 39 4.5.5 Solvingtridiagonalsystems 39 4.5.6 Solvingupperdiagonalsystems 40 4.5.7 Singularvaluedecomposition 42 4.6 Generalisedlinearleastsquares 44 4.7 Quadraticandcubicroots 46 4.8 Integration 49 4.8.1 Piecewiseconstantpolynomialfittin 49 4.8.2 Piecewisepolynomialintegration 51 4.8.3 Semi-analyticconditionalexpectations 57 5 Market:CurvesandSurfaces 63 5.1 Curves 63 5.2 Surfaces 64 5.3 Environment 65 6 DataModel 69 6.1 Observables 69 6.1.1 LIBOR 70 6.1.2 Swaprate 74 6.2 Flows 79 6.3 Adjuvants 82 6.4 Legs 84 6.5 Exercises 85 6.6 Trades 87 6.7 Tradeutilities 88 7 Timeline:EventsandController 93 7.1 Events 93 7.2 Timeline 94 7.3 Controller 97 8 TheHull–WhiteModel 99 8.1 Acomponent-baseddesign 99 8.1.1 Requestor 100 8.1.2 State 101 8.1.3 Filler 104 Contents vii 8.1.4 Rollback 108 8.1.5 Evolve 112 8.1.6 Exercise 115 8.2 Themodelandmodelfactories 118 8.3 Concludingremarks 121 9 PricingusingNumericalMethods 123 9.1 Alatticepricingframework 123 9.2 AMonte-Carlopricingframework 128 9.2.1 Pricingnon-callabletrades 129 9.2.2 Pricingcallabletrades 131 9.3 Concludingremarks 142 10 PricingFinancialStructuresinHull–White 145 10.1 PricingaBermudan 145 10.2 PricingaTARN 152 10.3 Concludingremarks 157 11 HybridPython/C++PricingSystems 159 11.1 nth imm of yearrevisited 159 11.2 Exercisingnth imm of yearfromC++ 161 12 PythonExcelIntegration 165 12.1 Black–scholesCOMserver 165 12.1.1 VBSclient 167 12.1.2 VBAclient 167 12.2 NumericalpricingwithPPFinExcel 168 12.2.1 Commonutilities 168 12.2.2 Marketserver 169 12.2.3 Tradeserver 176 12.2.4 Pricerserver 187 Appendices 191 A Python 193 A.1 Pythoninterpretermodes 193 A.1.1 Interactivemode 193 A.1.2 Batchmode 193 A.2 BasicPython 194 A.2.1 Simpleexpressions 194 A.2.2 Built-indatatypes 195 A.2.3 Controlfl wstatements 197 A.2.4 Functions 200 A.2.5 Classes 201 A.2.6 Modulesandpackages 203 A.3 Conclusion 205 viii Contents B Boost.Python 207 B.1 Helloworld 207 B.2 Classes,constructorsandmethods 207 B.3 Inheritance 209 B.4 Pythonoperators 212 B.5 Functions 212 B.6 Enums 214 B.7 Embedding 214 B.8 Conclusion 216 C Hull–WhiteModelMathematics 217 D PickupValueRegression 219 Bibliography 221 Index 223

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.