Download synth_gen.py from Avi-L/crypto-quant-eval: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/Avi-L/crypto-quant-eval/resolve/main/synth_gen.py
- Command line
-
hf download hf://Avi-L/crypto-quant-eval/synth_gen.py
-
curl -L -o synth_gen.py https://huggingface.co/Avi-L/crypto-quant-eval/resolve/main/synth_gen.py
1.37 kB
| """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") | |