Stock Portfolio Trend Visualization Using Python, matplotlib
Previously I shared the way to visualise daily pricing in a candle type data format, here I would walk through how to visualise a collection of stock portfolio in a time series data format.
Previously I shared the way to visualize daily pricing in a candle-type data format, here I would walk through how to visualize a collection of stock portfolios in a time series data format.
Tables of Content: Stock Portfolio Performance Trend Visualization Using Python
- Python Packages: matplotlib, yfinance
- Dataset required: datetime, specific pricing dataset of tickers
- Insert each ticker closing price data for plotting
- Full Python Script for visualizing stock portfolio performance trend
- Data Science & Machine Learning Couresa Course Recommendation
Python Packages: matplotlib, yfinance, pandas-datareader
Pip install finance
Pip install pandas-datareader
Pip install matplotlib
from pandas_datareader import data as pdr
import matplotlib.pyplot as plt
import yfinance as yf
Dataset required: datetime, specific pricing dataset of tickers
As well as the stock daily pricing visualization chapter, we need to implement fix-yahoo-finance library to replace broken yahoo-finance from pandas
yf.pdr_override()
Different from an individual ticker, portfolio tickers require to get the pricing dataset for each ticker. From my personal perspective, it’s great to add the security index pricing as well for adding an anchoring point. Here I add Nasdaq as my portfolio tickers are all from Nasdaq.
dataA = pdr.get_data_yahoo('NDAQ', startDate, endDate)
dataB = pdr.get_data_yahoo('TSLA', startDate, endDate)
dataC = pdr.get_data_yahoo('AMZN', startDate, endDate)
dataD = pdr.get_data_yahoo('AAPL', startDate, endDate)
Insert each ticker closing price data for plotting
Due to the different scale by each ticker, so it’s necessary to normalize it to 100 then insert each stock closing price data for plotting.
ax = (dataA['Close'] / dataA['Close'].iloc[0] * 100).plot(figsize=(15, 6))
(dataB['Close'] / dataB['Close'].iloc[0]
* 100).plot(ax=ax, figsize=(15, 6))
plt.legend(['NASDAQ', 'Tesla', 'Amazon', 'Apple'], loc='upper left')
plt.show()
Full Python script for visualizing stock pricing and trading volume
If you are interested in Stock Portfolio Trend Visualization Using Python, matplotlib, please subscribe to our newsletter by adding the message ‘Stock portfolio trend visulisation’. We would send you the script immediately to your mailbox.
I hope you enjoy reading Stock Portfolio Trend Visualization Using Python, matplotlib. If you did, please support us by doing one of the things listed below, because it always helps out our channel.
- Support and Donate to our channel through PayPal (paypal.me/Easy2digital)
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- Share the article on your social network with the hashtag #easy2digital
- You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount codes
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)