OrdinaryLeastSquaredStatsModels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_ordinary_least_squares(ols_dates, ols_data, statsmodels_settings): | |
""" | |
This method receives the dates and prices of a Quandl data-set as well as settings for the StatsModels package, | |
it then calculates the regression lines and / or the confidence lines are returns the objects | |
""" | |
intercept = np.column_stack((ols_dates, ols_dates ** statsmodels_settings.exponent)) | |
constant = sm.add_constant(intercept) | |
statsmodel_regression = sm.OLS(ols_prices, constant).fit() | |
print(statsmodel_regression.summary()) | |
if statsmodels_settings.confidence: | |
prstd, lower, upper = wls_prediction_std(statsmodel_regression) | |
return statsmodel_regression, lower, upper | |
else: | |
return statsmodel_regression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment