Real Time Stock Market Data Analysis with Python - Five Minute Python Scripts

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to the channel today I want to do a request from a subscriber on how we can start using real-time stock market data in our Python scripts let's jump right in jumping over to a text editor the first thing we need to do is to install a new package I'm on a Mac so I'll use a terminal and I'll type in pip 3 install and then the package is called alpha Vantage then we'll hit return to install the package I already have this package installed and that's where I get this message but you're sure download will use this package as an easy way to access your real time stock market data next we need to jump over to their website I just google it and go to the first link and now we need to go to get your free API key we'll put in our information here once you put in your information and click get free API key they return an API key to you go ahead and copy this value and we'll move it over to our Python script so say API key is equal to that value once you're watching this video I'll probably have already deleted this API key but it's a very straightforward process to get your own next we'll import all the packages that we need so it's import pandas as PD and then from Alpha Vantage dot time series we'll import the class time series lastly we'll import time next we'll drop down below our API key and say time series is equal to the time series parentheses set our keyword argument of key equal to this variable right here API key next we'll specify our output format so we'll put output format and then we want it as a painted a different so we'll pass in pandas here let's set the variables data and then metadata and we'll set this equal to time series get entered a we see that we have a lot of different values here that we can pull out so daily weekly and monthly but since we want minute-by-minute data let's use intraday will set the symbol so symbol equals and then we'll pass in a ticket so let's say we're looking at Microsoft stock comma and then we'll specify the interval so interval equals 1 minute and then we want an output size equal to full let's drop down and put print data to make sure it works go back to your command prompt for terminal and type in Python 3 and then the name of your file so minus stock stop hi to execute when we get the result we see we have minute-by-minute data of the stock that we specified we'll scroll up and we see that we have the data for the open the high low close and volume for the stock in each minute now that we're able to pull out the data we're able to do operations on but first let's talk about how we can save this data in real time like how our commenter wanted so we'll drop down and since this is already in a Pena's data frame we can use the function to Excel so let's say I is equal to 1 and usually I wouldn't create an infinite while loop but since our subscriber wants us to happen all the time let's do that so while I is equal to 1 or do this function like I said we already have a panda's data frame so we can just use the function to Excel we'll pass in the data frame and then to Excel well specify the output file path so let's say output dot xlsx and then let's use the time function so we're not running this console we'll say time sleep and then pass in the number of seconds that we want to wait so since our interval is one minute let's say 60 seconds we'll also need to include the function get intraday inside our while loop so we'll copy this line of code here and move it into our while loop now when we save and execute this every minute we should be returned to all the stock information into that excel file opening up the excel file we see we have it here but now let's talk about the data analysis so we'll hit ctrl C to end our while loop I'll go ahead and comment this out that way it doesn't interfere with the rest of the script now if we're wanting to pull real time data down to the minute it's likely that we're day trading day traders make all their money using the volatility of stocks so let's look at how we can find the volatility of stock in a given minute the first thing we need is the closing data of the stock in each minute so let's say close data and then we'll pull out the data frame data frame and type in the column for dot close this is just pulling out all the closing information from our painters data frame next we'll need the percent change in between each minute so let's say percent change is equal to close data and then we'll use a function already built into the paynus package so percent change now we can print percent change and see what we get when we execute we see that we get the percent change of the closing values in real time now if we're looking for volatile stocks in the last minute we don't really care about everything else in this series we only care about this last value so to get the last change we'll specify new variable called last change and then we'll say percent change and then we'll index it negative one this is just pulling out the last value in this series which is this value right here now we need to create a tolerance for something to happen so let's say if the absolute value of the last change is above a certain percentage we need to do some kind of action so let's say if the absolute value is above 0.4 of a percent then we'll create some kind of action now right here we could do a lot of things to alert us to this volatility happening in the last minute for example we could create a what's that notification or an email but for this video let's keep it simple and just return a statement so print and then we'll say Microsoft alert because we may be looking at a lot of different stocks and then we'll concatenate the string with the last change value this way if you're looking at a lot of different stocks in real time you know which stock is alerting you and what the volatility is we'll save this file and execute we see that we didn't get that alert because the stock is relatively stable I just want the script to be a brief tutorial on how we can start using real time data in our Python scripts and not necessarily the complete package so feel free to use the script as a baseline and change it however you seem necessary for the values that you want please note that I'm not a financial advisor and I don't encourage day trading unless you really know what you're doing the idea behind this Python script is just a way that we can better research stocks before we purchase them if you're looking to get involved in the stock market Robin Hood has a great free app that you can use to trade commission free if you're interested in getting involved in the stock market feel free to download it from the description below if you use my promotional link below you and I can both get a free stock up to two hundred dollars if you want more content about how we can use Python to analyze the stock market please let me know if you have any questions or comments about this video please let me know until next time [Music]
Info
Channel: Derrick Sherrill
Views: 142,717
Rating: 4.9198785 out of 5
Keywords: stock market, python, day trading, tutorial, pandas, automation, python automation, alpha vantage, real time, information, data, data analysis, analytics, data analytics, stock market analytics, programming, coding, Derrick Sherrill, coding tutorial, programming tutorial, five minute python scripts
Id: d2kXmWzfS0w
Channel Id: undefined
Length: 6min 13sec (373 seconds)
Published: Sat Jun 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.