In this article, I will take you through, how you can visualize real-time stock price data with Python by using the Yahoo finance API known as yahoo_fin.
I will use the Plotly package in python to visualize real-time stock price using python as using Plotly we can see an interactive result. I will also use the cufflinks package to create the candlestick chart which will visualize the real-time stock price using python.
Visualize Real-Time Stock Price with Python
I will start this task by importing all the necessary package that we need to get an visualize the real-time stock prices with Python. Now let’s import all the necessary libraries to get started with the task:
Real-Time Stock Price
Getting the real-time stock prices is quite easy in Python. We just need to use the yahoo_fin package for this task. Let’s see how we can get the real-time stock price by using the Yahoo Finance API:
Let’s see what google says if we find the stock price of Apple on Google:
As you can see we have got the real-time price using python in the output above. But this is not what we need, we need to visualize the real-time stock price. Let’s see how we can visualize the real-time data with python. But before that let’s have a look at the data to have a quick look at what we need to plot in the graph:
open high low ... adjclose volume ticker 2020-08-03 432.799988 446.549988 431.570007 ... 434.965759 77037800 AAPL 2020-08-04 436.529999 443.160004 433.549988 ... 437.870514 43267900 AAPL 2020-08-05 437.510010 441.570007 435.589996 ... 439.457642 30498000 AAPL 2020-08-06 441.619995 457.649994 439.190002 ... 454.790009 50607200 AAPL 2020-08-07 452.820007 454.700012 441.170013 ... 444.450012 49453300 AAPL
Plotting the Data
As you can see in the output above we have got a dataframe as an output which is the real-time stock prices data of Apple. Now let’s see how we can visualize the data using Plotly to get interactive result:
The output looks very nice and interactive. I hope you liked this article on getting and visualizing the real-time stock price data using python. Feel free to ask your valuable questions in the comments section below. You can also follow me on Medium to learn every topic of Machine Learning.