asset-class-comparison / utils /yfinance_utils.py
prasanth.thangavel
Made improvements
a71b954
raw
history blame
652 Bytes
import yfinance as yf
import pandas as pd
from functools import lru_cache
@lru_cache(maxsize=64) # Cache up to 64 different ticker/date combinations
def fetch_yfinance_daily(ticker, start_date, end_date):
try:
data = yf.download(ticker, start=start_date, end=end_date)
if data.empty:
print(f"No data found for {ticker} between {start_date} and {end_date}")
return None
print("data type returned:", type(data['Close']))
return data['Close'][ticker]
except Exception:
return None
if __name__ == "__main__":
print(fetch_yfinance_daily("MSFT", "2020-01-01", "2020-01-10"))