FinMM-MultiModal-Forecasting / fin-mm /code /FinMultiTime_index.py
GoldenGrapeGentleman1's picture
Upload fin-mm before machine wipe
e1715de verified
Raw History Blame Contribute Delete
2.38 kB
# build_kline_index.py
import json
from pathlib import Path
ROOT = Path("/workspace/data/finmultitime_hf")
# HS300
HS300_IMG_ROOT = ROOT / "image" / "HS300_image" / "HS300_image"
HS300_TS_ROOT = ROOT / "time_series" / "HS300_time_series" / "HS300_time_series"
# S&P500 图片:image/S&P500_image_a .../b.../c...
SP500_IMG_ROOT = ROOT / "image" / "image"
SP500_TS_ROOT = ROOT / "time_series" / "S&P500_time_series" / "S&P500_time_series"
OUT_PATH = ROOT / "finmultitime_kline_index.jsonl"
def collect_hs300():
for code_dir in sorted(HS300_IMG_ROOT.glob("*")):
if not code_dir.is_dir():
continue
stock_id = code_dir.name # 例如 000001.SZ
image_files = sorted(str(p) for p in code_dir.glob("*.png"))
if not image_files:
continue
ts_file = HS300_TS_ROOT / f"{stock_id}.csv"
rec = {
"market": "HS300",
"stock_id": stock_id,
"image_files": image_files,
"time_series_files": [str(ts_file)] if ts_file.is_file() else [],
}
yield rec
def collect_sp500():
# 遍历 S&P500_image_a ~ S&P500_image_h 等大目录
for big_dir in sorted(SP500_IMG_ROOT.glob("S&P500_image_*")):
if not big_dir.is_dir():
continue
# big_dir 下是按首字母分的子目录:aa, aapl, ...
for code_dir in sorted(big_dir.glob("*")):
if not code_dir.is_dir():
continue
stock_id = code_dir.name # 例如 aa, aapl
image_files = sorted(str(p) for p in code_dir.glob("*.png"))
if not image_files:
continue
ts_file = SP500_TS_ROOT / f"{stock_id}.csv"
rec = {
"market": "SP500",
"stock_id": stock_id,
"image_files": image_files,
"time_series_files": [str(ts_file)] if ts_file.is_file() else [],
}
yield rec
def main():
count = 0
with OUT_PATH.open("w", encoding="utf-8") as f:
for rec in collect_hs300():
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
count += 1
for rec in collect_sp500():
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
count += 1
print(f"[OK] wrote {count} records -> {OUT_PATH}")
if __name__ == "__main__":
main()