P1: JYS
c02 JWBK378-Fletcher May 1, 2009 19:51 Printer: Yet to come
The PPF Package 7
Trying:
print black
scholes(S=42., K=40., r=0.1, sig= 0.2, T=0.5, CP=PUT)
Expecting:
0.808598915338
ok
2 items had no tests:
main
main . test
1 items passed all tests:
2 tests in
main .black scholes
2 tests in 3 items.
2 passed and 0 failed.
Test passed.
2.2.2 PyUnit
A full suite of unit tests for all modules in the ppf package is provided in the ppf.test
sub-package. The tests can be run module-by-module or, to execute all tests in one go, a driver
‘test
all.py’ is provided:
C:\Python25\Lib\site-packages\ppf\test>python test all.py --verbose
python test
all.py --verbose
test
call (test core.black scholes tests) ... ok
test
put (test core.black scholes tests) ... ok
test (test
core.libor rate tests) ... ok
.
.
.
test
upper bound (test utility.bound tests) ... ok
test
equal range (test utility.bound tests) ... ok
test
bound (test utility.bound tests) ... ok
test
bound ci (test utility.bound tests) ... ok
--------------------------------------------------------------------
Ran 51 tests in 25.375s
OK
2.3 BUILDING AND INSTALLING PPF
In this section we look at what it takes to build and install the ppf package.
2.3.1 Prerequisites and Dependencies
ppf is composed of a mixture of pure Python modules underlied by some supporting extension
modules implemented instandard C++. Accordingly, to build and install ppf requiresa modern
C++ compiler. The C++ extension modules have some library dependencies of their own,
notably the Boost C++ libraries and the Blitz++ C++ library. Instructions for downloading
P1: JYS
c02 JWBK378-Fletcher May 1, 2009 19:51 Printer: Yet to come
8 Financial Modelling in Python
and installing the Boost C++ libraries can be found at http://www.boost.org and
instructions for Blitz++ can be found at http://www.oonumerics.org. Naturally, an
installation of Python is also required. On Windows, the authors favour the freely available
ActiveState Python distribution, see http://www.activestate.com for download and
installation details. Also required on the Python side for ppf is an installation of the NumPy
package, see http://www.scipy.org for download and installation details.
2.3.2 Building the C++ Extension Modules
The ppf C++ extension modules are most conveniently built using the Boost.Build system
1
a
copy of which is included with the ppf sources. Also provided with the ppf sources for the
convenience of Windows users is a pre-built executable ‘bjam.exe’. Although these notes will
become a little Windows-centric at this point, the basic principles will hold for *NIX users also.
On Windows, the ppf package has been successfully built and tested with the Microsoft Visual
Studio C++ compiler versions 7.1, 8.0 (express edition), 9.0 (express edition), mingw/gcc-
3.4.5,
2
mingw/gcc-4.3.0 with Python versions 2.4 and 2.5, Boost versions 1.33.1, 1.34.0,
1.35, 1.36, 1.37 and Blitz++ version 0.9. The ppf package has also been built and tested on
the popular Linux-based operating system, Ubuntu-8.04.1 with Boost version 1.36.0, Blitz++
version 0.9 and gcc-4.2.3.
In the remainder of this section, without loss of generality, we will assume a Windows
operating system, Blitz++ version 0.9, the ActiveState distribution of Python version 2.5 and
Boost version 1.36.
Build Instructions
Prerequisites
- Copy c:/path/to/ppf/ext/bjam.exe to somewhere in your %PATH%
- Install
o Blitz++-0.9
o Boost-1.36
o ActiveState Python 2.5
o NumPy for Python 2.5 (version 1.0.4 or 1.1.0)
- Edit as appropriate for your site
o c:/path/to/ppf/ext/build/user-config.jam
o c:/path/to/ppf/ext/build/site-config.jam
Build
- c:/path/to/ppf>cd ext&&bjam [debug|release]
This will create:
o c:/path/to/ppf/ppf/math/ppf
math.pyd and
o c:/path/to/ppf/ppf/date
time/ppf date time.pyd
1
See http://www.boost.org/doc/tools/build/index.html.
2
Minimalist GNU for Windows – see http://www.mingw.org.
P1: JYS
c02 JWBK378-Fletcher May 1, 2009 19:51 Printer: Yet to come
The PPF Package 9
2.3.3 Installing the PPF Package
Assuming the steps of the previous section have been performed, installation of the ppf
package which relies on the standard Python Distutils package is very simple.
Install
- c:/path/to/ppf>python setup.py install
which will copy the ppf package to the standard Python installation location
(c:/python25/lib/site-packages/ppf).
2.3.4 Testing a PPF Installation
The easiest way to verify a ppf installation is to run the ppf unit test suite.
Test
- c:/python25/lib/site-packages/ppf/test>python test all.py --
verbose
P1: JYS
c02 JWBK378-Fletcher May 1, 2009 19:51 Printer: Yet to come
10

Get Financial Modelling in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.