Real-time Stock Price Data Visualization from Yahoo Stocks using Python
We have visited the stock prices of any company on Google or using any Search Engine and found a complete chart that represents the latest and historical stock prices.
Here we have added the complete code that will help you to create a real-time stock price data visualization system using Python where you will enter the name of a company and the stock prices data will be visualized according to the company stock from Yahoo as an output.
So, in this article, I will take you through the task of real-time stock price data visualization using Python, To create a real-time stock price data visualization application, I will use provided streamlit library in Python which will show real-time data as a website dashboard.
In this task, we can use the streamlit library to create an interactive user interface where a user will enter the name of any company, and the stock price data will be visualized in the final result as output with a graphical interface and the matplotlib library in Python also used to show analysis.
Before Running make sure you have installed: Streamlit, Matplotlib, Pandas using pip, here is code to install:
pip install streamlit
pip install pandas
pip install matplotlib
pip install pandas_datareader
pip install yfinance
Now below is how you can create a real-time stock price data visualization application using Python:
#Real-time Stock Price Data Visualization from Yahoo Stocks using Python
##imported libraries
import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt
import datetime
from datetime import date, timedelta
today = date.today()
#configuring date
d1 = today.strftime(“%Y/%m/%d”)
end_date = d1
d2 = date.today() — timedelta(days=360)
d2 = d2.strftime(“%Y/%m/%d”)
start_date = d2
##importing streamlit library
import streamlit as st
#defining title of dashboard
st.title(“Real-time Stock Price Data Analysis by Babar Ali Jamali”)
a = st.text_input(“Enter Any Company >>:”)
#data analysis and plots
data = web.DataReader(name=a, data_source=’yahoo’, start=start_date, end=end_date)
fig, ax = plt.subplots()
ax = data[“Close”].plot(figsize=(12, 8), title=a+” Stock Prices”, fontsize=20, label=”Close Price”)
plt.legend()
plt.grid()
st.pyplot(fig)
Keep following us for more posts.