Example #1
0
testh2 = testh[tic2].values
testl1 = testl[tic1].values
testl2 = testl[tic2].values

x1 = crtf.ret(testc1)
x2 = crtf.ret(testc2)
xidx = ~np.isnan(x1) & ~np.isnan(x2)
x1 = x1[xidx]
x2 = x2[xidx]
dt = testc['Date'].values
dt = dt[xidx]

# static
x_act = np.corrcoef(x1, x2)[0, 1]
x12_act = np.ones(x1.shape[0])*x_act
crup.plot_ts(dt, x12_act)

# base case
n = x1.shape[0]
mi = 240
mi2 = (2*mi+1)/3
# x12_corr2 = np.ones(n)*np.nan
# x12_corr2 = (crtf.ema(x1*x2, mi)-crtf.ema(x1, mi)*crtf.ema(x2, mi))/\
#             np.sqrt((crtf.ema(x1**2, mi)-crtf.ema(x1, mi)**2)*(crtf.ema(x2**2, mi)-crtf.ema(x2, mi)**2))
# crup.plot_ts(dt, x12_corr2)
# x12_corr2 = np.ones(n)*np.nan
# x12_corr2 = (crtf.sma(x1*x2, mi)-crtf.sma(x1, mi)*crtf.sma(x2, mi))/\
#             np.sqrt((crtf.sma(x1**2, mi)-crtf.sma(x1, mi)**2)*(crtf.sma(x2**2, mi)-crtf.sma(x2, mi)**2))
# crup.plot_ts(dt, x12_corr2)

x12_corr61 = crtf.cor_cc(testc1, testc2, mi, smth=7, zl=False)
Example #2
0
xdt_ = xdt_[-3:-1]

xview = [i for i, j in enumerate(xdt) if j.astype('datetime64[Y]') in xdt_]
hl = np.zeros(xpr.shape[0])

# xprs1 = crtf2.lrma(xpr, 30, lg=True)
# xprs2 = crtf2.lrma2(xpr, 30, lg=True)
xprs3 = crtf2.lrma3(xpr, 30, lg=True)

# xr1 = crtf2.ret(xprs1)
# xr2 = crtf2.ret(xprs2)
xr3 = crtf2.ret(xprs3)

pl.figure(2)
pl.subplot(311)
crup.plot_ts(xdt[xview], xpr[xview])
# crup.plot_ts(xdt[xview], xprs1[xview])
# crup.plot_ts(xdt[xview], xprs2[xview])
crup.plot_ts(xdt[xview], xprs3[xview])

pl.subplot(312)
crup.plot_ts(xdt[xview], hl[xview])
m = 30
# xr1_ = crtf2.return_estimates_normal(xr1, m)
# crup.plot_ts(xdt[xview], xr1_[xview])
# xr2_ = crtf2.return_estimates_normal(xr2, m)
# crup.plot_ts(xdt[xview], xr2_[xview])
xr3_ = crtf2.return_estimates_normal(xr3, m)
crup.plot_ts(xdt[xview], xr3_[xview])

Example #3
0
        Y[i] = Ym[i]




    print(i)
    print(Value[0:20])
    print(Yg[0:20])
    print(Wg[0:20])
    print(WgCs[0:20])
    print(jIdx)
    print(WgCs[jIdx])
    print(Ym[0:25])
    print(Y[0:25])

crup.plot_ts(x['Date'].values, Input)
crup.plot_ts(x['Date'].values, Y)
Y2 = crtf.ema(Input, Periods)
crup.plot_ts(x['Date'].values, Y2)




#
# def mma(x, m, lg=False):
#     n = x.shape[0]
#     ny = crtf.fst_nan(x)
#     mi = int(m)
#     x1 = crtf.fill(x)
#     y = np.empty(n)*np.nan
#     ym = np.empty(n)*np.nan
Example #4
0
def _smoother(x, m):
    return crtf.fish_inv_trans(crtf.lrbeta(crtf.cumsum_special(crtf.fish_trans(x)), m, lg=False))


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)