end = '2018-01-01'
price = get_pricing('XOM', 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 logfit(x, a, b, c):
#return a * np.exp(-b * x) + c
return a * np.log(b * x) + c
#log(0) = -infinity, so x starts at 1
x = np.linspace(1,1+len(price),len(price))
coefficients, pcov = curve_fit(logfit, x, price.values)
print coefficients
print pcov
y = logfit(x, *coefficients)
f = pd.Series(y, index=price.index, name='log fit')
pd.concat([price, f], axis=1).plot()
#a, b, c value
[ 7.16530113 60.29273375 -7.21702861]
[[ 3.37758673e-02 4.82782411e+04 -5.73784558e+03]
[ 4.82782231e+04 3.17949296e+14 -3.77856886e+13]
[ -5.73784353e+03 -3.77856886e+13 4.49052185e+12]]
fit exxon mobile performance with log function
try fit for apple
try fit for deutsche bank
reference:http://chuanshuoge2.blogspot.com/2019/12/python-curve-fitting.html
No comments:
Post a Comment