Now that we have a baseline to compare with, let's build our first regression model. We're going to start with a very basic model using only the stock's prior closing values to predict the next day's close, and we're going to build it using a support vector regression. With that, let's set up our model:
- The first step is to set up a DataFrame that contains a price history for each day. We're going to include the past 20 closes in our model:
for i in range(1, 21, 1): sp.loc[:,'Close Minus ' + str(i)] = sp['Close'].shift(i) sp20 = sp[[x for x in sp.columns if 'Close Minus' in x or x == 'Close']].iloc[20:,] sp20
- This code gives us each day's closing price, along with the previous 20, all on the same line. The result of our code is seen in the following output...