HomeОбразованиеRelated VideosMore From: Siraj Raval

How to Predict Stock Prices Easily - Intro to Deep Learning #7

5654 ratings | 437107 views
We're going to predict the closing price of the S&P 500 using a special type of recurrent neural network called an LSTM network. I'll explain why we use recurrent nets for time series data, and why LSTMs boost our network's memory power. Coding challenge for this video: https://github.com/llSourcell/How-to-Predict-Stock-Prices-Easily-Demo Vishal's winning code: https://github.com/erilyth/DeepLearning-SirajologyChallenges/tree/master/Image_Classifier Jie's runner up code: https://github.com/jiexunsee/Simple-Inception-Transfer-Learning More Learning Resources: http://colah.github.io/posts/2015-08-Understanding-LSTMs/ http://deeplearning.net/tutorial/lstm.html https://deeplearning4j.org/lstm.html https://www.tensorflow.org/tutorials/recurrent http://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/ https://blog.terminal.com/demistifying-long-short-term-memory-lstm-recurrent-neural-networks/ Please subscribe! And like. And comment. That's what keeps me going. Join other Wizards in our Slack channel: http://wizards.herokuapp.com/ And please support me on Patreon: https://www.patreon.com/user?u=3191693 music in the intro is chambermaid swing by parov stelar Follow me: Twitter: https://twitter.com/sirajraval Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/ Signup for my newsletter for exciting updates in the field of AI: https://goo.gl/FZzJ5w
Html code for embedding videos on your blog
Text Comments (588)
Andrey Stroganov (1 day ago)
Validating your model on a training dataset is a bullshit. Try to validate it on unseen data, and you'll see the real "power" of your model.
John Mason (2 days ago)
Investors don't share any of the information they have. A sharing of information dilutes the effect. Remember this.
Praveen K (5 days ago)
Siraj, I like your videos but could you reduce the memes
Lê Hưng (8 days ago)
if he can make money by prediction, he won't have to become youtuber for sure haha
John (10 days ago)
4:22 this is literally the Heisenberg uncertainty principle in real life :0
Sudeep Dasgupta (12 days ago)
Stock prediction is very versatile, you cant predict with mathematical calculations only there is no formula for that. There are lots of factors matters for stock prices going up and low. Its just probabilistic values
THECCCUT (14 days ago)
Lol that Chief Keef in the outro :)
Robialmay Naufalmahdy (15 days ago)
anyone notice young RDJ?
harvinder arora (22 days ago)
Siraj I have a value error. Normalised_window = [(float(p) / float(window[0])) - 1) for p in window] could not convert string into float HELP!
TheOldSnake (1 month ago)
Just fyi, Burton Malkiel is the guy who doesn't know how to invest so he wrote a book tell you it can't be done. Read & watch Buffett, Munger, Benjamin Graham,...
Bob Crunch (1 month ago)
I looked at the challenge code, and here is my analysis. The code is in Python2, so there are some issues there. The two print statements must be changed. The xrange() function is deprecated in Python3 so must changed to range(). If the argument is a float, it must be cast to int. Other than that, it ran well (I copied the code in the Notebook and put in a separate .py program). It ran with the supplied sp500 data, and I created an AAPL (Apple) data file from Yahoo Finance. It ran well, but to get anything meaningful, it should cover at least ten years price history. Right now, I'm analyzing the outputs and see if they are meaningful and really useful for stock trading. As an exercise, I created a virtualenv and installed the TensorFlow and Keras there. It worked great except for the Notebook because I only had Python3 in the environment.
Alhasby Pranaja (1 month ago)
I have had my share of ups and downs when it comes to trading Forex and stock. Now, all I do is win, I mean I make thousands of dollars daily using The *Blended Model Strategy* if you have not heard about it all you have to do is find out about it on google +, The creator is *Dmitry Vladislav* and remember to save this link to thank me later.
Bob Crunch (1 month ago)
Andrew, thank you for the reply. I'm a little rusty at Python and was trying a lot of things quickly. Maybe I'll go back and investigate. For now, I'm just happy everything works. When I was researching range(), I found that in Python2, range() creates a list, but xrange() creates a generator that provides values as they are needed (better if the range is large). Python3 range() adapts to the application so xrange() is deprecated. BTW, I'm running on Ubuntu 18.04 "Bionic Beaver".
Andrew Tseng (1 month ago)
Yep, you are right. Just tried the code. not sure why the code could run when you have a float in range.
MrGreenT (1 month ago)
would this also work for fx trading, like currencies
M.K. Ultra (1 month ago)
This is more just an example of how LSTM recurrent networks work, for any real trading you would want to build a much more complex network and feed it a lot more relevant data such as market sentiment, etc in order to get a better prediction.
Marc Bergeron (1 month ago)
Stock prices are determined by expected future value of a company. This kind of pattern detection by looking at backwards data is not a method that actually predicts anything other than trends in larger economic cycles. Do not get me wrong, the tool itself is great, but anyone serious about trying to predict stock prices should look into the reasons stocks fluctuate and model those variable into a time series.
Pushkar Deshpande (1 month ago)
you talked for 10 minutes and gave 0 information. Your channel name should be 'Redundancy Guru'
Rick Snapp (2 months ago)
Wtf
panagranit pana (2 months ago)
It is amazing that your code in the Jyupter note book is so short.
NutHouseProductionz (2 months ago)
Wish I could understand what he is talking about.
Steven F (2 months ago)
Great content, but the memes were cringy lol
Victor Chan (2 months ago)
can i use the output from 2 different independent LSTM networks to feed into a 3rd LSTM network to create the overall network? would it be the same 1 LSTM network which uses all inputs from the 2 LSTMs?
mahchymk93 (2 months ago)
I mean blind monkeys are hard to come by....
ahhahhahahhahaha you make me lough too much man, take my suscribe XD
ayma kam (2 months ago)
Is there any body chasing you ?? why do you speak so rapidly that we can hardly catch any word ??. For God sake solw down a little bit :) :D
Abitamim Bharmal (3 months ago)
That clip of scientists on front of computers was 100% Asian. What has America come to?
Goby Swiss (3 months ago)
I can predict googles stock price in less than a minute looking at the chart. It’s easy
Crypto Mustache (3 months ago)
Still think. almost 2 years later, this video to be the most hilarious you ever done. The clip with the bonzai I lough everytime.
subhasish (3 months ago)
wait, Tony Stark was stock broker @0.38 before? That's how he made the money.
John Parz (3 months ago)
I don't understand what the input format is supposed to be, you only show 1 variable the closing price, what data goes into x_train and y_train? How do you load the time series data?
John Parz (3 months ago)
What data types are they, singular dimension array, multiple dimension array?
Eric Lamey (3 months ago)
Siraj: Great stuff thank you! Question, could you do a video that is more like "day trading?" Instead of just a single closing price each day, how to use multiple prices each day? Example data set for one month would be 20 (trading days) with 80 price samples (10 per hour).
BEPEC (3 months ago)
Yes, We can predict stock prices.
Rohit Singh (3 months ago)
how to start the code editor?
Ujjawal Ujjawal (3 months ago)
Impossible
Ken Semotiuk (3 months ago)
Why try to predict a rugged market, go drink beer and enjoy life!
Kevin Cawley (3 months ago)
What's the song called in the beginning?
what does print 'yo' in the 17th line in lstm.py mean?
Hydroman 7 (3 months ago)
Hi Siraj, 1st up ....wow!! Love the logic flow of the application but have zip coding skill (VBa does not count) and not even familiar with the interfaces shown. So how would a simpleton engineer apply this using an excel spreadsheet? could Excel even handle this? Can't call up the functions that you did in your code so would need to write the equations and functions needed. I want to replicate the logic process utilising the underlying equations and functions to analysis a data set in excel ?? Possible??
mrjohnsuen (4 months ago)
I use latest version of Mathamatica to build the LSTM as the package now comes with Netgraph and LSTM..
Harsh agrawal (4 months ago)
How to predict a sequence(multiple timesteps) using lstm is not clear
N64 Classics (5 months ago)
Enjoyed the memes and cut scenes throughout
Aniket Banginwar (5 months ago)
0:38 Is that Robert Downey Jr. ????
Follow meback2 (5 months ago)
Can u make example with him stock.
Hr. m (5 months ago)
My brain just exploded :/
Svetlana S (5 months ago)
New H.W.A Phoenix 5.0 trading tool is Rated for the outstanding performance capacity towards the previous Version Phoenix 4.5, I trade on High & Low and I am using this amazing trading tool with over 93.4% performance rating, (that's a good score). I recommend HEADWAYANALYSIS from my personal trading experience.
dan ashton (5 months ago)
you lost me very early haha
Luxe Travel Channel (5 months ago)
I think I'll stick with point and figure charting...lol...
DJ Porter (5 months ago)
Does anyone have the link to the video with the challenge winners that was presented in this video? I.e. predicting google with three features.
DJ Porter (5 months ago)
Found it. https://youtu.be/Oex0eWoU7AQ
Umair Rehman (6 months ago)
make a video on KG method please
Winston K (6 months ago)
I understood some of those terms and words.
Marc Djandji (6 months ago)
Quick question: What are the helper libraries that were imported using (import lstm,time)? Thanks in advance
GOLD & GHOSTS (6 months ago)
EOS is👑💪🤑🤑🤑🤑🤑🤑🤑🤑🤑
BigBadBurrow (6 months ago)
What I find a little odd is that trading was previously done by humans, so it had human emotion (hope, fear, greed) as factors in how stocks were traded. But what we're now doing is training computer models to mimic past human behaviour. If just a few people were doing this, then okay they probably have a big advantage, but when everyone is doing it then it seems to kinda detach from reality. Also, as time goes on and fewer humans are making trading decisions then we'll have to train computer models to react to how other computer models are behaving, which are themselves behaving to how other computer models are behaving. I dunno... something doesn't sit right.
Swapnil Bhadade (6 months ago)
waste
Disis Rabu (6 months ago)
You talk too much..wheres the code?where the code is predicting markets and where the predictions coming true???
TenthYoung (6 months ago)
You have the hand motions of a freestyle rapper
Winston Smith (6 months ago)
Only in the movie Pi, with the mean mega chip, can a computer predict tomorrow's price.
a. m. (6 months ago)
That's pretty much a mumbo jumbo model. The "cheat" that makes the model seem to perform that good, is in the normalization (see the lstm.py from the source https://github.com/jaungiers/LSTM-Neural-Network-for-Time-Series-Prediction). The author is dividing each 50 day slice from the S&P500 by the first 50 day slice....also in the test set. And that is not the same as dividing every value by the very first one. So the stock price movement from the first 50 training days is also partly included in each test example. As soon as you apply more common (valid) normalization methods, the model in not doing better than the monkey throwing darts.
That Guy (6 months ago)
Perhaps you could make a video using attention? Such as described in this paper as a better alternative to RNN and LSTM: https://arxiv.org/abs/1706.03762 What they found was that RNN and LSTM have issues with long data strings due to their fixed length internal representation. The subject was explored further here: https://machinelearningmastery.com/attention-long-short-term-memory-recurrent-neural-networks/
01 10 (7 months ago)
Oh...please...SLIGHTLY BETTER THEN RANDOM MEANS THAT YOU CAN'T MAKE ANYTHING MEANINGFUL OUTPUTS IN THAT FIELD. Bullshit
John Batchler (7 months ago)
I did better than wall St computer ai results keep it simple just find find ur entry and exit points
Jia Liang Low (7 months ago)
What is the lstm helper package, and how do I get it
LaBnErD85 (3 months ago)
Go to the GitHub link in the description and download the whole folder. It will the one named lstm.py.
Cristian Duguet (7 months ago)
is that Robert Downey Jr at 0:38??
Cristian Duguet (7 months ago)
not sure but he's definitely back at 8:50
Chandeepa Dissanayake (7 months ago)
In my opinion, Siraj Raval is a pure hype, and someone just copies code from some sources even without giving proper references. He just uses words such as "model" to wrap stuff up which he seems to have NO intuition or idea about. Building a neural net in 4 minutes, Some other deep concept in 30 minutes and such other stuff publish by Siraj Raval made me really dislike him. Those video stuff provide no proper intuition on what's happening inside them. Deep Learning is a DEEP subject that dives into some cool and DEEP mathematical concepts. So something like "Building a neural net in 4 minutes" with proper intuition and understanding of neural networks and deep learning is absolutely ridiculous and nuts. Sentdex's ML series is far better than this comparatively, he-at least provide a decent background to what's going on, even for the math. Just remember this is my opinion.
Yiif.ru (2 months ago)
Siraj just hype and want to earn money on education , and lie that DataScience easy
Kyaw Thwe (7 months ago)
when you said google+ IMAO
JM G (7 months ago)
I'm so confused, and yet everyone in the comments seems to know exactly what he's talking about word for word lol.
Marquise Williams (6 months ago)
You're not the only one. I don't even know how to code on Notepad.
transam351 (7 months ago)
"Just like Google+" I laughed so hard! LOL
79792903-1 97296301 (7 months ago)
What type of animal is his hat made from?
Zes (8 months ago)
wrg, can anyx, not need
csybe (8 months ago)
Can't believe he didn't include how to insert a date to output a price. Would be nice also to have a number of the accuracy of the model. Why else to even include test data? Anyone knows how to output this?
Beytullah Mijnen (8 months ago)
*Forex trading is not magic.... You are not going to be a millionaire overnight, but its a good background to raise your finances at a steady growth..... You need a proper understanding on its steps by a SUPERB FOREX TEACHER to trade for you, So go with now and make your balance double within To night from here >> **https://t.co/p84BYGCqbZ** .*
Jack A. McLeod (8 months ago)
*When strategics in the binary world, some people say risk is inevitable, 'YES IT IS TRUE', but i guarantee you that risk is inevitable when it comes with unimagined profit. This Strategy will make you benefited, make a change and rule your world. Start your Trading from here and make your successful forex life >> **https://t.co/pbFk7a6mEJ** .*
Clarence R. Huard (8 months ago)
*My advice is not to enter the market without basic knowledge. Forex trading is a zero sum game. It’s complex, so you need math skills to understand the market trends and different algorithm. What a party wins, the other loses. So the competition is fierce here. But a good system well developed with high tech algorithm, So trade with the Top Secret Strategy by and make your balance double from here **https://t.co/nxrVq1ATMa** .*
James Windley (8 months ago)
*I am so much impressed with this creative binary trading app (Link Here >> **https://t.co/2nQjFFyekI** ). Backed with expertise, this robot works splendid and if not much, brings in decent amount of profits. Thanks so much the team for creating such innovative robot. It’s like a boon to the traders in earning consistent profits .*
Carbon Based (8 months ago)
Bro - this is a hot topic, keep posting. I'm old. I have to watch you at 0.75 speed lol.
Jeffrey Robert (8 months ago)
Can you tell me if my phone is being hacked...and if so by whom..oh and does google hate me...
sgrouge (8 months ago)
Imagine a deep learning machine distributed over the internet, using computational of CPU/GPU of computer owners. Imagine his power. A decentralized AI over the internet trading for the best entries.
TheAndyb1979 (8 months ago)
Nice video of SciChart at 0:53. Did you ask for permission for that? :) https://www.scichart.com/example/wpf-chart-example-realtime-ticking-stock-charts/
zhonglian ni (8 months ago)
It seems the algorithm does not give you the correct indication of the future trend most of time. Each time I train the model and run the prediction model, it will give you a different prediction result. I run the code given by the link: https://github.com/llSourcell/How-to-Predict-Stock-Prices-Easily-Demo. Maybe the result given by the author is the best result ? Just curious, I don't know. Anyone who tried this model is welcomed to discuss this please.
Tavio Co (8 months ago)
How do we know an intrinsic value of a product? Combo of all resources that make the product possible. Its market price? Any other sales expenses + profit margin(roi). Anything else is entertaining speculation: taking money from someone to give it to someone else without actually selling the actual product. I mean gambling
Bhaskar Nair (8 months ago)
I didn't understand shit. But I feel intelligent..
Alhasby Pranaja (1 month ago)
I have had my share of ups and downs when it comes to trading Forex. Now, all I do is win, I mean I make thousands of dollars daily using The *Blended Model Strategy* if you have not heard about it all you have to do is find out about it on google +, The creator is *Dmitry Vladislav* and remember to save this link to thank me later.
SiggyMe (8 months ago)
Actually it makes sense in a weird way if I just let my mind cruise with the flow and allow it self assemble instead of doing the work letting you do it. Now if I can get my LSTM working I will be jaked.
World's Best Whistler (8 months ago)
I don't understand a shit!
Monty Shaw (9 months ago)
Also do you have a version that runs under python 3? And what is xrange, since it is undefined in your code.
Alejandro Rosales (8 months ago)
xrange = range for pytho3 <=
Monty Shaw (9 months ago)
Do you have a video on how to set up the python development environment for this video? I know the readme tells how to do it, but it seems like I would need to be a Python developer already to understand what you have there.
gespilk (9 months ago)
Amazon knows the sales of each manufacturer even before their quarterly reports. The rest is machine learning and picking them on the stock market. Amazon maps Stock to products-sold using predictive machine learning. Amazon has the data and nobody can get it. It is the ultimate "insider trading". Untouchable by the law. Aristotle Onassis spied by tapping phone conversations to become rich. What makes you think Bezos is not doing the same, spying on manufactures' sales rates?
Timothy Sawe (9 months ago)
Wow! Thank you
Neo Anderson (9 months ago)
Sorry..thats now how I would explain the concepts to a layman..
Anshika Gupta (9 months ago)
DUDE this code is copied form this source, atleast give credit! (PS His date of publishing is earlier) http://www.jakob-aungiers.com/articles/a/LSTM-Neural-Network-for-Time-Series-Prediction
Fabian Heinemann (6 months ago)
I assume there is quite some money and fame possible in making youtube videos on booming topics like data science + AI.
Amit Schandillia (6 months ago)
Ahh, thanks for sharing. Sad indeed that someone like Siraj had to resort to plagiarism.
Fabian Heinemann (6 months ago)
I agree that something strange is embedded in the page but I don't think its spam. The github repo of the original of the code is here: https://github.com/jaungiers/LSTM-Neural-Network-for-Time-Series-Prediction
Amit Schandillia (6 months ago)
Spam link.
Fabian Heinemann (7 months ago)
You are right Anshika! He just copied it, without giving a proper reference. Unsubscribed.
Peter Labuschagne (9 months ago)
Hey Siraj, this is great! How did you get the closing prices for S&P 500?
LaBnErD85 (3 months ago)
You can get it from Yahoo Finance
Bryce Chudomelka (9 months ago)
Siraj, PyCharm doesn't have the library for "import lstm". What alternative library should I be using? theanos_lstm? Thanks for your time.
PutBoy (9 months ago)
No, you can't predict stock prices. If deep learning algorithms could predict stock prices all mayor player would do it. They don't.
Liang Chen (9 months ago)
Only using historical price as inputs will not work, because the stork price is influenced by many factors that had not even appeared in history, like scandals of CEOs etc.
runkle75 (9 months ago)
"Just like Google+" hahaha
Chen Cheng (10 months ago)
sorry to ask a basic question: I assume the output in the stock price, but what's your input here? Date? But is there a logical connection between date and stock price?
LaBnErD85 (3 months ago)
The input is the price for the past 50 days and the output is the future 50 days
Why This Sucks (10 months ago)
love what youre doing here. I am new to coding. Only know a bit of java. Where do I start?
oneeyedboxer (10 months ago)
You are very good at researching and reciting material , however you have no insights into ML. I think you are very funny though and I hope you consider teaching stuff that you actually practice and can give deep insights.
Latin Dance Videos (6 months ago)
Yeah nah. It takes a solid level of understanding to make it look easy. Plus, when you realise this channel was conceived and designed for a specific niche, it becomes obvious why the charimsa, memes and style was chosen.
jose banderas (10 months ago)
ay baby
50kT (10 months ago)
Damn! I didn't know this was so easy! Thanks
Blake Neely (10 months ago)
センピー? ブロックチェイン自体が深い学習の可能性のために大きな飛躍をもたらすのはなぜですか あなたは深い脳チェーンやネーミングのようなものを見て回ることができますか?
Angelo Alexander (10 months ago)
This is the very first video I watch of yours. Instant subscriber. You take time to make your videos gripping. Thanks. (It might just be your personality but that's fine). But as well your technical expertise ;)
Walter Morawa (10 months ago)
Hello Fellow lstm noobs, So, this worked decently with up to 5000 data points, but then I scaled it to 35k points and all prediction lines are the same and point negatively. Does anyone know why? I thought it was supposed to improve with data. And before you say overfitting, this is very volatile data
Andreas K. (10 months ago)
Good Job on this man! But PLEASE: Dont ever sing again.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.