Generic Monte Carlo Engine for Numerical Calculations within Front ARENA Christer Olofsson TRITA-NA-E05126 Numerisk analys och datalogi Department of Numerical Analysis KTH and Computer Science 100 44 Stockholm Royal Institute of Technology SE-100 44 Stockholm, Sweden Generic Monte Carlo Engine for Numerical Calculations within Front ARENA Christer Olofsson TRITA-NA-E05126 Master’s Thesis in Computer Science (20 credits) within the First Degree Programme in Mathematics and Computer Science, Stockholm University 2005 Supervisor at Nada was Karl Meinke Examiner was Stefan Arnborg Abstract This report covers a (cid:28)rst implementation of a general Monte Carlo engine, within Front ARENA (PRIME client). The engine was developed to be powerful enough to price the derivatives Asian, Barrier, Asian basket, Barrier basket and Altiplano. The engine ended up powerful enough to de(cid:28)ne a valuation function for a coplex derivative issued by one of the major investment banks in just a couple of working hours. In spite of the (cid:29)exibility the performance ended up much better than expected. In the worst comparative test the engine was just a constant factor of 1:4 times slower than the speci(cid:28)c standard C++ implementation performed. The approach for the project has been to create a Python domain speci(cid:28)c language, power boosted by a C++ engine. The report describes how this has been done and what the positive and negative sides have been with such an approach. Generell Monte Carlo-motor f(cid:246)r (cid:28)nansiella ber(cid:228)kningar i Front ARENA Sammanfattning Den h(cid:228)r rapporten t(cid:228)cker en f(cid:246)rsta implementation av en generell Monte Carlo- motor i Front ARENA (PRIME-klienten). Motorn utvecklades till att vara tillr(cid:228)ck- ligt kraftfull f(cid:246)r att priss(cid:228)tta derivaten Asiat, Barri(cid:228)r, Asiat basket, Barri(cid:228)r basket samt Altiplano. Den slutliga implementationen visade sig vara tillr(cid:228)ckligt kraftfull att p(cid:229) bara ett par arbetstimmar skapa en v(cid:228)rderingsfunktion f(cid:246)r en av v(cid:228)rldens st(cid:246)rsta bankers mest komplexa derivat. Trots (cid:29)exibiliteten s(cid:229) visade sig prestanda vara betydligt b(cid:228)ttre (cid:228)n v(cid:228)ntat. I det s(cid:228)msta j(cid:228)mf(cid:246)relsetestet var motorn endast 1;4 g(cid:229)nger l(cid:229)ngsammare (cid:228)n en speci(cid:28)k standard C++implementation. M(cid:229)let f(cid:246)r projektet har varit att skapa ett Python-baserat dom(cid:228)nspeci(cid:28)kt spr(cid:229)k, med en C++motor f(cid:246)r (cid:246)kad prestanda. Rapporten t(cid:228)cker hur detta gjordes och vad de positiva och negativa sidorna har varit med ett s(cid:229)dant angreppss(cid:228)tt. Contents 1 Acknowledgement 1 2 Background and purpose 2 2.1 Statement of problem . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Goals of the project . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3 Theory 6 3.1 Financial background . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Monte Carlo simulations . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2.1 Formal de(cid:28)nition . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2.2 Path simulations . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2.3 Optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4 Implementation 12 4.1 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.2 End-User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.4 Re-engineering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.5 Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.5.1 Asian Option . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.5.2 Barrier Option . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.5.3 Basket Options . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.5.4 Altiplano Opton . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.6 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.7 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.7.1 Python based domain speci(cid:28)c language. . . . . . . . . . . . . 17 4.7.2 Monte Carlo engine and Math library . . . . . . . . . . . . . 18 4.7.3 Sequence diagram . . . . . . . . . . . . . . . . . . . . . . . . 20 5 Results 21 5.1 Language de(cid:28)nition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.1.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.2 Payo(cid:27) functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.2.1 Vanilla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.2.2 Asian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.2.3 Barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.2.4 Vanilla basket . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.2.5 Asian basket . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5.2.6 Barrier basket, down and out . . . . . . . . . . . . . . . . . . 26 5.2.7 Altiplano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.3 Test simulations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.3.1 Vanilla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 5.3.2 Asian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.3.3 Barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.3.4 Vanilla basket . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.3.5 Asian basket . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 5.3.6 Barrier basket, down and out . . . . . . . . . . . . . . . . . . 33 5.3.7 Altiplano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6 Discussion 35 6.1 Usability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 6.2 Domain speci(cid:28)c language . . . . . . . . . . . . . . . . . . . . . . . . 36 6.3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 6.4 Future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 6.5 Project plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 6.6 Re-engineering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 References 39 Chapter 1 Acknowledgement To write a report is not only due to the author himself/herself. It is equally im- portant that the author is in a prosperous and encouraging environment. This has become evident to me during the writing of this report. I am truly grateful to my environment, and want to give special tanks to: Professor Karl Meinke, who has not only been my tutor, but also been like a mentor to me who guided and helped me into interesting areas. Daniel Roos,my tutor at Front Capital System. Hehaswith a positive attitude and wide knowledge been an inspiring tutor. Front Capital System, a perfectly stimulating and fun company to be at. 1 Chapter 2 Background and purpose The aim for this project is to build a general Monte Carlo engine within Front ARENA for (cid:28)nancial calculations. Monte Carlo is a probabilistic algorithm that is widely used within the (cid:28)nancial industry for (cid:28)nd theoretical prices and risks for derivatives. It is frequently used in the following (cid:28)elds within the industry: (cid:136) Hard to value instruments. (cid:136) Value at risk calculations. (cid:136) Interest rate models, LMM. (cid:136) Credit risk. Hard to value instruments are derivatives for which there does not exist any other method than Monte Carlo simulation to decide their theoretical price. Value at risk calculations are the prospect of (cid:28)nancial losses or gains due to unex- pected changes in rates and market prices. Interest rate derivatives are more structured and complex than ordinary equity de- rivatives, which is what makes them really interesting. Many models as for example the LIBOR Market Model (LMM) are based on the Monte Carlo method. Credit risk is the risk that an issuer of debt securities or a borrower may default on its obligations, or that the payment may not be made on a negotiable instrument. 2 2.1 Statement of problem Monte Carlo (MC) is categorised as a (cid:16)simple to implement method(cid:17) with heavy computational costs. Traditionally MC is implemented in C/C++ within Front ARENA for performance, an approach that demands knowledge in C/C++, recom- pilation and restart costs of Front ARENA, crash bugs and integration layers. This in combination of constant innovation in marketplace, leading to fast turnaround times, makes it tempting to build a user-de(cid:28)ned Monte Carlo engine. The user-de(cid:28)ned idea is to allow the user to de(cid:28)ne payo(cid:27) functions in a simple domain speci(cid:28)c language within Front ARENA. This could for example look as such: pv = max(max(S1-K,0),max(S2-K,0)) This approach has the potential to meet up to the fast turnaround times, get rid of the recompilations/restarts, be easier than C/C++, decrease developing time and decrease bugs. Thiskindofuser-de(cid:28)nedapproaches arestartingtocomeupatcompetitorstoFront and some of their customers. 3 2.2 Goals of the project Thegoalfortheprojectwastocreateauser-de(cid:28)nedMCenginewithinFrontARENA (PRIMEclient) withequityfocus,within theBlackandScholes world. Itwasstated that the project should: (cid:136) De(cid:28)ne a domain speci(cid:28)c language for payo(cid:27) functions within Front ARENA, that covers a very broad range of current instrument and future instruments. Five derivatives were chosen that were not to similar and not so di(cid:27)erent in corporation with Front Capital System: Asian, Barrier, Asian basket, Barrier basket and Altiplano. (cid:136) Implement a C++ MC engine for performance. (cid:136) Expose quality tested building blocks as MC library. (cid:136) Allowing all parameters and the valuation code for one instrument to be in a single Python module. (cid:136) Develop a method with su(cid:30)cient performance: worst case comparison test shall not be slower than 10 times but preferably not more than 5 times slower. We here present (cid:28)gure 2.1 and 2.2 to give a better view of what the project aims for. Figure 2.1. Screen shot of Front ARENA PRIME client main window. An AEL editorisopened,inordertoeditthede(cid:28)nitionofpayo(cid:27)functioncalledmc-test-asian. 4
Description: