def result_dicts(some_mids,some_quotes,expiration_dict,trade_date,expiries): vol_results = dict() money_results = dict() dte_info = dict() #could be appended to expiry info but... basis_info = dict() #loop through all your expiries # -- append basis to your weighted mids table (we'll store this later) # -- store vols/moneyness info into dicts temporarily for exp in expiries: und_expiry_code = underlying_code_by_two_digit_code(exp) und_sym = underlying_code(und_expiry_code,underlyings(some_quotes)).values[0] exp_dte = dte(exp,trade_date,expiration_dict) print 'Expiry : ', exp, ' :: Corresponding Underlying: ',und_sym ,' :: DTE: ', exp_dte basis_code = exp+'-'+und_expiry_code+'-'+str(exp_dte) if und_expiry_code == exp: #quarterly spot_filtered = pd.Series(some_mids[und_sym].values,index=some_mids.index) syn_spread = pd.Series(np.zeros(len(spot_filtered)),index=some_mids.index) else: spot = synthetic_offset(exp,und_sym,some_mids) if len(spot.valid()) == 0: #we were never able to calculate a synthetic basis and thus can't calc underlying continue syn_spread = univariate_kf(spot.values,spot[spot.first_valid_index()],1,500) spot_filtered = pd.Series(syn_spread+some_mids[und_sym].values,index=spot.index) some_mids[basis_code] = spot_filtered vol_results[exp] = imp_vols_cython(some_mids.ix[:,options_expiry_mask(some_mids.columns,exp).values],spot_filtered,exp_dte) money_results[exp] = pd.DataFrame(altmoneys(spot_filtered.fillna(method='ffill').fillna(method='bfill').values, kospi_strikes_from_symbols(vol_results[exp].columns.values).values,exp_dte/260.0), index = some_mids.index, columns = vol_results[exp].columns) dte_info[exp] = exp_dte basis_info[exp] = pd.Series(syn_spread,index=spot.index) return [vol_results,money_results,dte_info,basis_info]
def save_supplementary(h5_pointer,pcap_info,vols_type): s = pd.Series(h5_pointer.keys()) vol_series_list = [] basis_series_list = [] fut_bid_series_list = [] fut_ask_series_list = [] print 'Pcap Info Length entering: ',len(pcap_info) for k in s[s.str.contains(vols_type)]: two_digit_code = k[1:3] my_und = underlying_code(underlying_code_by_two_digit_code(two_digit_code),underlyings(pcap_info)).values[0] just_that_data = pcap_info[options_expiry_mask(pcap_info.symbol,two_digit_code)] just_that_fut = pcap_info[pcap_info.symbol==my_und] strikes = np.array(kospi_strikes_from_symbols(just_that_data.symbol.values),dtype=object) just_those_vols = h5_pointer[k] basis = h5_pointer['basis'][two_digit_code] basis.index = basis.index.astype(np.int64) just_that_data['vols'] = cross(strikes,just_that_data.index.astype(long),just_those_vols.index.astype(long),just_those_vols.columns.values,just_those_vols.values) just_that_data['basis'] = basis.asof(just_that_data.index).fillna(method='ffill') just_that_data['fut_bid'] = just_that_fut.bid1.asof(just_that_data.index).fillna(method='ffill') just_that_data['fut_ask'] = just_that_fut.ask1.asof(just_that_data.index).fillna(method='ffill') vol_series_list.append(just_that_data['vols']) basis_series_list.append(just_that_data['basis']) fut_bid_series_list.append(just_that_data['fut_bid']) fut_ask_series_list.append(just_that_data['fut_ask']) pcap_info['vols'] = pd.concat(vol_series_list).reindex_like(pcap_info) pcap_info['basis'] = pd.concat(basis_series_list).reindex_like(pcap_info) pcap_info['fut_bid'] = pd.concat(fut_bid_series_list).reindex_like(pcap_info) pcap_info['fut_ask'] = pd.concat(fut_ask_series_list).reindex_like(pcap_info) h5_pointer.remove('supplementary') print 'Pcap Info Length exiting: ',len(pcap_info) h5_pointer.append('supplementary',pcap_info.ix[:,['vols','basis','fut_bid','fut_ask']])