Beispiel #1
0
def _refresh_signals(x):
    _d_comb, _d_sig = x
    # generate the signals (type 1)
    comb_prices = _d_comb.retrieve('Close')
    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 the signals (type 2)
    comb_ret = _d_comb.retrieve('Returns')
    for j in range(1, 51):
        comb_ret_lr = comb_ret.copy()
        comb_ret_qr = comb_ret.copy()
        for i in comb_ret_lr.tick_cols():
            comb_ret_qr[i] = crtf.lrma(crtf.lrma(crtf.qrma(comb_ret_qr[i].values, j*10), 5), 5)
            comb_ret_lr[i] = crtf.lrma(crtf.lrma(crtf.lrma(comb_ret_qr[i].values, j*10), 5), 5)
        _d_sig.store('QrS_'+str(j*10)+'D', comb_ret_qr)
        _d_sig.store('LrS_'+str(j*10)+'D', comb_ret_lr)
        del comb_ret_lr
        del comb_ret_qr
    return None
Beispiel #2
0
def _spear(x1, x2, m):
    n = x1.shape[0]
    xix = np.empty(n)*np.nan
    ny = np.maximum(crtf.fst_nan(x1), crtf.fst_nan(x2))
    if ny+m < n:
        for i in range(ny+m, n):
            xix[i] = _spearman(x1[i-m:i], x2[i-m:i])
        xix_ = crtf.fish_inv_trans(crtf.lrbeta(crtf.cumsum_special(crtf.fish_trans(xix)), 7, lg=False))
        xix1 = np.empty(n)*np.nan
        ny = crtf.fst_nan(xix_)
        xix1[ny+7*3:] = xix_[ny+7*3:]
        return xix1
    else:
        return xix
Beispiel #3
0
# x12_corr6[ny+7*3:] = x12_corr6_[ny+7*3:]
# crup.plot_ts(dt, x12_corr6)
#

# ---

x12_corr2 = np.ones(n)*np.nan
x12_corr2 = 3*crtf.ema(x1*x2, mi2)/np.sqrt(crtf.ema(x1**2, mi2)*crtf.ema(x2**2, mi2))-\
            2*crtf.ema(x1*x2, mi)/np.sqrt(crtf.ema(x1**2, mi)*crtf.ema(x2**2, mi))
crup.plot_ts(dt, x12_corr2)


x12_corr1_ft = crtf.fish_trans(x12_corr2)
x12_corr1_ft_c = cum_spec(x12_corr1_ft)
# x12_corr1_ft_sm = 6*(crtf.ema(x12_corr1_ft_c, 5)-crtf.ema(x12_corr1_ft_c, 7))/(7-1)
x12_corr1_ft_sm = crtf.lrbeta(x12_corr1_ft_c, 5, lg=False)
x12_corr6_ = crtf.fish_inv_trans(x12_corr1_ft_sm)
ny = crtf.fst_nan(x12_corr6_)
x12_corr6 = np.empty(x12_corr6_.shape[0])*np.nan
x12_corr6[ny+7*2:] = x12_corr6_[ny+7*2:]
crup.plot_ts(dt, x12_corr6)

x12_corr3 = crtf.cor_cc(testc1, testc2, mi)
crup.plot_ts(dt, x12_corr3[xidx])

# import matplotlib.pyplot as plt
# plt.figure(2)
# crup.plot_ts(dt, testc1[xidx])
# plt.figure(3)
# crup.plot_ts(dt, testc2[xidx])
#
Beispiel #4
0
def _smoother(x, m):
    return crtf.fish_inv_trans(crtf.lrbeta(crtf.cumsum_special(crtf.fish_trans(x)), m, lg=False))
Beispiel #5
0
window = 241
window1 = int((3*window-1)/2)
window2 = int((2*window+1)/3)
for i in range(window1, n):
    # i = n
    test_c1[i] = stats.spearmanr(testr1[i-window2:i], testr2[i-window2:i])[0]
    test_c2[i] = stats.spearmanr(testr1[i-window:i], testr2[i-window:i])[0]
    test_c3[i] = stats.spearmanr(testr1[i-window1:i], testr2[i-window1:i])[0]

dt = testc['Date'].values
dt = dt[test_idx]
crup.plot_ts(dt, crtf.fish_trans(test_c1))
crup.plot_ts(dt, crtf.fish_trans(test_c2))
crup.plot_ts(dt, crtf.fish_trans(test_c3))

test_c4= crtf.fish_inv_trans(crtf.lrbeta(crtf.cumsum_special(crtf.fish_trans(test_c2)), 7, lg=False))
crup.plot_ts(dt, test_c4)

test_c5 = crtf.fish_inv_trans(crtf.lrbeta(crtf.cumsum_special(crtf.fish_trans(3*test_c2-2*test_c3)), 7, lg=False))
crup.plot_ts(dt, test_c5)

#------------------------------------

test = d_comb[6].retrieve('Close')
test1 = crtf.ret(test['SPY'].values)
test2 = crtf.ret(test['TLT'].values)
testidx = ~np.isnan(test1) & ~np.isnan(test2)
test1 = test1[testidx]
test2 = test2[testidx]
testc = test1*test2/np.sqrt((test1**2)*(test2**2))
dt = test['Date'].values