# -*- coding: utf-8 -*-
"""sim-distillation-real-data.py が使う価格データを取得して data/cache/ に保存する。

使い方: python scripts/fetch_wave_data.py
yfinance の日足を使うので、誰でも同じデータで再現できる。
"""
import os
import warnings

warnings.filterwarnings("ignore")
import pandas as pd  # noqa: E402
import yfinance as yf  # noqa: E402

TICKERS = {"GC=F": "gold", "NQ=F": "nasdaq", "ES=F": "sp500", "YM=F": "dow",
           "CL=F": "oil", "JPY=X": "usdjpy", "EURUSD=X": "eurusd", "SI=F": "silver"}
START, END = "2010-01-01", "2026-09-18"

if __name__ == "__main__":
    os.makedirs("data/cache", exist_ok=True)
    for ticker, name in TICKERS.items():
        df = yf.download(ticker, start=START, end=END, interval="1d",
                         progress=False, auto_adjust=False)
        if df is None or len(df) == 0:
            print(f"  取得失敗: {name}")
            continue
        df = df[["Open", "High", "Low", "Close"]].dropna()
        df.columns = ["open", "high", "low", "close"]
        df.to_csv(f"data/cache/{name}.csv")
        print(f"  {name:8} {len(df):5d}本  {df.index[0].date()} 〜 {df.index[-1].date()}")
