Example #1
0
# 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)
crup.plot_ts(dt, x12_corr61[xidx])
x12_corr61 = crtf.cor_gk3(testo1, testc1, testo2, testc2, mi, smth=7, zl=False)
crup.plot_ts(dt, x12_corr61[xidx])
x12_corr61 = crtf.cor_pb(testo1, testh1, testl1, testc1, testo2, testh2, testl2, testc2, mi, smth=7, zl=False)
crup.plot_ts(dt, x12_corr61[xidx])
#
# x12_corr61 = crtf.cor_cc(testc1, testc2, mi, smth=13, zl=False)
# crup.plot_ts(dt, x12_corr61[xidx])

# x12_corr61 = crtf.cor_cc(testc1, testc2, mi, smth=19, zl=False)
# crup.plot_ts(dt, x12_corr61[xidx])

# x12_corr61 = crtf.cor_cc(testc1, testc2, mi, smth=7, zl=True)
# crup.plot_ts(dt, x12_corr61[xidx])
#
# x12_corr61 = crtf.cor_cc(testc1, testc2, mi, smth=13, zl=True)
# crup.plot_ts(dt, x12_corr61[xidx])
Example #2
0
np.corrcoef(testr1, testr2)[0, 1]
np.corrcoef(testrl1, testrl2)[0, 1]

np.mean(testr1*testr2)/np.sqrt(np.mean(testr1**2)*np.mean(testr2**2))
np.mean(testrl1*testrl2)/np.sqrt(np.mean(testrl1**2)*np.mean(testrl2**2))


cor_cc1 = crtf.cor_cc(testc1, testc2, 240, zl=False) #, smth=7)
cor_cc2 = crtf.cor_cc(testc1, testc2, 359.5, zl=False) #, smth=13)

crup.plot_ts(testc['Date'].values, cor_cc1)
crup.plot_ts(testc['Date'].values, cor_cc2)


cor_gk = crtf.cor_gk3(testo1, testc1, testo2, testc2, 240)
cor_pb = crtf.cor_pb(testo1, testh1, testl1, testc1, testo2, testh2, testl2, testc2, 240)

# cor_cc = crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(cor_cc, 5), 5), 5), 5), 5)
# cor_gk = crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(cor_gk, 5), 5), 5), 5), 5)
# cor_pb = crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(crtf.lrma(cor_pb, 5), 5), 5), 5), 5)

cor_cc = crtf.lrma(cor_cc, 15)
cor_gk = crtf.lrma(cor_gk, 15)
cor_pb = crtf.lrma(cor_pb, 15)

crup.plot_ts(testc['Date'].values, cor_cc)
crup.plot_ts(testc['Date'].values, cor_gk)
crup.plot_ts(testc['Date'].values, cor_pb)

x1 = crtf.ret(testc1)