File size: 652 Bytes
2aaf2a2 a71b954 2aaf2a2 a71b954 2aaf2a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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")) |