Python for Finance: Analyze Big Financial Data

(Elle) #1
Figure 18-1. Noncorrelated risk factors

Now consider the case where the two risk factors are highly positively correlated:


In  [ 31 ]: correlations    =   [[‘gbm’,    ‘jd’,   0.9]]

With this additional information, a new derivatives_portfolio object is to be


instantiated:


In  [ 32 ]: port_corr   =   derivatives_portfolio(
name=‘portfolio’,
positions=positions,
val_env=val_env,
assets=underlyings,
correlations=correlations,
fixed_seed=True)

In this case, there is no direct influence on the values of the positions in the portfolio:


In  [ 33 ]: port_corr.get_statistics()
Out[33]:
name quant. value curr. pos_value pos_delta pos_vega
0 eur_call_pos 5 2.804464 EUR 14.022320 3.3760 42.3500
1 am_put_pos 3 4.458565 EUR 13.375695 -2.0313 30.1416

However, the correlation takes place behind the scenes. For the graphical illustration, we


take the same two paths as before:


In  [ 34 ]: path_gbm    =   port_corr.underlying_objects[‘gbm’].\
get_instrument_values()[:, path_no]
path_jd = port_corr.underlying_objects[‘jd’].\
get_instrument_values()[:, path_no]

Figure 18-2 now shows a development almost in perfect parallelism between the two risk


factors:


In  [ 35 ]: plt.figure(figsize=( 7 ,     4 ))
plt.plot(portfolio.time_grid, path_gbm, ‘r’, label=‘gbm’)
plt.plot(portfolio.time_grid, path_jd, ‘b’, label=‘jd’)
plt.xticks(rotation= 30 )
plt.legend(loc= 0 ); plt.grid(True)
Free download pdf