release: v0.21.0

This commit is contained in:
Jimmy7892
2026-10-23 23:06:12 +02:00
parent 05204c9ca6
commit 71b542fe4b
50 changed files with 1403 additions and 340 deletions
+28 -10
View File
@@ -8,7 +8,7 @@ Demonstrates:
The standard format is a header row + `timestamp,open,high,low,close,volume`
where timestamp is Unix milliseconds. MT4/MT5 exports are auto-detected.
Data: synthetic — a sample generated by this file, reproducible
Data: synthetic (seed 18) — a sample generated by this file, reproducible
Usage:
python examples/18_csv_import.py
@@ -16,6 +16,8 @@ Usage:
import os
import tempfile
import numpy as np
import manifoldbt as mbt
from manifoldbt.indicators import close, ema
from manifoldbt.helpers import time_range, Interval
@@ -26,17 +28,31 @@ from manifoldbt.helpers import time_range, Interval
tmp = tempfile.mkdtemp()
csv_path = os.path.join(tmp, "SAMPLE_1m.csv")
# 120 days of 1-minute bars. The span is the point: annualised metrics (CAGR,
# Calmar) divide by the length of the window, so a fixture covering two days
# reports a growth rate with fifty digits in it and teaches the reader nothing
# except that nobody read the output.
N = 120 * 1440
rng = np.random.default_rng(18)
steps = rng.normal(1.4e-6, 4.0e-4, N) # ~+20% over the window
px = 100.0 * np.exp(np.cumsum(steps))
o = px
c = np.roll(px, -1)
c[-1] = px[-1]
amp = np.abs(rng.normal(0.0, 2.0e-4, N))
hi = np.maximum(o, c) * (1 + amp)
lo = np.minimum(o, c) * (1 - amp)
vol = rng.uniform(1_000, 5_000, N)
base_ms = 1_704_067_200_000 # 2024-01-01 00:00 UTC
px = 100.0
with open(csv_path, "w") as f:
f.write("timestamp,open,high,low,close,volume\n")
for i in range(3000):
ts = base_ms + i * 60_000 # 1-minute bars
nxt = px * (1.0 + (0.0009 if i % 3 else -0.0007))
hi = max(px, nxt) + 0.05
lo = min(px, nxt) - 0.05
f.write(f"{ts},{px:.4f},{hi:.4f},{lo:.4f},{nxt:.4f},{1000 + i}\n")
px = nxt
f.write("\n".join(
f"{base_ms + i * 60_000},{o[i]:.4f},{hi[i]:.4f},{lo[i]:.4f},{c[i]:.4f},{vol[i]:.0f}"
for i in range(N)
))
f.write("\n")
# -- 2. Import into the store (free, all tiers) -------------------------------
store = mbt.import_csv(
@@ -59,7 +75,7 @@ strategy = (
.describe("EMA(10/30) crossover on CSV-imported data")
)
start, end = time_range("2024-01-01", "2024-01-04")
start, end = time_range("2024-01-01", "2024-05-01")
config = mbt.BacktestConfig(
universe=[1],
time_range_start=start,
@@ -71,4 +87,6 @@ config = mbt.BacktestConfig(
if __name__ == "__main__":
result = mbt.run(strategy, config, store)
print("The series carries a mild upward drift, so the figures below")
print("describe the fixture. The mechanism on show is the import.\n")
print(result.summary())