.. _pde: Building in-house libraries: C++ =================================================== .. contents:: :depth: 3 :local: :backlinks: entry 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 :ref:`squareCPP` 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 :ref:`squareCPP`. 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 :ref:`frmchart`, with extra details. .. _pdechart: .. figure:: pythonExtension.png :scale: 100% :align: center :alt: Pricing of Bermudan swaption Pricing of Bermudan swaption