Skip to content

Instantly share code, notes, and snippets.

@romanmichaelpaolucci
Created January 23, 2024 17:53
Show Gist options
  • Save romanmichaelpaolucci/e4b0c549812164eea30b44f96391d732 to your computer and use it in GitHub Desktop.
Save romanmichaelpaolucci/e4b0c549812164eea30b44f96391d732 to your computer and use it in GitHub Desktop.
import yfinance as yf
import pandas as pd
# Define the stock symbols
# Define the time period
start_date = '2021-01-01'
end_date = '2022-01-01'
# Download the stock data
stock_data = yf.download(large_cap_tickers, start=start_date, end=end_date)
# Annual Returns for 2021
r_2021 = (stock_data.iloc[-1] - stock_data.iloc[0])/stock_data.iloc[0]
# Closing Price 2021
p_2021 = stock_data.iloc[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment