Skip to content

fix: session filter, short weight cap, futures multiplier in cash checks, CAGR overflow - #129

Open
quantum-like wants to merge 5 commits into
ml4t:mainfrom
quantum-like:review/fixes
Open

quantum-like wants to merge 5 commits into
ml4t:mainfrom
quantum-like:review/fixes

Conversation

@quantum-like

Copy link
Copy Markdown

Owning issue

Closes #128

Outcome

5 correctness fixes, one commit each, each with a focused test:

  • filter_to_trading_sessions extended the exchange schedule one day before the first bar but stopped on the last UTC date. Overnight sessions such as the CME equity open start on the calendar day before their session date, so a bar in that open was dropped when the frame ended on the prior UTC date. The schedule end is now also extended by one day. Test: tests/test_calendar.py::test_filter_keeps_overnight_open_before_session_date. (3f6eac0)
  • TargetWeightExecutor applied max_single_weight with min(), which caps long targets only; a −50% target with a 25% cap stayed at −50%. Short targets are now floored at -max_single_weight. Test: tests/execution/test_rebalancer.py::test_max_single_weight_caps_short_targets. (abc0c4c)
  • The next-bar simple cash check valued an order at price × quantity, ignoring the contract multiplier, and then skipped the gatekeeper. One ES contract at 4,000 with multiplier 50 was treated as a $4,000 order, so a $200,000 buy filled against $100,000 of cash. Projected cash now uses price × quantity × multiplier. Test: tests/test_config_wiring.py::test_next_bar_simple_cash_check_includes_contract_multiplier. (e78288d)
  • Buying-power reservation for sequential fills had the same gap; the reservation now includes the multiplier. Equity orders are unchanged (multiplier 1). Test: tests/test_config_wiring.py::test_buying_power_reservation_includes_contract_multiplier. (cd49c85)
  • cagr() raised OverflowError when a very short window was annualized (e.g. a one-minute move from 100,000 to 101,000), which aborted EquityCurve.to_dict(). That case now returns infinity; finite windows use the same formula as before. Test: tests/test_equity_curve.py::test_short_window_cagr_does_not_overflow. (c9397df)

Compatibility

  • No public compatibility impact
  • Compatibility impact is documented in the owning issue and migration guidance

Results change only in the cases above (overnight-session bars kept, short targets capped, futures orders sized with the multiplier, overflowing CAGR reported as inf).

Verification

  • Tests reproduce the prior failure or verify the requested behavior (each listed test fails on main and passes with its fix)
  • Ruff lint and format checks pass (ruff format --check is clean on the changed files and ruff check reports nothing new in them versus main, but I did not run the full pre-commit suite)
  • ty passes (not run on this branch)
  • Test suite passes: pytest excluding benchmarks: 2198 passed, 9 skipped before; 2194 passed, 9 skipped, 9 failed after.
  • Package build passes when applicable (not run)
  • Strict MkDocs build passes when documentation is affected (no documentation changes)
  • Ecosystem qualification passes (not run)

The 9 failures are the retained-evidence checks in tests/contracts/test_parity_claim_generation.py and tests/contracts/test_real_strategy_runner.py. They hash the engine source files and compare against pins in validation/CORRECTNESS_RESULTS.json and validation/REAL_STRATEGY_RESULTS.json, so any engine source edit changes them. Refreshing those pins needs a re-derived cross-framework run that I could not do, so I left the published evidence files untouched. They are not behavior regressions, but they will need your refresh before merge.

Documentation and release

No documentation changes. The behavior changes above may be worth a line in the next patch-release notes.

Amir

cursoragent and others added 5 commits October 7, 2026 07:31
CME-style sessions open on the calendar day before their session date.
The filter expanded the schedule start but not the end, so a bar on that
open was removed whenever the frame's latest UTC date was still the prior day.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>
min() only upper-bounds a weight, so a short target more negative than the
configured cap was left unchanged. Apply the cap as a magnitude limit.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>
The open cash check treated notional as price times quantity and then
skipped the gatekeeper. A one-lot futures buy could fill and drive cash
negative. Scale the projected debit by the contract multiplier.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>
Sequential fills treat a reserved order as already validated and skip the
gatekeeper. The shadow reserved price times quantity, so a futures order
could fill for many times the reserved cash. Reserve price times quantity
times multiplier.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>
A one-minute equity gain made (final/initial) ** (1/years) exceed the float
range and raise OverflowError while assembling run metrics. Return infinity
for that overflow and leave finite windows unchanged.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Overnight session bar dropped, short weight cap ignored, futures multiplier missing from cash checks, CAGR overflow

2 participants