examples: fix and harmonize the strategy backtests across all languages (#324)
The strategy_* examples were only syntax-smoked in CI, never run, which hid two classes of problem: 1. Python strategy_macd_adx / strategy_bollinger_squeeze passed three separate arguments to the candle indicators ADX/ATR, whose .update() takes a single candle — a TypeError at runtime — and read the ADX tuple at index 0 (plus_di) instead of 2 (adx). Both fixed. 2. The Go / C# / R / Java strategies defaulted to synthetic data and used a different (annualised) one-line summary, so they printed wildly different numbers from the Rust/Python/Node/C/WASM suite. Rewrite them to the shared per-trade backtest (load the bundled BTCUSDT CSV by default, same entry/exit logic, same print_summary output). All nine runnable bindings now print byte-identical backtest summaries on the same data (MACD+ADX 246 trades / -47.19%, RSI 37 / -17.84%, Bollinger 1 / -7.82%), verified by diffing each language's output against the Python reference. WASM shares the same logic and bundled dataset (browser-rendered).
This commit is contained in:
@@ -115,7 +115,7 @@ def main() -> None:
|
||||
|
||||
for c in candles:
|
||||
bb_out = bb.update(c["close"])
|
||||
atr_val = atr.update(c["high"], c["low"], c["close"])
|
||||
atr_val = atr.update(c)
|
||||
price = c["close"]
|
||||
mtm = equity * (price / entry_price) if in_position else equity
|
||||
equity_curve.append(mtm)
|
||||
|
||||
Reference in New Issue
Block a user