Example #1
0
def _get_signals(i):
    # i = 'SP500'
    print('Calculating signals for %s ' % i)
    univ_ib_aret = mkt_retrieve(i, 'Stats', 'AltReturns')
    tick_cols = univ_ib_aret.tick_cols()

    univ_ib_sig = univ_ib_aret[['Date', 'Date']]
    univ_ib_sig.set_columns(['Date', 'Dummy'])

    for k in tick_cols:
        for jidx, j in enumerate(_lbck):
            univ_ib_sig[k + '_' + _lbck_name[jidx] + '_' + 'LRB'] = filt.lrbeta(univ_ib_aret[k].values, j)
            univ_ib_sig[k + '_' + _lbck_name[jidx] + '_' + 'QRB'] = filt.qrbeta(univ_ib_aret[k].values, j)
            univ_ib_sig[k + '_' + _lbck_name[jidx] + '_' + 'QRG'] = filt.qrgamma(univ_ib_aret[k].values, j)
    del univ_ib_sig['Dummy']
    mkt_store(i, 'MovReg', 'Signals', univ_ib_sig)
    return None
Example #2
0
def _get_specific_signals(i):
    print('Calculating limited set of signals for %s' % i)
    univ_ib_aret = mkt_retrieve(i, 'Stats', 'AltReturns')

    for ski, sk in enumerate(_sig_sets):
        univ_ib_sig = univ_ib_aret[['Date', 'Date']]
        univ_ib_sig.set_columns(['Date', 'Dummy'])
        for k in sk:
            _col_to_use = k[0:6]
            _val_to_use = float(k[7:10])
            _opr_to_use = k[11:14]
            if _opr_to_use == 'LRB':
                univ_ib_sig[k] = filt.lrbeta(univ_ib_aret[_col_to_use].values, _val_to_use)
            elif _opr_to_use == 'QRB':
                univ_ib_sig[k] = filt.qrbeta(univ_ib_aret[_col_to_use].values, _val_to_use)
            else:
                univ_ib_sig[k] = filt.qrgamma(univ_ib_aret[_col_to_use].values, _val_to_use)
        del univ_ib_sig['Dummy']
        mkt_store(i, 'MovReg', 'Signals' + _sig_sets_name[ski], univ_ib_sig)
    return None
def movreg_qr(x, m):
    y1 = filt.qrbeta(x, m)
    y2 = filt.qrgamma(x, m)
    return y1+y2*(2*m+1)
def movreg_qrg(x, m):
    return filt.qrgamma(x, m)*(2*m+1)
def get_measures():
    univ_ib_gd = cr_cret.retrieve(univ_ib_eqidx_ext + "ExchOpen")

    _prc_measures = [
        "Close",
        "AdjSer20D",
        "AdjSer30D",
        "AdjSer40D",
        "AdjSer20W",
        "AdjSer30W",
        "AdjSer40W",
        "AdjSer20M",
        "AdjSer30M",
        "AdjSer40M",
    ]
    _prc_measures_name = ["CLS", "A2D", "A3D", "A4D", "A2W", "A3W", "A4W", "A2M", "A3M", "A4M"]
    tick_cols = univ_ib_gd.tick_cols()

    for k in range(0, 10):  # for different prices
        univ_ib_pr = cr_cret.retrieve(univ_ib_eqidx_ext + _prc_measures[k])

        for j in range(5, 305, 5):
            univ_ib_lrbeta_lvl = nan_df(univ_ib_pr)
            univ_ib_qrbeta_lvl = nan_df(univ_ib_pr)
            univ_ib_qrgamm_lvl = nan_df(univ_ib_pr)

            univ_ib_lrbeta_ch0 = nan_df(univ_ib_pr)
            univ_ib_qrbeta_ch0 = nan_df(univ_ib_pr)
            univ_ib_qrgamm_ch0 = nan_df(univ_ib_pr)

            univ_ib_lrbeta_ch1 = nan_df(univ_ib_pr)
            univ_ib_qrbeta_ch1 = nan_df(univ_ib_pr)
            univ_ib_qrgamm_ch1 = nan_df(univ_ib_pr)

            univ_ib_lrbeta_ch2 = nan_df(univ_ib_pr)
            univ_ib_qrbeta_ch2 = nan_df(univ_ib_pr)
            univ_ib_qrgamm_ch2 = nan_df(univ_ib_pr)

            for i in tick_cols:
                z = np.where(univ_ib_gd[i].values.astype("int") == 1)[0]
                univ_ib_pr_ = univ_ib_pr[i].values[z]

                univ_ib_lrb_ = filt.lrbeta(univ_ib_pr_, j)
                univ_ib_lrbeta_lvl[list(z), i] = univ_ib_lrb_
                univ_ib_lrbeta_ch0[list(z), i] = filt.chg(univ_ib_lrb_, 1)
                univ_ib_lrbeta_ch1[list(z), i] = filt.chg(univ_ib_lrb_, 3)
                univ_ib_lrbeta_ch2[list(z), i] = filt.chg(univ_ib_lrb_, 5)

                univ_ib_qrb_ = filt.qrbeta(univ_ib_pr_, j)
                univ_ib_qrbeta_lvl[list(z), i] = univ_ib_qrb_
                univ_ib_qrbeta_ch0[list(z), i] = filt.chg(univ_ib_qrb_, 1)
                univ_ib_qrbeta_ch1[list(z), i] = filt.chg(univ_ib_qrb_, 3)
                univ_ib_qrbeta_ch2[list(z), i] = filt.chg(univ_ib_qrb_, 5)

                univ_ib_qrb_ = filt.qrgamma(univ_ib_pr_, j)
                univ_ib_qrgamm_lvl[list(z), i] = univ_ib_qrb_
                univ_ib_qrgamm_ch0[list(z), i] = filt.chg(univ_ib_qrb_, 1)
                univ_ib_qrgamm_ch1[list(z), i] = filt.chg(univ_ib_qrb_, 3)
                univ_ib_qrgamm_ch2[list(z), i] = filt.chg(univ_ib_qrb_, 5)

                univ_ib_lrbeta_lvl[i] = filt.fill(univ_ib_lrbeta_lvl[i].values)
                univ_ib_lrbeta_ch0[i] = filt.fill(univ_ib_lrbeta_ch0[i].values)
                univ_ib_lrbeta_ch1[i] = filt.fill(univ_ib_lrbeta_ch1[i].values)
                univ_ib_lrbeta_ch2[i] = filt.fill(univ_ib_lrbeta_ch2[i].values)

                univ_ib_qrbeta_lvl[i] = filt.fill(univ_ib_qrbeta_lvl[i].values)
                univ_ib_qrbeta_ch0[i] = filt.fill(univ_ib_qrbeta_ch0[i].values)
                univ_ib_qrbeta_ch1[i] = filt.fill(univ_ib_qrbeta_ch1[i].values)
                univ_ib_qrbeta_ch2[i] = filt.fill(univ_ib_qrbeta_ch2[i].values)

                univ_ib_qrgamm_lvl[i] = filt.fill(univ_ib_qrgamm_lvl[i].values)
                univ_ib_qrgamm_ch0[i] = filt.fill(univ_ib_qrgamm_ch0[i].values)
                univ_ib_qrgamm_ch1[i] = filt.fill(univ_ib_qrgamm_ch1[i].values)
                univ_ib_qrgamm_ch2[i] = filt.fill(univ_ib_qrgamm_ch2[i].values)

            if j < 10:
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_LVL_00" + str(j), univ_ib_lrbeta_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH0_00" + str(j), univ_ib_lrbeta_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH1_00" + str(j), univ_ib_lrbeta_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH2_00" + str(j), univ_ib_lrbeta_ch2
                )

                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_LVL_00" + str(j), univ_ib_qrbeta_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH0_00" + str(j), univ_ib_qrbeta_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH1_00" + str(j), univ_ib_qrbeta_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH2_00" + str(j), univ_ib_qrbeta_ch2
                )

                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_LVL_00" + str(j), univ_ib_qrgamm_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH0_00" + str(j), univ_ib_qrgamm_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH1_00" + str(j), univ_ib_qrgamm_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH2_00" + str(j), univ_ib_qrgamm_ch2
                )
            elif j < 100:
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_LVL_0" + str(j), univ_ib_lrbeta_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH0_0" + str(j), univ_ib_lrbeta_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH1_0" + str(j), univ_ib_lrbeta_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH2_0" + str(j), univ_ib_lrbeta_ch2
                )

                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_LVL_0" + str(j), univ_ib_qrbeta_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH0_0" + str(j), univ_ib_qrbeta_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH1_0" + str(j), univ_ib_qrbeta_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH2_0" + str(j), univ_ib_qrbeta_ch2
                )

                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_LVL_0" + str(j), univ_ib_qrgamm_lvl
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH0_0" + str(j), univ_ib_qrgamm_ch0
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH1_0" + str(j), univ_ib_qrgamm_ch1
                )
                cr_sig_mr_sg.store(
                    univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH2_0" + str(j), univ_ib_qrgamm_ch2
                )
            else:
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_LVL_" + str(j), univ_ib_lrbeta_lvl)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH0_" + str(j), univ_ib_lrbeta_ch0)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH1_" + str(j), univ_ib_lrbeta_ch1)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_LRB_CH2_" + str(j), univ_ib_lrbeta_ch2)

                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_LVL_" + str(j), univ_ib_qrbeta_lvl)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH0_" + str(j), univ_ib_qrbeta_ch0)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH1_" + str(j), univ_ib_qrbeta_ch1)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRB_CH2_" + str(j), univ_ib_qrbeta_ch2)

                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_LVL_" + str(j), univ_ib_qrgamm_lvl)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH0_" + str(j), univ_ib_qrgamm_ch0)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH1_" + str(j), univ_ib_qrgamm_ch1)
                cr_sig_mr_sg.store(univ_ib_eqidx_ext + _prc_measures_name[k] + "_QRG_CH2_" + str(j), univ_ib_qrgamm_ch2)
    return None