Created
September 13, 2023 11:18
-
-
Save florinel-chis/c7eccb93bec374cd8b628080db363dee to your computer and use it in GitHub Desktop.
yfinance get TSLA daily data for the past 3 years
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yfinance as yf | |
import pandas as pd | |
from datetime import datetime, timedelta | |
# Define the ticker symbol | |
ticker_symbol = "TSLA" | |
# Calculate the date from 3 years ago | |
end_date = datetime.today().strftime('%Y-%m-%d') | |
start_date = (datetime.today() - timedelta(days=3*365)).strftime('%Y-%m-%d') | |
# Fetch the data | |
data = yf.download(ticker_symbol, start=start_date, end=end_date) | |
# The data is now in a pandas DataFrame. You can view it, save it, or manipulate it as needed. | |
print(data) | |
# If you want to save the data to a CSV file, you can do so with the following: | |
data.to_csv("TSLA_3_years_data.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment