from gekko import GEKKO import numpy as np import matplotlib.pyplot as plt import pandas as pd # Google stock url = 'http://apmonitor.com/che263/uploads/Main/goog.csv' # import data with pandas data = pd.read_csv(url) print(data['Close'][0:5]) print('min: '+str(min(data['Close'][0:20]))) print('max: '+str(max(data['Close'][0:20]))) # GEKKO model m = GEKKO() # input data x = m.Param(value=np.array(data['Open'])) # parameters to optimize a = m.FV() a.STATUS=1 b = m.FV() b.STATUS=1 c = m.FV() c.STATUS=1 # variables y = m.CV(value=np.array(data['Close'])) y.FSTATUS=1 # regression equation m.Equation(y==b*m.exp(a*x)+c) # regression mode m.options.IMODE = 2 # optimize m.options.solver = 1 m.solve(disp=True) # print parameters print('Optimized, a = ' + str(a.value[0])) print('Optimized, b = ' + str(b.value[0])) print('Optimized, c = ' + str(c.value[0])) # plot data plt.figure() plt.plot(data['Open'],data['Close'],'ro',label='Stock Data') plt.plot(x.value,y.value,'bx',label='Predicted') plt.xlabel('Open Price') plt.ylabel('Close Price') plt.legend() plt.show()