summaryrefslogtreecommitdiff
path: root/tests/fixtures_synth.py
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-17 14:32:37 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-17 14:32:37 +0800
commit5c0ba37eda80d39e6ceca59bb1d5f4942f858995 (patch)
tree948723f9cedf7ccb0707fa6ee516bd30fe20fd10 /tests/fixtures_synth.py
downloadstrategy-lab-5c0ba37eda80d39e6ceca59bb1d5f4942f858995.tar.gz
chore: establish Strategy Lab source baseline (development, not release)
Diffstat (limited to 'tests/fixtures_synth.py')
-rw-r--r--tests/fixtures_synth.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/fixtures_synth.py b/tests/fixtures_synth.py
new file mode 100644
index 0000000..69b305b
--- /dev/null
+++ b/tests/fixtures_synth.py
@@ -0,0 +1,39 @@
+"""Deterministic synthetic OHLCV fixtures for worker tests.
+
+Every object here carries ``_synthetic: true`` and must never be used as a
+production fallback. Values are simple deterministic series so accounting
+ assertions in backtest tests can be hand-verified.
+"""
+import pandas as pd
+
+_SYNTHETIC = {"_synthetic": True}
+
+
+def synthetic_daily(symbol: str = "SH#600000", start="2024-01-02", days=20,
+ base=10.0, volume=1_000_000, extra_fields=True) -> pd.DataFrame:
+ dates = pd.bdate_range(start, periods=days)
+ rows = []
+ price = base
+ for i, d in enumerate(dates):
+ o = round(price, 2)
+ c = round(price * 1.02, 2) if i % 2 == 0 else round(price * 0.98, 2)
+ h = round(max(o, c) * 1.01, 2)
+ l = round(min(o, c) * 0.99, 2)
+ row = {
+ "date": d.strftime("%Y-%m-%d"),
+ "symbol": symbol,
+ "open": o, "high": h, "low": l, "close": c,
+ "volume": volume + i * 1000,
+ }
+ if extra_fields:
+ # raw provider-style extra fields preserved verbatim
+ row["amount"] = round((o + h + l + c) / 4 * (volume + i * 1000), 2)
+ row["turnover"] = round(0.5 + i * 0.01, 3)
+ rows.append(row)
+ price = c
+ df = pd.DataFrame(rows)
+ df.attrs["synthetic"] = True
+ return df
+
+
+SYNTH = _SYNTHETIC