Time for action – predicting price with a linear model
Keeping an open mind, let's assume that we can express a stock price p
as a linear combination of previous values, that is, a sum of those values multiplied by certain coefficients we need to determine:
In linear algebra terms, this boils down to finding a least-squares method (see https://www.khanacademy.org/math/linear-algebra/alternate_bases/orthogonal_projections/v/linear-algebra-least-squares-approximation).
Note
Independently of each other, the astronomers Legendre and Gauss created the least squares method around 1805 (see http://en.wikipedia.org/wiki/Least_squares). The method was initially used to analyze the motion of celestial bodies. The algorithm minimizes the sum of the squared residuals (the difference between measured
and predicted
values):
The recipe goes as follows:
First, form a vector
b
containingN
price values:b = c[-N:] b = b[::-1] print("b", x)
The result is as follows:
b [ 351.99 346.67 352.47 355.76 355.36]
Second...