Quantitative Risk Management in Python
Jamsheed Shorish
Computational Economist
statsmodels
's OLS
object over full period 1950 - 2019res.ssr
import statsmodels.api as sm res = sm.OLS(log_pop, year).fit()
print('SSR 1950-2019: ', res.ssr)
SSR 1950-2019: 0.29240576138055463
res_before.ssr
and res_after.ssr
pop_before = log_pop.loc['1950':'1989']; year_before = year.loc['1950':'1989']; pop_after = log_pop.loc['1990':'2019']; year_after = year.loc['1990':'2019'];
res_before = sm.OLS(pop_before, year_before).fit() res_after = sm.OLS(pop_after, year_after).fit()
print('SSR 1950-1989: ', res_before.ssr) print('SSR 1990-2019: ', res_after.ssr)
SSR 1950-1989: 0.011741113017411783
SSR 1990-2019: 0.0013717593339608077
numerator = (ssr_total - (ssr_before + ssr_after)) / 2
denominator = (ssr_before + ssr_after) / 66
chow_test = numerator / denominator print("Chow test statistic: ", chow_test, "; Critical value, 99.9%: ", 7.7)
Chow test statistic: 702.8715822890057; Critical value, 99.9%: 7.7
Quantitative Risk Management in Python