Can deep learning predict the stock market? - YouTube

Channel: Leo Isikdogan

[0]
When you hear that 70% percent of trading volume in the entire US stock market is generated
[4]
by algorithms, you might think you are missing out something big.
[8]
Are we the only fools in the market who still trade the traditional way?
[11]
If the machines dominate the market today, do us mere mortals even stand a chance against
[16]
the mighty machines?
[17]
Well, a big chunk of that automated 70% is a result of high-frequency trading algorithms
[23]
trying to predict only milliseconds into the future.
[26]
And those algorithms usually use very very simple methods, nothing fancier than a chain
[31]
of hardcoded rules or a simple linear regression model.
[34]
So yes, if you race against milliseconds, then you do need to be a machine.
[39]
But for casual investors like us, that shouldn't really matter.
[42]
Or should it?
[44]
Deep learning models can learn much more complex patterns in data.
[47]
Is it possible to predict longer-term price movements in the market using deep learning?
[52]
Nobody knows for sure.
[54]
Many large financial institutions are hiring data scientists, machine learning engineers,
[59]
and deep learning experts with hefty salaries.
[62]
So, does that mean it works for sure?
[64]
Well, that may give us a sign about the trends in investing strategies, but institutional
[69]
investing can be different from individual investing.
[72]
For example, unless you are buying a very-low-volume stock, the shares you buy or sell barely have
[77]
any impact on the price.
[79]
But if you are buying and selling in large amounts, how you execute your trades can make
[83]
a big difference.
[84]
A machine learning model can help decide how you should split up your sales over time to
[89]
avoid causing big price movements.
[91]
To actually predict the price movements, you can try a lot of things.
[94]
From very simple things such as training LSTMs or Temporal Convolutional Networks on historical
[100]
prices to overly complex models such as training Convolutional LSTMs on satellite imagery to
[106]
predict macroeconomic movements.
[108]
Any predictive model you may build practically tries to find some inefficiencies in the market.
[113]
So, in a fully efficient market, none of these models should work.
[117]
For example, your model can analyze text from various sources, such as financial news websites
[122]
and social media, to decide whether a particular stock will go up or down.
[126]
You can do sentiment analysis at character level text or audio.
[130]
You can analyze not only what's in an earnings statement but also the way it's announced.
[134]
However, the efficient market hypothesis states that the stock prices reflect all available
[139]
and relevant information immediately.
[142]
It's likely that any new information that can impact the prices is already incorporated
[146]
in the price by the time your model gets to parse it from the web.
[150]
If you think this hypothesis is true, then using any data beyond the prices would be
[155]
redundant.
[156]
Then, should we just use nothing but the historical price information to build a predictive model?
[161]
That saves us a lot of trouble.
[163]
Technically, that's the opposite of what the hypothesis says.
[166]
But for now, let's forget about that and talk about what we can do with historical price
[170]
data.
[171]
Trying to forecast the direction of prices by finding patterns in past market data is
[175]
a form of technical analysis.
[177]
Day traders do this all the time.
[180]
They look at charts and name the patterns they see things like head and shoulders, cup
[184]
holders, shooting stars, etc.
[188]
Neural networks are very good at finding patterns in data.
[191]
If there are really such patterns, a neural network with enough capacity would be easily
[194]
able to pick up any patterns that might lead to profit.
[198]
Give a neural network a price chart, then it will fit a function to that chart as closely
[201]
as possible.
[202]
The problem is that being able to find patterns in past data doesn't mean that those patterns
[207]
will generalize and hold in the future as well.
[209]
A neural network can even find 'patterns' in completely random data.
[213]
But what the model actually learns wouldn't be any more useful than a lookup table.
[217]
A table that holds the price information for the past data while having no predictive power.
[222]
This is called overfitting, you can check out my earlier videos to learn more about
[226]
it.
[227]
Machine learning models are not the only ones who find patterns in data that don't exist.
[232]
Humans do too.
[233]
We see faces in the clouds and inanimate objects.
[236]
We see patterns in price charts and assume that the prices will regress to the mean.
[240]
I generated this chart, for example, completely randomly by changing the price by some random
[245]
percentage at each point.
[247]
Yet there seems to be some pattern.
[249]
So, I would be cautious about technical analysis.
[252]
There are so many books and success stories about how some authors got rich by doing technical
[257]
analysis, but honestly, most of those authors are getting rich by either writing the books
[262]
about how they got rich or they just happened to be lucky.
[265]
Yes, the odds of such luck is not very high, but there's a lot of survivorship bias.
[270]
Because losers hardly ever write books about their failure stories.
[274]
If you gather 1000 people in a room and ask them to predict coin flips, the odds of at
[278]
least one person predicting the outcome of 8 flips in a row is over 98%.
[284]
It takes only a room of people to find a clairvoyant.
[287]
There are many many more people trading in the market.
[290]
Earlier I mentioned that according to the efficient market hypothesis, any publicly
[294]
available information that might have an impact on the price of an asset has already done
[298]
it.
[299]
Past market data is publicly available information.
[301]
So, any information it might have, such as some patterns, is likely to be already in
[306]
the price in an efficient market.
[309]
Not all markets are efficient or rational, though.
[311]
For example, something as simple as the log-periodic power law model was able to predict the 2018
[316]
Bitcoin bubble 8 days before the bubble burst.
[319]
It doesn't mean that it will predict the next one, or whether there'll be another cryptocurrency
[323]
bubble at all.
[324]
Still, it's an interesting observation in hindsight.
[327]
Ok, let's say you want to experiment with machine learning models to predict the stock
[331]
market just for fun, so where to start?
[335]
You can start with defining the goal of your model and pick a corresponding loss function.
[339]
For example, if you want your model to pick the best stocks among some options, you can
[343]
treat this as an n-way classification problem and use a softmax cross-entropy as your loss
[348]
function.
[349]
If you want your model to give a rating between 0 and 1 to any given stock, then you can use
[353]
sigmoid cross entropy.
[354]
Next, you can go on to design your model architecture.
[358]
It doesn't have to be a sophisticated model.
[360]
You can stack one or two layers of LSTMs or gated recurrent units.
[364]
You can even use temporal convolutional networks, which are simple and easy to train.
[369]
You can check out my earlier video on recurrent models to learn more.
[372]
What about hardware?
[374]
GPUs are one of the first things that come to mind when the topic is machine learning.
[379]
In this particular case, you probably won't need any special hardware.
[382]
If you already have a GPU, then use it.
[384]
Otherwise, unless you plan to use some extraordinarily large volume data, any model that is too big
[389]
to train on a CPU will wildly overfit.
[392]
So, whatever hardware you already have will probably be enough to get started.
[396]
If you want to speed up your experiments using GPUs, you can always use cloud services and
[401]
pay as much as you use.
[403]
One of the problems we have with using stock market data in deep models is that we don't
[408]
have enough data to train a large model without overfitting.
[412]
To reduce the risk of overfitting, you can do all sorts of data preprocessing and augmentation.
[416]
For example, you can add a small amount of noise to your data.
[419]
Pick a random subset of stocks for each time interval at every epoch.
[425]
And Generate new samples by taking random linear combinations of existing stocks.
[429]
Those samples should essentially behave like randomly managed mutual funds or ETFs.
[434]
If you want to use data other than just price and volume information you can look into Google
[438]
Trends to see how much people are searching for particular keywords.
[442]
However, any signal you might get from there is likely to be lagged.
[446]
None of these will probably work.
[447]
So, I wouldn't expect too much.
[450]
But give it a try anyway, you'll learn a lot while you try even if it doesn't work.
[454]
If you find a trick that no one has found yet and it does work, have fun and enjoy the
[458]
profits.
[460]
Anything I say here is clearly not investment advice.
[462]
I don't have a financial background.
[464]
I'm a computer scientist who played a little bit with financial data in my spare time just
[468]
for fun.
[469]
I do have a decent amount of experience in machine learning, but my area of expertise
[473]
is its applications on imaging data.
[476]
Alright, that's all for today.
[477]
I hope you liked it.
[479]
Subscribe for more videos, while keeping in mind that this is not the type of videos that
[483]
I usually make.
[484]
And as always, thanks for watching, stay tuned, and see you next time.