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

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

6970 ratings | 530232 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 Hit the Join button above to sign up to become a member of my channel for access to exclusive content!
Html code for embedding videos on your blog
Text Comments (677)
Daniel Arthur (7 hours ago)
Wow been looking for something like this for so long.. But I didn't understand a lot since I don't know how to code and don't know anything about machine learning and data science
Omar Omeiri (7 days ago)
I didnt get how the train_test_split was done using this "lstm" helper library. What is being used as a label? I mean y_train and y_test. Is it the x_train shifted by 50? How many data points were indexed to the test set?
Christopher Ryan (14 days ago)
the stock market has been of immense success. since i started with Pat Brown in January, i always make huge profits
Jason Cole (14 days ago)
Pat Brown is the best recommendation you can get. i invested 7 months through his portfolio while learning the ropes from him.
Sam Bliz (14 days ago)
i really encourage anyone struggling with trade to contact Pat Brown at <[email protected]> am also a beneficiary
Jaden Walker (14 days ago)
i like the way Pat Brown gives his daily trade updates. He keeps me involved
Lynn maria (14 days ago)
i just got started with stock trading investment. i would like to know the best stock i can invest. how can i contact Pat Brown?
Luzia Mike (14 days ago)
i have been in trade with Pat Brown for over 3 months now since the firm of the last broker i was working with ran into bankruptcy. i always win
Maria Ioan Anton (15 days ago)
Training new model w/ 3-layer, 128-cell LSTMs Training on 15,228,624 character sequences. Epoch 1/50 14871/14871 [==============================] - 987s 66ms/step - loss: 1.4959 Epoch 2/50 14871/14871 [==============================] - 969s 65ms/step - loss: 1.3340 Epoch 3/50 14871/14871 [==============================] - 961s 65ms/step - loss: 1.3073 Epoch 4/50 14871/14871 [==============================] - 964s 65ms/step - loss: 1.2924 Epoch 5/50 14871/14871 [==============================] - 969s 65ms/step - loss: 1.2819 Epoch 6/50 14871/14871 [==============================] - 969s 65ms/step - loss: 1.2739 Epoch 7/50 14871/14871 [==============================] - 963s 65ms/step - loss: 1.2673 Epoch 8/50 14871/14871 [==============================] - 997s 67ms/step - loss: 1.2616 Epoch 9/50 14871/14871 [==============================] - 1006s 68ms/step - loss: 1.2566 Epoch 10/50 14871/14871 [==============================] - 997s 67ms/step - loss: 1.2521 #################### Temperature: 0.2 #################### st things of the country of the sons of Jesus, and the God of Israel, and the LORD shall call the children of Israel and the LORD thy God, and the words of the LORD came unto the children of Israel, and to the children of Israel, and the LORD shall be the sons of Joshua, and the LORD said unto him, stranger which he was a stranger of the country where the princess was a state of a continual position of the princess. The state of the whole thing had been at the same time the convent was a state of the country of the barricade of the country of the LORD had called the children of Israel, and the versation of the LORD. 10:13 And he said unto him, The LORD shall be as the way of the land of Egypt, and the congregation of the LORD, and the priests of the children of Israel, and the priests and the LORD shall be a statute of the sons of the sons of Ahaziah, and the son of Jehoiada the son of S #################### Temperature: 0.5 #################### tain of the movement of the former things were started out to me, and then to the soul and the sofa of the meat offering, and was a love of the necessary. “But the terrible one would be gone up to the stature, and I was broken upon his shadow and shall be a great sweet to be of the LORD of the LORD sea in the paper, the whole elementation of an house that is all the people whom thou hast said: and he shall call the fruits of the children of Israel. 2:16 And the LORD said unto me, The LORD shall be an holy feather was the first time and the rest of the whole country, who reached the rattle of the lands which the charge of the people of the children of Israel, and the congregation of the LORD is in the land of Egypt: and the king had caused him a few people and even the former private special that had been full of work of his willow things and man, and shall both the window of the LORD t #################### Temperature: 1.0 #################### ennigsent Urksa, he sways lewd; thou stood meat of a noise he was hid fiery that put a partidimates there were a calm portfobbic. Before nigh he wuncted to it.” “I don’t know that I wouldn’t hear,” she sat hallwage and looked for only give her bad hands. “Hened, characterd it phises. He soon seate crossed in the city: and when Eliana because they made them on the way, and thou comest not to you, and ye are twelve: forth Jacob the uppropes had fell, the sire that got the trembling form and erassed his fingers. The suit of his contents on whisper drinked into his flesh.
Damnit Bobby (20 days ago)
When you fail at something hide all evidence that you ever tried.
Thomas Kuncewicz (22 days ago)
Bruv what I have to do to have you host a Netflix show / I'm mad at myself for only discovering your channel today! Keep up the amazing videos, 5/5 explanations
Akshay (27 days ago)
Bakchodi karbalo isse bass
ShadowMaster 45 (1 month ago)
bruh what
do we really need math behind neural net to use them efficiently ?
CHAKIB BACHOUNDA (1 month ago)
kray97 (1 month ago)
Auto Regressive Integrated Moving Average
Walter Schloss (1 month ago)
Notice me Senpai
Mathews Mwansa (1 month ago)
Many thanks but you speak faster and that makes grasping the information hard for people who are just learning ML.
JRFrogman (1 month ago)
Dude!!!! You need to stop smoking crack or cut back on the coffee. You go too slow during the history lessons but start to speed up as the material becomes more complicated. I feel like I need to watch some of this video at 1/10th speed.
Luci Cal (1 month ago)
Needed to put playback speed on 0.75x in order to understand what these concepts mean.
Bill Franz (1 month ago)
Stock market is far from random, it has patterns, but they usually take time to learn.
Gino Pizza (2 months ago)
Hi Siraj, i can't find the python's module named lstm you use for load_data function, can you tell me which package is? Thanks in advance
Julmali Ahiyal (2 months ago)
Cool. Didn't understand a thing though
Rajesh Thennan (2 months ago)
Coming up next. Let me show you how to predict the future of a domain I have almost no clue about. And then claim that the tools I used don't work for the domain or the domain is unpredictable.
Alon (2 months ago)
Be careful when predicting stock prices: https://medium.com/@alon.lek/how-not-to-predict-stock-prices-2bf9da9ba91d
Sumit Kumar (2 months ago)
how to install these helper libraries ?
Augustine mwathi (2 months ago)
Hey thanks for this informative video. Do you code for forex trading platform like mt4 and ctrader? I'm looking for someone to code for me an AI software /bot that is purely based on price action.
calculate the speed of the difference occurring to give a more accurate read out of probability! which is giving you a volume indicator built in I think.
Kay Bey (2 months ago)
positive economic reform ideas. Thanks for sharing another clue !
Obi Kenobi (3 months ago)
Bs clickbait. Just proof you can predict.
yolo mein (3 months ago)
I dare you to use this with your money on the real stock market
F.X.L 365 (3 months ago)
He knows what he talking about but he doesn't have any kind of knowledge about he's audience .. what Ever he said it's valuable for him not for audience bcz they don't understand he's failed
jerry mander (3 months ago)
Technonerds trying to use Math to somehow predict the market by trying to mathematically simulating human impulses. Way to complicated . KISS principle Keep It Simple !!!!!! Too many moving parts.
FartGod (3 months ago)
I like your energy but damn you move fast sometimes, you spit knowledge like you're on a cocktail of nootropics and dark web cathinone analogues,
CreativeWayofLife (3 months ago)
Siraj, you are the very best! I work myself through a pile of papers for my Master Thesis and often get stuck in the details. Watching your Video Lessons makes me understand the relations between the individual concepts. I feel like many things are perceived as trivial by researchers and are hence omitted in their papers. Thanks a lot for closing that gap between research and education!
jupiejupe (4 months ago)
Ludwig for Stock Price Prediction please.
imagynat 3d (4 months ago)
hi, when i try to open this files in windows, dont open, appear my black screen, i need to install a program?
Avyact Jain (4 months ago)
What is the X_train and y_train in this example? The dataset is just a vector of collection of closing prices.
klajdi ruci (4 months ago)
Looks like a bird poop his hair and he liked it.
Robert Ferraro (4 months ago)
I am of the opinion that even the most sophisticated stock predicting neural network will never do better than the market. In fact you will do worse than the market because such positions it might take will only keep you in the market for a few days. So you are paying $10 to buy and $10 to sell and you will also lose on the change in the market price based upon your order. A neural network can only do as well as predicting coin toss outcomes which is 50/50. Notice he said it can only do just slightly better than 50% which really is what the market performance is - a little better than 50% and is equivalent to a biased coin with the degree of bias that is equivalent to the market direction and performance. The best strategy always - find a good stock buy it and hold it and sell when you are ready. You pay $10 in commissions at both ends and the market prices at buy and sell time are only a fraction of the overall growth you may get. But hey.... let them keep trying - it keeps ambitious minds busy.
ADNAN FAROOQ (4 months ago)
Price of a stock is only equal to how much cash company will be able to generate .Not this foolish math.
__ (4 months ago)
The Age of the Algorithm o:
Aaron Wing (5 months ago)
what are the helper libraries?
A Normal PUBG Gamer (5 months ago)
Ye bsdika sirf bkchodi pelta hai kya
Mr.Tweezy007 (5 months ago)
Bruh this video ended up confusing me more than it helped. The only redeeming part of the video is that i now know what i am supposed to look up in order to get to understand this better. Neural networks are highly complex and this nigga just zipped through at a break neck speed. Wtf lol
Wayne Filkins (5 months ago)
So did you predict it and was it correct???
Saxoprane (5 months ago)
Are you coding or is it Sentdex video ?
Tamil Selvan S (5 months ago)
hi Siraj, can you please me share the spyder code for stock prediction in money control(India). ([email protected])
jawad mansoor (5 months ago)
1:43 they are all girls?
Phil S (6 months ago)
Hello Siraj / all. I've been playing around with the software from github and well it's not much fun when the stuff don't work as expected. I really enjoy my channel I think it's very interesting, but when does the spoken word ( through what ever software { Python, Java, C++, LUA, etc.etc ) start to create app's the runs on any device. We have on the fly compilers that have been written by people. When does the AI begin to communicate with hardware and write code
بدر الغامدي (6 months ago)
is that robert downey jounier 0:38
Razzle1964 (6 months ago)
My mate used to have tons of heavyweight books about neural networking over 20yrs ago & had a sizeable mainframe in his bedroom (equal to 4 or 5 big refridgerators), at his parents home in Watford. Never understood a word of it. Bloody nice bloke, though!😉
canpolat (6 months ago)
Couldn’t be more complex.
Stefan Kocher (6 months ago)
I'm working with PyCharm and a virtual environment but "import lstm" won't work, the rest of the imports work just fine. Has anyone a hint how to fix this?
Was geht (6 months ago)
One question , is it possible to use neural network to estimate American option price with monte-carlo-methode ? Is anyone who has a idea or a good link for me :)
Mike Ellertson (6 months ago)
which lstm package are you using? I can't seem to find the right one on PyPi. The lstm "helper library" I mean. The one on line 4 @ https://youtu.be/ftMq5ps503w?t=472
Özgür AKPINAR (6 months ago)
00:38 Isn't that Rober Downey Junior?
Joy (6 months ago)
Hey Siraj.. !! After fitting and testing LSTM model, how can I predict for the future time steps? For example, I have 146 years of data. I have used 100 years data for training my model and 46 years of data for testing my model. Now I want to predict the data for the next 10 years. Could you please share the code?
Akylas Strat (7 months ago)
Can you predict stock prices movements with ML? Possibly. Can you make money of it? Probably not. You have to incorporate trading fees, liquidity, leverage, risk management. You might have predicted correct that a stock will fall and short-sell, but a single upward tick can get you bust, depending on your exposure.
Sofiane Lrd (7 months ago)
I am really distracted by the pictures you put in ...
Himanshu Suthar (7 months ago)
If this works, I''l share 20% of my stipend with you.
Yi Xing (1 month ago)
if this worked, he'd not shown it to you
Ryan Meunier (7 months ago)
I don't understand what was said, or how I got here, but you explained it very well.
Mr.Tweezy007 (5 months ago)
denisbaranoff (7 months ago)
Stock prediction imposible in general. AI information is in stock price. All information is in stock price.
Alex (7 months ago)
How to let two neural networks trade against each other?
Pierre M S Silva (7 months ago)
Solid piece of gold. I'm a web developer without college degree, but learned everything by myself and I've been in the tech biz for almost 10 yrs now. I love finding things to learn, and the way you manage to compact so much valuable information in such a small video, is music to my ears. I'll soon be experimenting with machine learning and AI. Thank you very much for such valuable piece of content. Peace from Brazil!
Becky L (7 months ago)
I am getting an error for import lstm, time. Error msg - no module named lstm
Howard Dixon (7 months ago)
Jesus christ. If you understood any of this..... go fuck yourself
ousainou jaiteh (7 months ago)
Hi Siraj where can I find the link to download the dataset
Anirudh Parashar (7 months ago)
It's a fuzi, it's a fazi, it's a fugazi, nobody knows.
Andrey Stroganov (7 months 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 (7 months ago)
Investors don't share any of the information they have. A sharing of information dilutes the effect. Remember this.
Praveen K (8 months ago)
Siraj, I like your videos but could you reduce the memes
Lê Hưng (8 months ago)
if he can make money by prediction, he won't have to become youtuber for sure haha
Siddharth Dandekar (2 months ago)
Not everyone does everything for money. Some people just want to make the world a better place.
John (8 months ago)
4:22 this is literally the Heisenberg uncertainty principle in real life :0
Sudeep Dasgupta (8 months 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 (8 months ago)
Lol that Chief Keef in the outro :)
Robialmay Naufalmahdy (8 months ago)
anyone notice young RDJ?
harvinder arora (8 months 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 (8 months 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,...
Abby Sack (9 months 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 (8 months 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.
Abby Sack (9 months 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 (9 months ago)
Yep, you are right. Just tried the code. not sure why the code could run when you have a float in range.
MrGreenT (9 months ago)
would this also work for fx trading, like currencies
M.K. Ultra (9 months 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 (9 months 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 (9 months ago)
you talked for 10 minutes and gave 0 information. Your channel name should be 'Redundancy Guru'
igor (5 months ago)
Lol, he gave a lot of information my friend. It looks more like ur not able to deal with this
Rick Snapp (10 months ago)
panagranit pana (10 months ago)
It is amazing that your code in the Jyupter note book is so short.
NutHouseProductionz (10 months ago)
Wish I could understand what he is talking about.
Steven F (10 months ago)
Great content, but the memes were cringy lol
Victor Chan (10 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?
ahhahhahahhahaha you make me lough too much man, take my suscribe XD
ayma kam (10 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 (10 months ago)
That clip of scientists on front of computers was 100% Asian. What has America come to?
Goby Swiss (10 months ago)
I can predict googles stock price in less than a minute looking at the chart. It’s easy
Crypto Mustache (11 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 Chatterjee (11 months ago)
wait, Tony Stark was stock broker @0.38 before? That's how he made the money.
John Parz (11 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 (11 months ago)
What data types are they, singular dimension array, multiple dimension array?
Eric Lamey (11 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).
Yes, We can predict stock prices.
bol lol (11 months ago)
how to start the code editor?
Ujjawal Ujjawal (11 months ago)
Ken Semotiuk (11 months ago)
Why try to predict a rugged market, go drink beer and enjoy life!
Kevin Cawley (11 months ago)
What's the song called in the beginning?
what does print 'yo' in the 17th line in lstm.py mean?
Hydroman 7 (11 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 (1 year ago)
I use latest version of Mathamatica to build the LSTM as the package now comes with Netgraph and LSTM..
Harsh agrawal (1 year ago)
How to predict a sequence(multiple timesteps) using lstm is not clear
N64 Classics (1 year ago)
Enjoyed the memes and cut scenes throughout
Aniket Banginwar (1 year ago)
0:38 Is that Robert Downey Jr. ????

Would you like to comment?

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