import pandas as pd from datetime import datetime, timezone import json import yfinance as yf
# ---------------- Settings ---------------- # Match your original ticker set tickers = ["MSFT","AAPL","NVDA","GOOG","AMZN","META","TSLA","CRM","AMD","INTC","BABA","PYPL","CBOE","BLK"]
# Keep the same ms-epoch inputs you were using start_date = int(datetime(2025, 6, 20, tzinfo=timezone.utc).timestamp() * 1000) end_date = int(datetime(2025, 8, 18, tzinfo=timezone.utc).timestamp() * 1000)
for t in tickers: print(f"--> {t}: {interval} {start_ts.date()} to {end_ts.date()}") try: # Download OHLCV df = yf.download( t, start=start_ts.tz_convert(None), end=end_ts.tz_convert(None), interval=interval, auto_adjust=False, progress=False, group_by="ticker", threads=True, )
if df is None or df.empty: print(f" (no data returned)") stock_data_dict[t] = {"candles": []} continue
# Ensure the index is datetime and build epoch-ms column from it idx = pd.to_datetime(df.index, utc=True) df["datetime"] = (idx.astype("int64") // 10**6) # ns → ms
# Some intraday frames don’t have Adj Close; use Close if missing if "adjclose" not in df.columns and "close" in df.columns: df["adjclose"] = df["close"]
# Some symbols/intervals may lack volume; create if missing if "volume" not in df.columns: df["volume"] = pd.NA
except Exception as e: print(f" Error fetching data for {t}: {e}")
# ---------------- Quick summary ---------------- print("\nSummary:") for t, payload in stock_data_dict.items(): n = len(payload.get("candles", [])) print(f"{t}: {n} rows")
# ---------------- Persist: JSON + CSV ---------------- # Write JSON (similar to your 'AAAA_stock_data_NEW.json') with open("yahoo_stock_data.json", "w") as f: json.dump(stock_data_dict, f, indent=4)
# Flatten to one CSV like your pipeline expects all_rows = [] for t, payload in stock_data_dict.items(): rows = payload.get("candles", []) for r in rows: r2 = dict(r) r2["ticker"] = t all_rows.append(r2)
kann FB -Daten in der Yahoo -Finanz -API
als FB als Meta nicht mehr auf Yahoo -Finanz -API Daten finanzieren. Als Meta scheinen FB -Daten nicht mehr auf Yahoo zu finden.
data =...
Ich verwende Mac OS und empfange einen Fehler, wenn ich Folgendes mache:
import pandas as pd
import yfinance as yf
from yahoofinancials import YahooFinancials