Python for Finance: Analyze Big Financial Data

(Elle) #1
eur_call.update(initial_value=s)
p_list.append(eur_call.present_value(fixed_seed=True))
d_list.append(eur_call.delta())
v_list.append(eur_call.vega())
Out[15]: CPU times: user 239 ms, sys: 8.18 ms, total: 248 ms
Wall time: 248 ms

Equipped with all these values, we can graphically inspect the results. To this end, we use


a helper function as shown in Example 17-3.


Example 17-3. Helper function to plot options statistics



DX Library Valuation


plot_option_stats.py



import matplotlib.pyplot as plt


def plot_option_stats(s_list, p_list, d_list, v_list):
”’ Plots option prices, Deltas, and Vegas for a set of
different initial values of the underlying.


            Parameters
==========
s_list : array or list
set of initial values of the underlying
p_list : array or list
present values
d_list : array or list
results for Deltas
v_list : array or list
results for Vegas
”’

plt.figure(figsize=( 9 , 7 ))
sub1 = plt.subplot( 311 )
plt.plot(s_list, p_list, ‘ro’, label=‘present value’)
plt.plot(s_list, p_list, ‘b’)
plt.grid(True); plt.legend(loc= 0 )
plt.setp(sub1.get_xticklabels(), visible=False)
sub2 = plt.subplot( 312 )
plt.plot(s_list, d_list, ‘go’, label=‘Delta’)
plt.plot(s_list, d_list, ‘b’)
plt.grid(True); plt.legend(loc= 0 )
plt.ylim(min(d_list) - 0.1, max(d_list) + 0.1)
plt.setp(sub2.get_xticklabels(), visible=False)
sub3 = plt.subplot( 313 )
plt.plot(s_list, v_list, ‘yo’, label=‘Vega’)
plt.plot(s_list, v_list, ‘b’)
plt.xlabel(‘initial value of underlying’)
plt.grid(True); plt.legend(loc= 0 )


Importing this function and providing the valuation results to it generates a picture like


that shown in Figure 17-1:


In  [ 16 ]: from plot_option_stats import plot_option_stats
%matplotlib inline
In [ 17 ]: plot_option_stats(s_list, p_list, d_list, v_list)
Free download pdf