Example #1
0
def _calculate_betas(x):
    _d_pca_rt, _d_comb, _d_pca_bt = x
    pca_pr = _d_pca_rt.retrieve('Prices')
    tick_pr = _d_comb.retrieve('Close')
    pca_cols = [i for i in pca_pr.columns.tolist() if i != 'Date']
    tick_cols = [i for i in tick_pr.columns.tolist() if i != 'Date']
    for i in pca_cols:
        pca_pr_i = pca_pr[['Date', i]]
        tick_pr_i = cruf.DataFrame.merge(tick_pr, pca_pr_i, on='Date')
        tick_pr_i_beta = tick_pr.copy()
        for j in tick_cols:
            tick_pr_i_beta[j] = crtf.beta_cc(tick_pr_i[j].values, tick_pr_i[i].values, 120)
        _d_pca_bt.store(i+'_Beta', tick_pr_i_beta)
        del pca_pr_i, tick_pr_i, tick_pr_i_beta
    gc.collect()
Example #2
0
def _refresh_stats(x):
    _d_comb, _d_sig = x
    comb_prices = _d_comb.retrieve('Close')
    spy_prices = d_pr_cl.retrieve('SPY')
    nuv_prices = d_pr_cl.retrieve('NUV')

    # volatility measures
    comb_vol = comb_prices.copy()
    for i in comb_vol.tick_cols():
        comb_vol[i] = crtf.vol_cc(comb_prices[i].values, 120)
    _d_comb.store('Vol_CC_120D', comb_vol)

    # store the leverage
    comb_lev = comb_vol.copy()
    for i in comb_lev.tick_cols():
        comb_lev[i] = crtf.lrma(0.01/comb_vol[i].values, 30, lg=True)
    _d_comb.store('Lev_CC_120D', comb_lev)

    # generate the signals
    for j in range(1, 51):
        comb_ret_qr = comb_prices.copy()
        comb_ret_lr = comb_prices.copy()
        for i in comb_ret_lr.tick_cols():
            comb_ret_qr[i] = crtf.qrbeta(comb_ret_qr[i].values, j*10)
            comb_ret_lr[i] = crtf.lrbeta(comb_ret_lr[i].values, j*10)
        _d_sig.store('QrB_'+str(j*10)+'D', comb_ret_qr)
        _d_sig.store('LrB_'+str(j*10)+'D', comb_ret_lr)
        del comb_ret_lr
        del comb_ret_qr

    # generate 12-1 momentum, its score and factor returns
    comb_mom = comb_prices.copy()
    for i in comb_mom.tick_cols():
        comb_mom[i] = crtf.lrma(crtf.ret(comb_mom[i].values, 250)-crtf.ret(comb_mom[i].values, 21), 20)
    _d_comb.store('MOM_12m1v', comb_mom)
    comb_mom1 = comb_mom.copy()
    comb_mom1_tc = comb_mom.tick_cols()
    comb_mom1_val = comb_mom[comb_mom1_tc].values
    comb_mom1_val_st = np.sum(~np.isnan(comb_mom1_val), axis=1)
    comb_mom1_idx = np.where(comb_mom1_val_st>30)[0][0]
    dummy = np.empty(len(comb_mom1_tc)) * np.nan
    for j in range(0, comb_mom1_idx):
        comb_mom1_val[j, :] = dummy
    for j in range(comb_mom1_idx, comb_mom1_val.shape[0]):
        comb_mom1_val[j, :] = crup.full_norm_rankit(comb_mom1_val[j, :])
    comb_mom1[:, comb_mom1_tc] = comb_mom1_val
    _d_comb.store('MOM_12m1s', comb_mom1)
    comb_mom1['Close'] = np.nan
    comb_ret = _d_comb.retrieve('Returns')[comb_mom1_tc].values
    comb_ret[np.isnan(comb_ret)] = 0
    comb_mom1_val[np.isnan(comb_mom1_val)] = 0
    comb_mom1['Close'] = 2*np.sum(comb_ret * comb_mom1_val, axis=1)/np.sum(abs(comb_mom1_val), axis=1)
    comb_mom1 = comb_mom1[['Date', 'Close']]
    comb_mom1['Close'] = crup.conv_to_price(comb_mom1['Close'].values)
    _d_comb.store('MOMf', comb_mom1)

    # calculate mom_beta
    comb_mom_val = comb_mom1['Close'].values
    comb_mom_beta = comb_prices.copy()
    for i in comb_mom_beta.tick_cols():
        comb_mom_beta[i] = crtf.beta_cc(comb_mom_beta[i].values, comb_mom_val, 120)
    _d_comb.store('MOM_Beta_6m', comb_mom_beta)
    comb_mom_beta = comb_prices.copy()
    for i in comb_mom_beta.tick_cols():
        comb_mom_beta[i] = crtf.beta_cc(comb_mom_beta[i].values, comb_mom_val, 60)
    _d_comb.store('MOM_Beta_3m', comb_mom_beta)
    comb_mom_beta = comb_prices.copy()
    for i in comb_mom_beta.tick_cols():
        comb_mom_beta[i] = crtf.beta_cc(comb_mom_beta[i].values, comb_mom_val, 180)
    _d_comb.store('MOM_Beta_9m', comb_mom_beta)
    comb_mom_beta = comb_prices.copy()
    for i in comb_mom_beta.tick_cols():
        comb_mom_beta[i] = crtf.beta_cc(comb_mom_beta[i].values, comb_mom_val, 240)
    _d_comb.store('MOM_Beta_12m', comb_mom_beta)

    # calculate low_vol_beta
    comb_lowv = comb_prices.copy()
    for i in comb_lowv.tick_cols():
        comb_lowv[i] = crtf.lrma(crtf.vol_cc(comb_prices[i].values, 32, zl=False), 20)
    _d_comb.store('LVOL_32dv', comb_lowv)
    comb_lowv1 = comb_lowv.copy()
    comb_lowv1_tc = comb_lowv.tick_cols()
    comb_lowv1_val = comb_lowv[comb_lowv1_tc].values
    comb_lowv1_val_st = np.sum(~np.isnan(comb_lowv1_val), axis=1)
    comb_lowv1_idx = np.where(comb_lowv1_val_st>30)[0][0]
    dummy = np.empty(len(comb_lowv1_tc)) * np.nan
    for j in range(0, comb_lowv1_idx):
        comb_lowv1_val[j, :] = dummy
    for j in range(comb_lowv1_idx, comb_lowv1_val.shape[0]):
        comb_lowv1_val[j, :] = crup.full_norm_rankit(comb_lowv1_val[j, :])
    comb_lowv1[:, comb_lowv1_tc] = comb_lowv1_val
    _d_comb.store('LVOL_32ds', comb_lowv1)
    comb_lowv1['Close'] = np.nan
    comb_ret = _d_comb.retrieve('Returns')[comb_lowv1_tc].values
    comb_ret[np.isnan(comb_ret)] = 0
    comb_lowv1_val[np.isnan(comb_lowv1_val)] = 0
    comb_lowv1['Close'] = 2*np.sum(comb_ret * comb_lowv1_val, axis=1)/np.sum(abs(comb_lowv1_val), axis=1)
    comb_lowv1 = comb_lowv1[['Date', 'Close']]
    comb_lowv1['Close'] = crup.conv_to_price(comb_lowv1['Close'].values)
    _d_comb.store('LVOLf', comb_lowv1)

    # calculate lvol_beta
    comb_lowv_val = comb_lowv1['Close'].values
    comb_lowv_beta = comb_prices.copy()
    for i in comb_lowv_beta.tick_cols():
        comb_lowv_beta[i] = crtf.beta_cc(comb_lowv_beta[i].values, comb_lowv_val, 120)
    _d_comb.store('LVOL_Beta_6m', comb_lowv_beta)
    comb_lowv_beta = comb_prices.copy()
    for i in comb_lowv_beta.tick_cols():
        comb_lowv_beta[i] = crtf.beta_cc(comb_lowv_beta[i].values, comb_lowv_val, 60)
    _d_comb.store('LVOL_Beta_3m', comb_lowv_beta)
    comb_lowv_beta = comb_prices.copy()
    for i in comb_lowv_beta.tick_cols():
        comb_lowv_beta[i] = crtf.beta_cc(comb_lowv_beta[i].values, comb_lowv_val, 180)
    _d_comb.store('LVOL_Beta_9m', comb_lowv_beta)
    comb_lowv_beta = comb_prices.copy()
    for i in comb_lowv_beta.tick_cols():
        comb_lowv_beta[i] = crtf.beta_cc(comb_lowv_beta[i].values, comb_lowv_val, 240)
    _d_comb.store('LVOL_Beta_12m', comb_lowv_beta)

    # calculate beta to various indices
    # idx_list = ['GSPC', 'IXIC', 'VIX', 'BKX', 'DRG', 'IXCO', 'RUA', 'RUT', 'RUI', 'SOX', 'TRAN', 'UTY', 'XAU', 'XNG',
    #             'NBI', 'OSX']
    # for j in idx_list:
    #     comb_idx_beta = comb_prices.copy()
    #     comb_idx_beta2 = comb_prices.copy()
    #     comb_idx_beta3 = comb_prices.copy()
    #     comb_idx_beta4 = comb_prices.copy()
    #     y_ = d_idx.retrieve(j)[['Date', 'Close']]
    #     x_ = cruf.DataFrame.merge(comb_idx_beta, y_, how='left', on='Date')
    #     x_['Close'] = crtf.fill(x_['Close'].values)
    #     for i in comb_idx_beta.tick_cols():
    #         x_[i] = crtf.fill(x_[i].values)
    #         comb_idx_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #         comb_idx_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #         comb_idx_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #         comb_idx_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    #     _d_comb.store(j+'_Beta_6m', comb_idx_beta)
    #     _d_comb.store(j+'_Beta_3m', comb_idx_beta2)
    #     _d_comb.store(j+'_Beta_9m', comb_idx_beta3)
    #     _d_comb.store(j+'_Beta_12m', comb_idx_beta4)

    # calculate special series (Size)
    y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
                               d_idx.retrieve('RUT')[['Date', 'Close']], how='outer', on='Date')
    y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    y1_ = y1_[['Date', 'Close']]
    y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    comb_y_beta = comb_prices.copy()
    comb_y_beta2 = comb_prices.copy()
    comb_y_beta3 = comb_prices.copy()
    comb_y_beta4 = comb_prices.copy()
    x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    x_['Close'] = crtf.fill(x_['Close'].values)
    for i in comb_y_beta.tick_cols():
        x_[i] = crtf.fill(x_[i].values)
        comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
        comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
        comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
        comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    _d_comb.store('Size_Beta_6m', comb_y_beta)
    _d_comb.store('Size_Beta_3m', comb_y_beta2)
    _d_comb.store('Size_Beta_9m', comb_y_beta3)
    _d_comb.store('Size_Beta_12m', comb_y_beta4)

    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
    #                            d_idx.retrieve('IXIC')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 2400)
    # _d_comb.store('Nas_Beta_6m', comb_y_beta)
    # _d_comb.store('Nas_Beta_3m', comb_y_beta2)
    # _d_comb.store('Nas_Beta_9m', comb_y_beta3)
    # _d_comb.store('Nas_Beta_12m', comb_y_beta4)

    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
    #                            d_idx.retrieve('SOX')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Semi_Beta_6m', comb_y_beta)
    # _d_comb.store('Semi_Beta_3m', comb_y_beta2)
    # _d_comb.store('Semi_Beta_9m', comb_y_beta3)
    # _d_comb.store('Semi_Beta_12m', comb_y_beta4)

    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
    #                            d_idx.retrieve('NBI')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Bio_Beta_6m', comb_y_beta)
    # _d_comb.store('Bio_Beta_3m', comb_y_beta2)
    # _d_comb.store('Bio_Beta_9m', comb_y_beta3)
    # _d_comb.store('Bio_Beta_12m', comb_y_beta4)
    #
    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
    #                            d_idx.retrieve('DRG')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Drug_Beta_6m', comb_y_beta)
    # _d_comb.store('Drug_Beta_3m', comb_y_beta2)
    # _d_comb.store('Drug_Beta_9m', comb_y_beta3)
    # _d_comb.store('Drug_Beta_12m', comb_y_beta4)
    #
    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('GSPC')[['Date', 'Close']],
    #                            d_idx.retrieve('IXCO')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Comp_Beta_6m', comb_y_beta)
    # _d_comb.store('Comp_Beta_3m', comb_y_beta2)
    # _d_comb.store('Comp_Beta_9m', comb_y_beta3)
    # _d_comb.store('Comp_Beta_12m', comb_y_beta4)
    #
    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('IXCO')[['Date', 'Close']],
    #                            d_idx.retrieve('SOX')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Comp1_Beta_6m', comb_y_beta)
    # _d_comb.store('Comp1_Beta_3m', comb_y_beta2)
    # _d_comb.store('Comp1_Beta_9m', comb_y_beta3)
    # _d_comb.store('Comp1_Beta_12m', comb_y_beta4)
    #
    # y1_ = cruf.DataFrame.merge(d_idx.retrieve('DRG')[['Date', 'Close']],
    #                            d_idx.retrieve('NBI')[['Date', 'Close']], how='outer', on='Date')
    # y1_['Close'] = crtf.ret(y1_['Close_y'].values) - crtf.ret(y1_['Close_x'].values)
    # y1_ = y1_[['Date', 'Close']]
    # y1_['Close'] = crtf.fill1(y1_['Close'].values, 0)*1.5
    # y1_['Close'] = crup.conv_to_price(y1_['Close'].values)
    # comb_y_beta = comb_prices.copy()
    # comb_y_beta2 = comb_prices.copy()
    # comb_y_beta3 = comb_prices.copy()
    # comb_y_beta4 = comb_prices.copy()
    # x_ = cruf.DataFrame.merge(comb_y_beta, y1_, how='left', on='Date')
    # x_['Close'] = crtf.fill(x_['Close'].values)
    # for i in comb_y_beta.tick_cols():
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_y_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_y_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_y_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_y_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('Bio1_Beta_6m', comb_y_beta)
    # _d_comb.store('Bio1_Beta_3m', comb_y_beta2)
    # _d_comb.store('Bio1_Beta_9m', comb_y_beta3)
    # _d_comb.store('Bio1_Beta_12m', comb_y_beta4)

    # correlation with SPY
    comb_sp_beta = comb_prices.copy()
    comb_sp_beta2 = comb_prices.copy()
    comb_sp_beta3 = comb_prices.copy()
    comb_sp_beta4 = comb_prices.copy()
    for i in comb_sp_beta.tick_cols():
        x_ = cruf.DataFrame.merge(comb_sp_beta[['Date', i]], spy_prices[['Date', 'Close']], how='left', on='Date')
        x_.sort('Date')
        x_['Close'] = crtf.fill(x_['Close'].values)
        x_[i] = crtf.fill(x_[i].values)
        comb_sp_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
        comb_sp_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
        comb_sp_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
        comb_sp_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    _d_comb.store('SP_Beta_6m', comb_sp_beta)
    _d_comb.store('SP_Beta_3m', comb_sp_beta2)
    _d_comb.store('SP_Beta_9m', comb_sp_beta3)
    _d_comb.store('SP_Beta_12m', comb_sp_beta4)

    # # correlation with NUV
    # comb_sp_beta = comb_prices.copy()
    # comb_sp_beta2 = comb_prices.copy()
    # comb_sp_beta3 = comb_prices.copy()
    # comb_sp_beta4 = comb_prices.copy()
    # for i in comb_sp_beta.tick_cols():
    #     x_ = cruf.DataFrame.merge(comb_sp_beta[['Date', i]], nuv_prices[['Date', 'Close']], how='left', on='Date')
    #     x_.sort('Date')
    #     x_['Close'] = crtf.fill(x_['Close'].values)
    #     x_[i] = crtf.fill(x_[i].values)
    #     comb_sp_beta[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 120)
    #     comb_sp_beta2[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 60)
    #     comb_sp_beta3[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 180)
    #     comb_sp_beta4[i] = crtf.beta_cc(x_[i].values, x_['Close'].values, 240)
    # _d_comb.store('NUV_Beta_6m', comb_sp_beta)
    # _d_comb.store('NUV_Beta_3m', comb_sp_beta2)
    # _d_comb.store('NUV_Beta_9m', comb_sp_beta3)
    # _d_comb.store('NUV_Beta_12m', comb_sp_beta4)
    return None