end = '2018-01-01'
price = get_pricing('AAPL', fields='price', start_date=start, end_date=end)
price.plot()
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import pandas as pd
def expfit(x, a, b, c, d, e, f):
return a*np.exp(-(b*x*x+c*x+d))+e*x+f
x = np.linspace(1,1+len(price),len(price))
params, params_covariance = curve_fit(expfit, x, price.values )
print params
y = expfit(x, *params)
f = pd.Series(y, index=price.index, name='exp fit')
pd.concat([price, f], axis=1).plot()
[ 7.84216333e+01 5.57230815e-05 -7.13434301e-03 1.45807761e+00
5.84734404e-02 -4.80640750e+00]
[ 8.44865621e+00 1.29652892e-04 -1.37545875e-02 -1.42288153e+00
-1.96774039e-02 6.58394726e+01]
https://chuanshuoge2.blogspot.com/2019/12/quantopian-curve-fit-gaussian.html
No comments:
Post a Comment