Python for Finance: Analyze Big Financial Data

(Elle) #1

self.instrument_values = paths


Of course, since we are dealing now with a different model, we need a different set of


elements in the market_environment object. In addition to those for the


geometric_brownian_motion class (see Table 16-1), there are three additions, as outlined


in Table 16-2: namely, the parameters of the log-normal jump component, lambda, mu, and


delta.


Table 16-2. Specific elements of market environment for jump_diffusion class


Element Type Mandatory Description

lambda

Constant

Yes

Jump intensity (probability p.a.)

mu

Constant

Yes

Expected jump size

delta

Constant

Yes

Standard deviation of jump size

For the generation of the paths, this class of course needs further random numbers because


of the jump component. Inline comments in the method generate_paths highlight the two


spots where these additional random numbers are generated. For the generation of


Poisson-distributed random numbers, see also Chapter 10.


A Use Case


In what follows, we again illustrate the use of the simulation class jump_diffusion


interactively. We make use of the market_environment object defined for the GBM object


in the previous section:


In  [ 15 ]: me_jd   =   market_environment(‘me_jd’, dt.datetime( 2015 ,  1 ,     1 ))
In [ 16 ]: # add jump diffusion specific parameters
me_jd.add_constant(‘lambda’, 0.3)
me_jd.add_constant(‘mu’, -0.75)
me_jd.add_constant(‘delta’, 0.1)

To this environment, we add the complete environment of the GBM simulation class,


which completes the input needed:


In  [ 17 ]: me_jd.add_environment(me_gbm)

Based on this market_environment object, we can instantiate the simulation class for the


jump diffusion:


In  [ 18 ]: from jump_diffusion import jump_diffusion
In [ 19 ]: jd = jump_diffusion(‘jd’, me_jd)

Due to the modeling approach we have implemented, the generation of instrument values


is now formally the same. The method call in this case is a bit slower, however, since we


need to simulate more numerical values due to the jump component:


In  [ 20 ]: %time paths_3   =   jd.get_instrument_values()
Out[20]: CPU times: user 19.7 ms, sys: 2.92 ms, total: 22.6 ms
Wall time: 21.9 ms

With the aim of again comparing two different sets of paths, change, for example, the


jump probability:

Free download pdf