Here is a program which compare the multiple stock/equity data using python and plot a graph for there performances for more than one year date range. I have used NSE stocks data such as Reliance, ITC and TCS companies stock data to do the comparison.
First you need to install the Yahoo finance using following command:
pip install yahoo-finance
Please find the below code for the stock comparsion:
# Import yfinance package
import yfinance as yf
import matplotlib.pyplot as plt
# Get the data for the SPY (an ETF on the S&P 500 index) and the stock Apple by specifying the stock ticker, start date, and end date
data = yf.download(['RELIANCE.NS', 'ITC.NS', 'TCS.NS'],'2022-01-01','2023-03-18')
# Plot the adjusted close prices
data["Adj Close"].plot()
plt.show()
Output for code is:
Comments
Post a Comment