_tmp1 = int(_tmp[1:3])
    _tmp2 = np.sum(np.array(smth_param(int(_tmp[4:6]))))
    _tmp3 = int(_tmp[7:10])
    _tmp = _tmp1*_tmp2+_tmp3
    _penalty[z] = np.sqrt(np.sqrt(_tmp))

for z2 in [0.55, 0.65, 0.75, 0.85]:
    print('Processing threshold = %s' % str(z2))
    _mom_sig = []
    _mom_sig_idx = []
    _mom_val = []
    scorrel_vec = np.ones(num_col, dtype=bool)
    for z in range(0, 150):
        # z = 0
        if z == 0:
            _idx = bst.argmax_fixed(np.abs(correl_vec/_penalty))     # changed here
            _mom_sig.append(tcl2[_idx])
            _mom_sig_idx.append(_idx)
            _mom_val.append(correl_vec[_idx])
        else:
            scorrel_vec[_mom_sig_idx[-1]] = False       # new change to make it faster
            # for j1 in _mom_sig_idx:
            #     scorrel_vec[j1] = False
            for j1 in range(0, num_col):
                if scorrel_vec[j1]:     # and (j1 not in _mom_sig_idx), new change
                    # new change below to make it faster
                    if bst.kendall_tau(test2_all[tcl2[j1]].values, test2_all[tcl2[_mom_sig_idx[-1]]].values) > z2:
                        scorrel_vec[j1] = False
                    # for j2 in _mom_sig_idx:                     # new change to make it faster
                    #     if bst.kendall_tau(test2_all[tcl2[j1]].values, test2_all[tcl2[j2]].values) > z2:
                    #         scorrel_vec[j1] = False
예제 #2
0
    test1_ = test1[['Date', 'Close']]
    test1_['Returns'] = filt.ret(test1_['Close'].values)
    fret1 = test1_['Returns'].values / testv

    num_col = len(tcl2)
    correl_vec = np.zeros(num_col)
    for z in range(0, num_col):
        correl_vec[z] = bst.kendall_tau(fret1, test2[tcl2[z]].values)

    _mom_sig = []
    _mom_sig_idx = []
    _mom_val = []
    for z in range(0, 50):
        # z = 0
        if z == 0:
            _idx = bst.argmax_fixed(correl_vec)
            _mom_sig.append(tcl2[_idx])
            _mom_sig_idx.append(_idx)
            _mom_val.append(correl_vec[_idx])
        else:
            scorrel_vec = np.ones(num_col, dtype=bool)
            for j1 in _mom_sig_idx:
                scorrel_vec[j1] = False
            for j1 in range(0, num_col):
                if j1 not in _mom_sig_idx:
                    for j2 in _mom_sig_idx:
                        if scorrel_vec[j1] and (bst.kendall_tau(test2[tcl2[j1]].values, test2[tcl2[j2]].values)) > 0.95:
                            scorrel_vec[j1] = False
            scorrel_idx = np.where(scorrel_vec)[0]
            if scorrel_idx.shape[0] > 0:
                correl_red = correl_vec[scorrel_idx]