A rather brief use case illustrates the use of the simulation class. As usual, we need a
market environment, for example to model a volatility (index) process:
In [ 35 ]: me_srd = market_environment(‘me_srd’, dt.datetime( 2015 , 1 , 1 ))
In [ 36 ]: me_srd.add_constant(‘initial_value’, . 25 )
me_srd.add_constant(‘volatility’, 0.05)
me_srd.add_constant(‘final_date’, dt.datetime( 2015 , 12 , 31 ))
me_srd.add_constant(‘currency’, ‘EUR’)
me_srd.add_constant(‘frequency’, ‘W’)
me_srd.add_constant(‘paths’, 10000 )
Two components of the market environment are specific to the class:
In [ 37 ]: # specific to simualation class
me_srd.add_constant(‘kappa’, 4.0)
me_srd.add_constant(‘theta’, 0.2)
Although we do not need it here to implement the simulation, the generic simulation class
requires a discounting object. This requirement can be justified from a risk-neutral
valuation perspective, which is the overarching goal of the whole DX analytics library:
In [ 38 ]: # required but not needed for the class
me_srd.add_curve(‘discount_curve’, constant_short_rate(‘r’, 0.0))
In [ 39 ]: from square_root_diffusion import square_root_diffusion
In [ 40 ]: srd = square_root_diffusion(‘srd’, me_srd)
As before, we get simulation paths, given the market_environment object as input, by
calling the get_instrument_values method:
In [ 41 ]: srd_paths = srd.get_instrument_values()[:, : 10 ]
Figure 16-3 illustrates the mean-reverting characteristic by showing how the single
simulated paths on average revert to the long-term mean theta (dashed line):
In [ 42 ]: plt.figure(figsize=( 8 , 4 ))
plt.plot(srd.time_grid, srd.get_instrument_values()[:, : 10 ])
plt.axhline(me_srd.get_constant(‘theta’), color=‘r’, ls=‘—’, lw=2.0)
plt.grid(True)
plt.xticks(rotation= 30 )
Figure 16-3. Simulated paths from square-root diffusion simulation class (dashed line = long-term mean theta)