OLS_Slope_InterceptN slope, intercept should be intercept, slope
neilsmurphy opened this issue · 3 comments
Andre Tavares posted this question in the community:
André Tavares 9 days ago
The class OLS_Slope_InterceptN calculates slope and intercept. However I think it is on the wrong order. It is as follows:
slope, intercept = sm.OLS(p0, p1).fit().params
I think the correct is:
intercept, slope = sm.OLS(p0, p1).fit().params
I am right?
The code in question can be found in the indicators/ols.py module at line 58.
My cursory look at statsmodel documentation suggests that the backtrader implementation is incorrect and backwards. \
Here are a few helpful links.
https://www.statsmodels.org/devel/generated/statsmodels.regression.linear_model.OLS.html
https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html
Thoughts?
Suggested solution by @rafaeltg:
Removing self.p.prepend_constant in order to avoid invalid result parameters order. With prepend = True intercept is the first parameter and slope the second.
There is a pull request for this in mementum/backtrader. I have asked the creator of the PR to issue it here.
Merged in mementum/backtrader.