Conclusions
This chapter provides the framework for the larger project of building a Python library to
value options and other derivatives by Monte Carlo simulation. The chapter introduces the
Fundamental Theorem of Asset Pricing, illustrating it by a rather simple numerical
example. Important results in this regard are provided for a general market model in
discrete time.
The chapter also develops a Python class for risk-neutral discounting purposes to make
numerical use of the machinery of the Fundamental Theorem of Asset Pricing. Based on a
list of either Python datetime objects or floats representing year fractions, instances of
the class constant_short_rate provide the respective discount factors (present values of
unit zero-coupon bonds).
The chapter concludes with the rather generic market_environment class, which allows
for the collection of relevant data and Python objects for modeling, simulation, valuation,
and other purposes.
To simplify future imports we will use a wrapper module called dx_frame.py, as
presented in Example 15-4.
Example 15-4. Wrapper module for framework components
DX Library Frame
dx_frame.py
import datetime as dt
from get_year_deltas import get_year_deltas
from constant_short_rate import constant_short_rate
from market_environment import market_environment
A single import statement like the following then makes all framework components
available in a single step:
from dx_frame import *
Thinking of a Python library and a package of modules, there is also the option to store all
relevant Python modules in a (sub)directory and to put in that directory a special init file
that does all the imports. For example, when storing all modules in a directory called dx,
say, the file presented in Example 15-5 does the job. However, notice the naming
convention for this particular file.
Example 15-5. Python packaging file
DX Library
packaging file
init.py
import datetime as dt
from get_year_deltas import get_year_deltas
from constant_short_rate import constant_short_rate
from market_environment import market_environment
In that case you can just use the directory name to accomplish all the imports at once:
from dx import *