In [1]:
from dx import *
In [2]:
me = market_environment(name='me', pricing_date=dt.datetime(2015, 1, 1))
me.add_constant('initial_value', 0.01)
me.add_constant('volatility', 0.1)
me.add_constant('kappa', 2.0)
me.add_constant('theta', 0.05)
me.add_constant('paths', 1000)
me.add_constant('frequency', 'M')
me.add_constant('starting_date', me.pricing_date)
me.add_constant('final_date', dt.datetime(2015, 12, 31))
me.add_curve('discount_curve', 0.0) # dummy
me.add_constant('currency', 0.0) # dummy
In [3]:
ssr = stochastic_short_rate('sr', me)
In [4]:
time_list = [dt.datetime(2015, 1, 1),
dt.datetime(2015, 4, 1),
dt.datetime(2015, 6, 15),
dt.datetime(2015, 10, 21)]
In [5]:
ssr.get_forward_rates(time_list, 10)
Out[5]:
In [6]:
ssr.get_discount_factors(time_list, 10)
Out[6]:
In [7]:
me.add_constant('initial_value', 36.)
me.add_constant('volatility', 0.2)
# time horizon for the simulation
me.add_constant('currency', 'EUR')
me.add_constant('frequency', 'M')
# monthly frequency; paramter accorind to pandas convention
me.add_constant('paths', 10)
# number of paths for simulation
In [8]:
r = constant_short_rate('r', 0.01)
In [9]:
me.add_curve('discount_curve', ssr)
In [10]:
gbm = geometric_brownian_motion('gbm', me)
In [11]:
gbm.get_instrument_values()
Out[11]:
In [12]:
import matplotlib.pyplot as plt
%matplotlib inline
In [13]:
# short rate paths
plt.plot(ssr.process.instrument_values[:, :10]);
Copyright, License & Disclaimer
© Dr. Yves J. Hilpisch | The Python Quants GmbH
DX Analytics (the "dx library") is licensed under the GNU Affero General Public License version 3 or later (see http://www.gnu.org/licenses/).
DX Analytics comes with no representations or warranties, to the extent permitted by applicable law.
http://www.pythonquants.com | analytics@pythonquants.com | http://twitter.com/dyjh
Python Quant Platform | http://quant-platform.com
Derivatives Analytics with Python (Wiley Finance) | http://derivatives-analytics-with-python.com
Python for Finance (O'Reilly) | http://shop.oreilly.com/product/0636920032441.do