Skip to content

thejourneyofman/QuantLib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13,996 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parallelized Quantlib (For test use)

Motivation

Challenge an ad-hoc way to make giant projects (in case of Quantlib, about half million LOC) work in a parallel computing style that supports both multiple processes and multiple threads by adding as little codes as possible.

Restrictions

It's NOT an integral version-up for Quantlib users but a test bed of the integrity and extensibility of HPC how a fulcrum can pry to a whole project. In this case, I added about few hundreds of lines (less than 1% of the whole project) of code and started working from the base classes which are inherited by many top-level objects and functions.

Features

For now it supports multiple threads in a particle size of Instrument, that is, one pricing engine (in some case it's bounded with a certain time-consuming stochastic process) works in an independent single thread for a single instrument.

Meanwhile, it provides a protocol to use MPI that can support multiple processes to manage the main thread and the instruments can be grouped to different processes in a in a particle size of "Portfolio" as to be a future work.

A use case (EquityOption)

You have a basket of options to be monitored and performed by calculations using different pricing engines for different option types. And each option may use different engines (BSM, Binomial, MC for an example) to compare the NPV or other indicators for the purpose of your strategy.

In its original synchronous mode, it works like

std::cout << europeanOption->NPV() << std::endl;
bermudanOption->setPricingEngine(binomialEngine);
std::cout << bermudanOption->NPV() << std::endl;
americanOption->setPricingEngine(mcEngine);
std::cout << americanOption->NPV() << std::endl;

In a new asynchronous mode, it works like

bermudanOption->setPricingEngine(binomialEngine);
americanOption->setPricingEngine(mcEngine);
portfolio->reset();
portfolio->subscribeSignal(europeanOption);
portfolio->subscribeSignal(bermudanOption);
portfolio->subscribeSignal(americanOption);
portfolio->start();

Broadcast Strategies

It supports three kinds of broadcasting strategies to communicate all the signals from different processes and threads.

allToAll

All signals from each process and its threads will be broadcasted to all other processes (full connection).

gatherFromSlaves

Main processes will gather all signals from other processes and their threads. (inward start connection)

broadcastFromMaster

Main processes will broadcast its signals to other processes and their threads. (outward start connection)

Objects/Classes Added

ThreadedLazyObject (based on LazyObject), which manages the thread, signal and slot.

ObjectWrapper, which handles the threading processes and errors.

Strategy, which provides different modes of broadcasting between processes.

Communicator, which is a simple wrapper of MPI.

How to use it

go to the Solution Directory(where sln file is) \MSMPI\Bin

Run " .\mpiexec.exe -n [Number of Processes] Solution Directory\Examples\EquityOption\bin\EquityOption-x64-mt-gd.exe"

How to build it

Following the guidance of official site of Quanlib with some additional configuration,

add the path of boost thread and MSMPI libraries to the project

add "USE_MPI" to the preprocessors

go to the file of userconfig.hpp, uncomment the following line

#    define QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN

Tools

Environment

-- Windows 10

-- Visual Studio 2019 (v142)

-- Microsoft .NET Framework (4.8.03752)

-- ISO C++17 Standard (/std:c++17)

-- boost (1.75.0)

-- MSMPI (10.1.2) 64 bit

The following parts are cloned from original repository

https://github.com/lballabio/QuantLib

QuantLib: the free/open-source library for quantitative finance

Download Licensed under the BSD 3-Clause License DOI PRs Welcome

Linux build status Windows build status Mac OS build status CMake build status

Codacy Badge Code Quality: Cpp Coverage Status


The QuantLib project (http://quantlib.org) is aimed at providing a comprehensive software framework for quantitative finance. QuantLib is a free/open-source library for modeling, trading, and risk management in real-life.

QuantLib is Non-Copylefted Free Software and OSI Certified Open Source Software.

Download and usage

QuantLib can be downloaded from http://quantlib.org/download.shtml; installation instructions are available at http://quantlib.org/install.shtml for most platforms.

Documentation for the usage and the design of the QuantLib library is available from http://quantlib.org/docs.shtml.

A list of changes for each past versions of the library can be browsed at http://quantlib.org/reference/history.html.

Questions and feedback

The preferred channel for questions (and the one with the largest audience) is the quantlib-users mailing list. Instructions for subscribing are at http://quantlib.org/mailinglists.shtml.

Bugs can be reported as a GitHub issue at https://github.com/lballabio/QuantLib/issues; if you have a patch available, you can open a pull request instead (see "Contributing" below).

Contributing

The preferred way to contribute is through pull requests on GitHub. Get a GitHub account if you don't have it already and clone the repository at https://github.com/lballabio/QuantLib with the "Fork" button in the top right corner of the page. Check out your clone to your machine, code away, push your changes to your clone and submit a pull request; instructions are available at https://help.github.com/articles/fork-a-repo.

In case you need them, more detailed instructions for creating pull requests are at https://help.github.com/articles/using-pull-requests, and a basic guide to GitHub is at https://guides.github.com/activities/hello-world/. GitHub also provides interactive learning at https://lab.github.com/.

It's likely that we won't merge your code right away, and we'll ask for some changes instead. Don't be discouraged! That's normal; the library is complex, and thus it might take some time to become familiar with it and to use it in an idiomatic way.

We're looking forward to your contributions.

About

The QuantLib C++ library

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 97.6%
  • C 1.1%
  • Makefile 0.6%
  • CMake 0.4%
  • Fortran 0.2%
  • M4 0.1%