Python for Finance: Analyze Big Financial Data

(Elle) #1

for the derivatives_portfolio object just defined:


In  [ 23 ]: portfolio.get_statistics()
Out[23]:
name quant. value curr. pos_value pos_delta pos_vega
0 eur_call_pos 5 2.814638 EUR 14.073190 3.3605 42.7900
1 am_put_pos 3 4.472021 EUR 13.416063 -2.0895 30.5181

The sum of the position values, Deltas, and Vegas is also easily calculated. This portfolio


is slightly long Delta (almost neutral) and long Vega:


In  [ 24 ]: portfolio.get_statistics()[[‘pos_value’,    ‘pos_delta’,    ‘pos_vega’]].sum()
# aggregate over all positions
Out[24]: pos_value 27.489253
pos_delta 1.271000
pos_vega 73.308100
dtype: float64

A complete overview of all positions is conveniently obtained by the get_positions


method — such output can, for example, be used for reporting purposes (but is omitted


here due to reasons of space):


In  [ 25 ]: portfolio.get_positions()

Of course, you can also access and use all (simulation, valuation, etc.) objects of the


derivatives_portfolio object in direct fashion:


In  [ 26 ]: portfolio.valuation_objects[‘am_put_pos’].present_value()
Out[26]: 4.450573
In [ 27 ]: portfolio.valuation_objects[‘eur_call_pos’].delta()
Out[27]: 0.6498

This derivatives portfolio valuation is conducted based on the assumption that the risk


factors are not correlated. This is easily verified by inspecting two simulated paths, one for


each simulation object:


In  [ 28 ]: path_no =    777
path_gbm = portfolio.underlying_objects[‘gbm’].get_instrument_values()[
:, path_no]
path_jd = portfolio.underlying_objects[‘jd’].get_instrument_values()[
:, path_no]

Figure 18-1 shows the selected paths in direct comparison — no jump occurs for the jump


diffusion:


In  [ 29 ]: import matplotlib.pyplot as plt
%matplotlib inline
In [ 30 ]: 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