So in this lecture, we are going to do stock predictions once again, but this time our objective is
slightly different.
Instead of trying to forecast the return and effectively the price, we are going to simply try to predict
the direction.
So that should make the task much easier.
Instead of trying to predict a number which has an infinite number of choices, we're just going to
predict up or down, which is two choices.
Furthermore, to make this even easier.
We will only try to predict one step ahead.
So this is effectively the easiest task possible.
Let's see how machine learning will do.
OK, so notice that for our imports, we are now importing classifiers and not aggressives.
OK, so, again, we're going to download our data and choose IBM as our stock.
OK, so the new part here is how we create the data set, so for this data set, we're again going to
use a stationary time series as input, which comes from the log returns.
The target is simply whether the log return is positive or negative.
An easy way to compute there is to use greater than zero.
Multiplying by one is technically not necessary, but I like my targets to be zero and one instead of
true and false.
Notice how I'm using 21 lags for this script.
This is just to test the idea that maybe we can get better predictions if we use more lax.
OK, so basically the only difference in our loop now is that when we want to get the target, the target
no longer comes from the Time series itself.
Instead, it has been pre computed.
Other than that, it's the same as before.
OK, so the next step is to split our data into train and test.
The next step is to train a logistic regression.
OK, so the train accuracy is only about 50 percent, not great.
And the test accuracy is also only about 50 percent, so pretty much just as hard as predicting a coin
toss.
The next step is to train a support vector machine.
So this does better on the train set, but let's see whether or not it does better on the tests.
Unfortunately, it does not do better on the test set so we can conclude that the model just over fits.
The next step is to try the random forest.
OK, so the random forest gets 100 percent on the train set, which is not unsurprising given what we
have seen.
But the test set is, again, very close to 50 percent.
So, again, just in overfit model.
OK, so what we can conclude from this is that the linear model was the only model that did not overfit.
Now, again, I want to mention that the exercises and things you can try in this course are nearly
endless.
You might be wondering what if I included other columns such as open high in volume?
What if I included the returns of other stocks?
So these are all interesting things to try.
You should be able to test out these ideas with pretty much no new code.
So, as always, keep trying new things and I'll see you in the next lecture.