Skip to content

Instantly share code, notes, and snippets.

Created June 22, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/e4a62aada59ea4362225 to your computer and use it in GitHub Desktop.
Save anonymous/e4a62aada59ea4362225 to your computer and use it in GitHub Desktop.
OrdinaryLeastSquaredStatsModels
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