Python for Finance: Analyze Big Financial Data

(Elle) #1

Market Environments


Market environment is “just” a name for a collection of other data and Python objects.


However, it is rather convenient to work with this abstraction since it simplifies a number


of operations and also allows for a consistent modeling of recurring aspects.


[ 69 ]

A market


environment mainly consists of three dictionaries to store the following types of data and


Python objects:


Constants


These can be, for example, model parameters or option maturity dates.


Lists


These are sequences of objects in general, like a list object of objects modeling


(risky) securities.


Curves


These are objects for discounting; for example, like an instance of the


constant_short_rate class.


Example 15-3 presents the market_environment class. Refer to Chapter 4 for a refresher


on the handling of dict objects.


Example 15-3. Class for modeling a market environment with constants, lists, and curves



DX Library Frame


market_environment.py



class market_environment(object):
”’ Class to model a market environment relevant for valuation.


            Attributes
==========
name: string
name of the market environment
pricing_date : datetime object
date of the market environment

Methods
=======
add_constant :
adds a constant (e.g. model parameter)
get_constant :
gets a constant
add_list :
adds a list (e.g. underlyings)
get_list :
gets a list
add_curve :
adds a market curve (e.g. yield curve)
get_curve :
gets a market curve
add_environment :
adds and overwrites whole market environments
with constants, lists, and curves
”’

def init(self, name, pricing_date):
self.name = name
self.pricing_date = pricing_date
self.constants = {}
self.lists = {}
self.curves = {}

Free download pdf