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 cum_spec(x): ny = crtf.fst_nan(x) n = x.shape[0] y = np.empty(n)*np.nan y[ny:n] = np.cumsum(x[ny:n]) return y
# # --- 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]) # # #