Posts

Showing posts from June 22, 2014

Market Prediction using Python Fitting Tools (Numpy, Scipy)

Image
[] In [1]: import numpy # Generate artificial data = straight line with a=0 and b=1 # plus some noise. # xdata = numpy.array([0.0,1.0,2.0,3.0,4.0,5.0]) xdata = numpy . array ([ 0.0 , 1.0 , 2.0 , 3.0 , 4.0 ]) # we will repace the original data into real data # ydata = numpy.array([0.1,0.9,2.2,2.8,3.9,7.1]) ydata = numpy . array ([ 10.4 , 10.5 , 11.5 , 13.0 , 15.1 ]) # Initial guess. x0 = numpy . array ([ 0.0 , 0.0 , 0.0 ]) In [2]: plot ( xdata , ydata , 'o-' ) Out[2]: [<matplotlib.lines.Line2D at 0xaf4fa72c>] In [3]: sigma = numpy . ones ( 5 ) print sigma [ 1. 1. 1. 1. 1.] In [4]: # The objective is defined by 2D polymer. def func ( x , a , b , c ): return a + b * x + c * x * x In [5]: import scipy.optimize as optimization results = optimization . curve_fit ( func , xdata , ydata , x0 , si