Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(backtest): report the global futures leverage default

cgycoreye6192eed9640
diff --git a/agent/backtest/engines/global_futures.py b/agent/backtest/engines/global_futures.py
index 803d94eb5..29aec77cf 100644
--- a/agent/backtest/engines/global_futures.py
+++ b/agent/backtest/engines/global_futures.py
@@ -199,7 +199,9 @@ class GlobalFuturesEngine(FuturesBaseEngine):
A product absent from the multiplier or commission table is not an error:
it is silently priced on a generic constant (50, ES's own multiplier, and
$2.50). The run reports every such fallback under ``pricing_assumptions``
- so a default cannot pass for data (#1393's failure class).
+ so a default cannot pass for data (#1393's failure class). Sizing is the
+ same kind of assumption with no product table to look it up in, so the
+ fixed leverage default is recorded there too, under product ``"*"``.
"""
def __init__(self, config: dict):
@@ -211,7 +213,12 @@ class GlobalFuturesEngine(FuturesBaseEngine):
# default, so the run has to say which numbers were assumed rather
# than looked up. Recording only: this recorder changes no value.
self._pricing_defaults: dict[tuple[str, str], Any] = {}
- leverage = config.get("leverage", 10.0)
+ if "leverage" in config:
+ leverage = config["leverage"]
+ else:
+ # Sizing has no product table: 10.0 is assumed, not looked up.
+ leverage = 10.0
+ self._pricing_defaults[("*", "leverage")] = leverage
config = {**config, "leverage": leverage}
super().__init__(config)
# Futures bands come off the previous settlement, not the previous close.
diff --git a/agent/tests/test_global_futures_digit_routing.py b/agent/tests/test_global_futures_digit_routing.py
index a1713059a..3182024d1 100644
--- a/agent/tests/test_global_futures_digit_routing.py
+++ b/agent/tests/test_global_futures_digit_routing.py
@@ -38,9 +38,15 @@ def test_contract_reaches_runner_pricing(symbol, product, multiplier, commission
engine._active_symbol = symbol
assert engine.calc_commission(2, 100, 1, True) == 2 * commission
assumptions = engine._engine_diagnostics().get("pricing_assumptions", [])
- assert assumptions == (
- [{"product": product, "field": "commission", "value": 2.5}] if product in {"OJ", "ZR"} else []
+ expected = (
+ []
+ if product not in {"OJ", "ZR"}
+ else [{"product": product, "field": "commission", "value": 2.5}]
)
+ assert assumptions == [
+ {"product": "*", "field": "leverage", "value": 10.0},
+ *expected,
+ ]
@pytest.mark.parametrize("symbol", ["M6E=F", "M6EZ4", "M6EZ2026.CME"])
@@ -50,7 +56,8 @@ def test_unlisted_digit_product_is_reported_without_invented_pricing(symbol):
assert _extract_product(symbol) == "M6E"
engine.get_contract_multiplier(symbol)
assert engine._engine_diagnostics()["pricing_assumptions"] == [
- {"product": "M6E", "field": "contract_multiplier", "value": 50}
+ {"product": "*", "field": "leverage", "value": 10.0},
+ {"product": "M6E", "field": "contract_multiplier", "value": 50},
]
diff --git a/agent/tests/test_global_futures_pricing_assumptions.py b/agent/tests/test_global_futures_pricing_assumptions.py
index 888151ea3..67dd77ee6 100644
--- a/agent/tests/test_global_futures_pricing_assumptions.py
+++ b/agent/tests/test_global_futures_pricing_assumptions.py
@@ -19,7 +19,8 @@ fill the tables, because filling them leaves the *next* added product silently
defaulting. Numbers are unchanged here; the run states which of them were
assumed. ``_PRICE_LIMIT`` is deliberately not reported: a product absent from
it is not "priced" on a fallback, it is simply not subject to a limit modelled
-for equity index contracts.
+for equity index contracts. Leverage is reported for the opposite reason: it
+has no product table to miss, so the fixed default is always an assumption.
"""
from __future__ import annotations
@@ -48,6 +49,11 @@ def _assumptions(engine: GlobalFuturesEngine) -> dict[tuple[str, str], object]:
return {(row["product"], row["field"]): row["value"] for row in reported}
+# Sizing has no product table, so every run that does not configure leverage
+# is priced on this assumption.
+_LEVERAGE_ASSUMED = {("*", "leverage"): 10.0}
+
+
class TestPricingAssumptionsAreReported:
def test_an_unlisted_product_reports_both_defaults(self) -> None:
engine = _engine("ZZZF25")
@@ -86,13 +92,23 @@ class TestPricingAssumptionsAreReported:
assert engine.get_contract_multiplier("ESZ4") == float(_DEFAULT_MULTIPLIER)
engine.calc_commission_for_symbol("ESZ4", 1, 6400.0, True)
- assert _assumptions(engine) == {}
+ assert _assumptions(engine) == _LEVERAGE_ASSUMED
- def test_a_fully_covered_run_declares_nothing(self) -> None:
+ def test_a_fully_covered_run_declares_only_the_leverage_assumption(self) -> None:
engine = _engine("ESZ4")
engine.get_contract_multiplier("ESZ4")
engine.calc_commission_for_symbol("ESZ4", 1, 6400.0, True)
+ assert engine._engine_diagnostics() == {
+ "pricing_assumptions": [
+ {"product": "*", "field": "leverage", "value": 10.0}
+ ]
+ }
+
+ def test_configured_leverage_is_not_reported_as_assumed(self) -> None:
+ engine = _engine("ESZ4", leverage=4.0)
+
+ assert engine.default_leverage == 4.0
assert engine._engine_diagnostics() == {}
def test_a_commission_override_is_not_a_table_default(self) -> None:
@@ -100,7 +116,7 @@ class TestPricingAssumptionsAreReported:
engine = _engine("ZZZF25", commission_per_contract=0.99)
assert engine.calc_commission(2.0, 400.0, 1, True) == 1.98
- assert _assumptions(engine) == {}
+ assert _assumptions(engine) == _LEVERAGE_ASSUMED
def test_the_warning_fires_once_per_field_not_once_per_bar(
self, caplog: pytest.LogCaptureFixture
@@ -172,3 +188,6 @@ class TestDiagnosticsSeam:
}
assert ("ZZZ", "contract_multiplier") in reported
assert ("ZZZ", "commission") in reported
+ # Sizing is assumed on every unconfigured run, so it must reach the
+ # same artifact the table fallbacks do.
+ assert ("*", "leverage") in reported