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
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) test1 = test1[testidx] test2 = test2[testidx] testc = test1*test2/np.sqrt((test1**2)*(test2**2)) dt = test['Date'].values