Python for Finance: Analyze Big Financial Data

(Elle) #1
imp_vol =   bsm_call_imp_vol(
V0, # VSTOXX value
options_data.loc[option][‘STRIKE’],
options_data.loc[option][‘TTM’],
r, # short rate
options_data.loc[option][‘PRICE’],
sigma_est=2., # estimate for implied volatility
it= 100 )
options_data[‘IMP_VOL’].loc[option] = imp_vol

In this code, there is some pandas syntax that might not be obvious at first sight. Chapter 6


explains pandas and its use for such operations in detail. At this stage, it suffices to


understand the following features:


In  [ 10 ]: futures_data[‘MATURITY’]
# select the column with name MATURITY
Out[10]: 496 2014-04-18
497 2014-05-16
498 2014-06-20
499 2014-07-18
500 2014-08-15
501 2014-09-19
502 2014-10-17
503 2014-11-21
Name: MATURITY, dtype: datetime64[ns]
In [ 11 ]: options_data.loc[ 46170 ]
# select data row for index 46170
Out[11]: DATE 2014-03-31 00:00:00
EXP_YEAR 2014
EXP_MONTH 4
TYPE C
STRIKE 1
PRICE 16.85
MATURITY 2014-04-18 00:00:00
TTM 0.049
IMP_VOL 0
Name: 46170, dtype: object
In [ 12 ]: options_data.loc[ 46170 ][‘STRIKE’]
# select only the value in column STRIKE
# for index 46170
Out[12]: 1.0

The implied volatilities for the selected options shall now be visualized. To this end, we


use only the subset of the options_data object for which we have calculated the implied


volatilities:


In  [ 13 ]: plot_data   =   options_data[options_data[‘IMP_VOL’]    >    0 ]

To visualize the data, we iterate over all maturities of the data set and plot the implied


volatilities both as lines and as single points. Since all maturities appear multiple times,


we need to use a little trick to get to a nonredundent, sorted list with the maturities. The


set operation gets rid of all duplicates, but might deliver an unsorted set of the maturities.


Therefore, we sort the set object (cf. also Chapter 4):


[ 13 ]

In  [ 14 ]: maturities  =   sorted(set(options_data[‘MATURITY’]))
maturities
Out[14]: [Timestamp(‘2014-04-18 00:00:00’),
Timestamp(‘2014-05-16 00:00:00’),
Timestamp(‘2014-06-20 00:00:00’),
Timestamp(‘2014-07-18 00:00:00’),
Timestamp(‘2014-08-15 00:00:00’),
Timestamp(‘2014-09-19 00:00:00’),
Timestamp(‘2014-10-17 00:00:00’),
Timestamp(‘2014-11-21 00:00:00’)]

The following code iterates over all maturities and does the plotting. The result is shown


as Figure 3-1. As in stock or foreign exchange markets, you will notice the so-called

Free download pdf