def test_OLSsummary_rsquared_label(self): # Check that the "uncentered" label is correctly added after rsquared x = [1, 5, 7, 3, 5, 2, 5, 3] y = [6, 4, 2, 7, 4, 9, 10, 2] reg_with_constant = OLS(y, x, hasconst=True).fit() assert 'R-squared:' in str(reg_with_constant.summary2()) assert 'R-squared:' in str(reg_with_constant.summary()) reg_without_constant = OLS(y, x, hasconst=False).fit() assert 'R-squared (uncentered):' in str(reg_without_constant.summary2()) assert 'R-squared (uncentered):' in str(reg_without_constant.summary())
def test_OLSsummary_rsquared_label(self): # Check that the "uncentered" label is correctly added after rsquared x = [1, 5, 7, 3, 5, 2, 5, 3] y = [6, 4, 2, 7, 4, 9, 10, 2] reg_with_constant = OLS(y, x, hasconst=True).fit() assert 'R-squared:' in str(reg_with_constant.summary2()) assert 'R-squared:' in str(reg_with_constant.summary()) reg_without_constant = OLS(y, x, hasconst=False).fit() assert 'R-squared (uncentered):' in str( reg_without_constant.summary2()) assert 'R-squared (uncentered):' in str(reg_without_constant.summary())
def test_ols_summary_rsquared_label(): # Check that the "uncentered" label is correctly added after rsquared x = [1, 5, 7, 3, 5, 2, 5, 3] y = [6, 4, 2, 7, 4, 9, 10, 2] reg_with_constant = OLS(y, add_constant(x)).fit() r2_str = 'R-squared:' with pytest.warns(UserWarning): assert r2_str in str(reg_with_constant.summary2()) with pytest.warns(UserWarning): assert r2_str in str(reg_with_constant.summary()) reg_without_constant = OLS(y, x, hasconst=False).fit() r2_str = 'R-squared (uncentered):' with pytest.warns(UserWarning): assert r2_str in str(reg_without_constant.summary2()) with pytest.warns(UserWarning): assert r2_str in str(reg_without_constant.summary())
result_et_hat_adf = GetADFuller(Y=et_hat, maxlags=1, regression='nc') print('ADF Statistic: %f' % result_et_hat_adf['adfstat']) #%% # Verifying above with statsmodel sm_result_et_hat_adf = adfuller(et_hat, maxlag=1, regression='nc', autolag=None, regresults=True) print(sm_result_et_hat_adf) resultols = OLS(Y1_t.T, Y2_t_d.T).fit() resultols.summary2() #%% # Plot OLS Fit # Generate equally spaced X values between the true X range x_axis = np.linspace(Y2_t.min(), Y2_t.max(), 100) #Plot the estimated dependent variable Y1_t_hat = a_hat + beta2_hat * x_axis # Plot own fit on top of seaborrn scatter + fit plt.title('Cointegrating Regression: Bitcoin and Ethereum') ax = sns.regplot(x=Y2_t_Series, y=Y1_t_Series, fit_reg=False) ax.plot(x_axis, Y1_t_hat, 'r') plt.legend(['OLS Fit', 'Real Values'], loc='lower right')
print "%0.4f" % my_res_adf['adfstat'] # ===== STABILITY CHECK ===== print key, np.abs(my_res_adf['roots']) print "passes stability check: {0}".format(is_stable(my_res_adf['roots'])) from statsmodels.regression.linear_model import OLS Y = y.diff()[1:] # must remove first element from array which is nan X = pd.concat([x.diff()[1:], e_t_hat.shift(1)[1:]], axis=1) X_c = add_constant(X) sm_res_ecm = OLS(Y, X).fit() # fit without constant sm_res_ecm_c = OLS(Y, X_c).fit() # fit without constant sm_res_ecm_c.summary2() sm_res_ecm.summary2() # ====== FIT TO OU PROCESS ====== # My implementations from analysis import my_AR # AR(p) model # Import statsmodels equivalents to validate results from statsmodels.tsa.ar_model import AR # Run AR(1) model with constant term with e_t_hat as endogenous variable my_res_ar = my_AR(endog=e_t_hat, maxlag=1, trend='c') sm_res_ar = AR(np.array(e_t_hat)).fit(maxlag=3, trend='c', method='cmle') # Stability Check