Пример #1
0
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]
Пример #2
0
def kf_vols(raw):
    simple_kf = raw.copy()
    for c in simple_kf.columns:
      dex = simple_kf[c].first_valid_index()
      if dex:
          seed = simple_kf[c][dex]
          simple_kf[c] = univariate_kf(simple_kf[c].values,seed,seed/1000.,seed/10.)
      return simple_kf
Пример #3
0
def splined_kf_residualized(raw,simple_kf_vols,moneys):
    splined_kf_vols = crs.crs_vols(simple_kf_vols,moneys,deltas=np.array([]))

    splined_kf_adjusted = splined_kf_vols.copy()
    for c in splined_kf_vols.columns:
        residuals = (raw[c] - splined_kf_vols[c])
        filtered_residuals = univariate_kf(residuals.values,0,1,10000)
        splined_kf_adjusted[c] += filtered_residuals
    return splined_kf_adjusted