def test_stationary(seed, method, axis, trend, n_samples): coint = CointAnalysis(method=method, axis=axis, trend=trend) x0 = make_stationary(seed=seed, n_samples=n_samples, n_series=1) x1 = make_nonstationary(seed=seed, n_samples=n_samples, n_series=1) X = np.concatenate([x0, x1], axis=1) assert coint.test(X).pvalue_ is np.nan
def test_coint_test(): X = np.random.randn(100, 2) with pytest.raises(ValueError): coint = CointAnalysis(method='hoge') coint.test(X) with pytest.raises(ValueError): coint = CointAnalysis(axis=2) coint.test(X) with pytest.raises(ValueError): coint = CointAnalysis(trend='ct') coint.test(X)
def main(): hyg = fetch_etf('HYG') bkln = fetch_etf('BKLN') X = np.array([hyg, bkln]).T coint = CointAnalysis() # pvalue pvalue = coint.test(X).pvalue_ print(f'pvalue: {pvalue}') # fit, transform spread = pd.Series(coint.fit_transform(X), index=hyg.index) print(f'coef: {coint.coef_}') print(f'mean: {coint.mean_}') print(f'std: {coint.std_}') # plot plot_prices(hyg, bkln) plot_adjust(hyg, bkln, coint) plot_spread(spread)
def test_notcointegrated(seed, method, axis, trend, gamma, n_samples): coint = CointAnalysis(method=method, axis=axis, trend=trend) X = make_notcointegrated(seed=seed, n_samples=n_samples, gamma=gamma) assert coint.test(X).pvalue_ > 0.1