Avi-L commited on
Commit
cf678fc
·
verified ·
1 Parent(s): 672df78

synthetic data generator for smoke tests

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