170 likes | 173 Views
Learn how to benefit from parallelism in the Price-It Library by extracting low-level and high-level parallelism. Discover the use of OpenMP for low-level parallelism and the parallelization of Greek calculations for high-level parallelism.
E N D
Extracting parallelism in Price-It Library Pricing Partners
Outline • The C++ Price-It library • Short description • Parallelism ? • Low-level parallelism: Multicore using OpenMP • High-level parallelism: Sensitivities with ProActive
The C++ Price-It Library • Core Library of all Pricing Partners Product • Originally written for Price-It Excel, the Pricing Partners financial addin for Microsoft Excel • Used in Price-It for Summit and in Price-It Online and as an internal tool for Independent Valuation • Written in C++ • Originally written for Microsoft compiler • Has been ported to Sun Solaris • JNI, COM interfaces for easy integration • Unfortunately not conceived as thread safe
How to benefit from parallelism ? • Well known industry fact • Moore’s Law will be sustained through multicore • « Free Lunch » is over • Upgrading the entire code base to thread-safe is very costly • Is there any easier (and cheaper) alternatives to extract parallelism from Price-it Library ?
How to benefit from parallelism ? – 2 • To benefit from parallelism we need to find parts of code that can run independently • Low-level for and while loop can easily be made independent • High-level independent calculation such as Greeks (sensitivities) can also be parallelized at a low cost.
Low-level Parallelism with OpenMP • Description • Set of standardized compiler directives to extract parallelism at the for/while loop level • Designed to use multiple core and/or processor on a single machine • Not vendor-specific • How we used it • Find a low-level loop bottleneck using a profiler • Make the loop code thread safe (easy as it is low-level code) • Add a few #pragma omp to the C++ source code • Does not alter source code as the directives can be turned with a global switch
Low-level Parallelism with OpenMP – Limits • No parallelism across machinesLimited to the number of cores available on the workstation • Only for the inner loops of the codeLimited speed-up
High-level Parallelism • In quantitative pricing a common high-level parallelism with mostly independent jobs is Greeks Calculation • Computing derivatives of the Price with the regard to various parameters: • The underlying price (the stock price or the interest rates curve) • Volatility • Correlation
Greeks • P is the price of a product • dP/dx where x can be • Underlying value • Delta -> 1st order derivative • Gamma -> 2nd order derivative • Gamma cross -> multi-asset product : cross derivative • Interest rate -> theta • Underlying volatility -> vega
Greeks – 2 • Differentiation will be numerical not analytical • 1st order derivative • 2nd order derivative • There can be up to 4 prices to compute for a single derivative value • Derivation is often done with regard to a curve
Differentiation with regard to curves • Different ways to shift data curves • Many price calculations in perturbative and cumulative shift modes
Representing a price computation • A Price-It computation can be seen as a tree of function calls • The tree of function calls can be serialized as an XML stream
Distributing Calculations • Preprocessing • « Differentiating » the XML pricing calls, i.e. shifting some of the inputs • Distribution • Sending all those pricing requests to workers • Have them perform the calculation • Wait for the result • Postprocessing • « Calculating »
Implementation using interprocess commuication • A first implementation: custom-developed grid middleware in C# -> not maintainable • A proof of concept very simple implementation was then made using Boost C++ thread and interprocess shared memory libraries • Limited to a single machine • Manual launching of the worker, no error recovery • Reference implementation that was the base of the joint ActiveEon / Pricing Partners work
Pricing Partners-ActiveEon joint work Excel and Price-it DLL (C/C++) ProActive Scheduler (Java) ProActive Worker (Java) ProActive Worker (Java) ProActive Worker (Java) Price-it computation DLL (C++) Price-it computation DLL (C++) Price-it computation DLL (C++)
Conclusion • Various ways to easily leverage parallelism in a large existing code base designed without parallelism in mind • Collaboration started 1 month ago • Most of the time spent building a C++/JNI bridge to integrate the ProActive scheduler and workers with Price-it DLL • Final tests needed before an estimated production-ready version in December ’08 • Come and watch the demo at 6:00 pm!
Conclusions • Questions ?