Building in-house libraries: C++

Input/output

The data structure that best fits our purposes is the Python dictionary.

The main idea is that Python dictionary is a very rich data structure, containing not only the inputs, but also the logic required for setup and pricing. The C++ library should be unaware of financial concepts.

This is a very flexible and powerful design, as the C++ library can be thin (development focused on the mathematical and numerical aspects), require seldom updates, and focus on the “heavy lifting” - perform heavy computations.

See Using the C++ library for an example of communication between C++ and Python via a simple Python dictionary.

The main question is how to handle the Python dictionary inside the C++ library. We already mentioned two off-the-shelf solution. It also makes sense to build a custom solution in-house, as we do not need the most general interface. Two possible approaches are:

  • Create a dictionary structure in C++ by building on top of the STL map. While no catch-it-all solution seem to exist (akin to Boost for smart pointers), there are plenty of tips and ideas on the internet (Stack Overflow, etc).
  • Dissasemble the Python dictionary in the wrapper, like we did in Using the C++ library. This can be done at run time by automatically generating the hadcoded wrapper cpp file and finish building the library (by spawning a sub-process).

Flow chart

This flow is part of the framework chart Entire framework in one flowchart, with extra details.

Pricing of Bermudan swaption

Pricing of Bermudan swaption

Table Of Contents

Previous topic

Building in-house libraries: Python

Next topic

Tips: Work smarter, not harder

This Page