Skip to content

Instantly share code, notes, and snippets.

@blakesanie
Created August 6, 2019 00:13
Show Gist options
  • Save blakesanie/44924ee4fb6ea89ea36c869bfe76d9e6 to your computer and use it in GitHub Desktop.
Save blakesanie/44924ee4fb6ea89ea36c869bfe76d9e6 to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn.linear_model import LinearRegression
def exponentialRegression(closing):
x = np.arange(1,len(closing) + 1).reshape((-1, 1))
y_normalized = np.divide(closing, closing[0])
y_ln = np.log(y_normalized)
model = LinearRegression()
model.fit(x, y_ln)
scalar = np.exp(model.intercept_) * closing[0]
base = np.power(np.exp(model.coef_)[0], 252)
rSquared = model.score(x, y_ln)
return {
"scalar": scalar,
"roi": ((base - 1) * 100),
"r2": rSquared
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment