Python for Finance: Analyze Big Financial Data

(Elle) #1
np.array(calculate_model_values(opt_local).values())
option_selection[‘ERRORS’] = \
option_selection[‘MODEL’] - option_selection[‘PRICE’]

We get the following results:


In  [ 52 ]: option_selection[[‘MODEL’,  ‘PRICE’,    ‘ERRORS’]]
Out[52]: MODEL PRICE ERRORS
46482 4.746597 4.85 -0.103403
46483 4.286923 4.30 -0.013077
46484 3.863346 3.80 0.063346
46485 3.474144 3.40 0.074144
46486 3.119211 3.05 0.069211
46487 2.793906 2.75 0.043906
46488 2.494882 2.50 -0.005118
46489 2.224775 2.25 -0.025225
46490 1.981110 2.10 -0.118890

The average pricing error is relatively low, at less than 1 cent:


In  [ 53 ]: round(option_selection[‘ERRORS’].mean(),     3 )
Out[53]: -0.002

Figure 19-1 shows all the results graphically. The largest difference is observed for the call


option that is farthest out of the money:


In  [ 54 ]: import matplotlib.pyplot as plt
%matplotlib inline
fix, (ax1, ax2) = plt.subplots( 2 , sharex=True, figsize=( 8 , 8 ))
strikes = option_selection[‘STRIKE’].values
ax1.plot(strikes, option_selection[‘PRICE’], label=‘market quotes’)
ax1.plot(strikes, option_selection[‘MODEL’], ‘ro’, label=‘model values’)
ax1.set_ylabel(‘option values’)
ax1.grid(True)
ax1.legend(loc= 0 )
wi = 0.25
ax2.bar(strikes - wi / 2., option_selection[‘ERRORS’],
label=‘market quotes’, width=wi)
ax2.grid(True)
ax2.set_ylabel(‘differences’)
ax2.set_xlabel(‘strikes’)
Free download pdf