File size: 1,374 Bytes
cf678fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """Generate synthetic 1h bars + 8h funding for harness smoke tests.
Layout matches crypto_eval.data.load_local exactly:
<out>/bars_BTCUSDT_1h.parquet (UTC DatetimeIndex, OHLCV)
<out>/funding_BTCUSDT.parquet (UTC DatetimeIndex, funding_rate)
<out>/manifest.json ({"outputs": {...}} placeholder)
"""
import json
import sys
from pathlib import Path
import numpy as np
import pandas as pd
out = Path(sys.argv[1] if len(sys.argv) > 1 else "/tmp/synthdata")
out.mkdir(parents=True, exist_ok=True)
rng = np.random.default_rng(7)
n = 20_000
idx = pd.date_range("2022-01-01", periods=n, freq="1h", tz="UTC")
ret = rng.normal(0.0, 0.01, n)
close = 30_000.0 * np.exp(np.cumsum(ret))
open_ = np.r_[close[0], close[:-1]]
high = np.maximum(open_, close) * (1 + rng.uniform(0, 0.002, n))
low = np.minimum(open_, close) * (1 - rng.uniform(0, 0.002, n))
vol = rng.lognormal(8, 0.5, n)
bars = pd.DataFrame(
{"open": open_, "high": high, "low": low, "close": close, "volume": vol},
index=idx,
)
bars.to_parquet(out / "bars_BTCUSDT_1h.parquet")
fidx = idx[::8]
funding = pd.DataFrame(
{"funding_rate": rng.normal(1e-4, 2e-4, len(fidx))}, index=fidx
)
funding.to_parquet(out / "funding_BTCUSDT.parquet")
(out / "manifest.json").write_text(json.dumps({"outputs": {}}, indent=2))
print(f"synthetic data written to {out}: {n} bars, {len(fidx)} funding ticks")
|