
P1: JYS
c03 JWBK378-Fletcher May 1, 2009 19:52 Printer: Yet to come
3
Extending Python from C++
It is usual in financial institutions that make use of quantitative analysis programs to have a
considerable investment in C++. Thus it can be important to foster interoperability between
C++ and Python. This chapter studies how Python modules can be implemented in C++ by
means of the Boost.Python
1
library (see also Appendix B for a primer on the Boost.Python
library).
3.1 BOOST.DATE TIME TYPES
It is common in quantitative analysis programming to require manipulation of and computa-
tions involving dates. The ‘Python Library’ contains excellent functionality for such activities.
Pricing systems written in C++, however, will be implemented using C++ datatypes for the
representation of dates and times. For pricing frameworks implemented in a hybrid of Python
and C++, it would be convenient to settle on a common representation of these fundamental
types. Accordingly, in this section we demonstrate the ‘reflection’ of functionality from the
C++ Boost.Date
Time library to Python.
Our reflection of the C++ date types into Python will be housed in the Python module
‘ppf
date time.pyd’, implemented in C++. We declare this intention in the entry point to our
Python module in the file ‘module.cpp’:
#include <boost/python/module.hpp>
namespace ppf
{
namespace date
time
{
void register
date();
void register
date more();
} // namespace ...