Skip to content

BUG: Fix simulation correctness bugs in slippage, cancel policy, and order params#316

Open
pandashark wants to merge 1 commit intostefan-jansen:mainfrom
pandashark:bugfix/simulation-correctness
Open

BUG: Fix simulation correctness bugs in slippage, cancel policy, and order params#316
pandashark wants to merge 1 commit intostefan-jansen:mainfrom
pandashark:bugfix/simulation-correctness

Conversation

@pandashark
Copy link

Summary

Fixes 5 simulation correctness bugs that can produce incorrect backtest results:

  • EOD cancel policy: execute_daily_cancel_policy only cancelled the first order per asset and skipped assets with a single order entirely. Replaced inline logic with cancel_all_orders_for_asset().
  • Slippage overfill: NoSlippage and FixedSlippage used order.amount instead of order.open_amount, overfilling partially filled orders.
  • Null price crash: VolumeShareSlippage returned bare None on NaN price instead of (None, None), causing TypeError during tuple unpacking.
  • Stuck flag: before_trading_start didn't reset _in_before_trading_start on exception, permanently blocking orders.
  • Zero price ignored: limit_price/stop_price used truthiness checks, treating 0.0 as falsy and silently converting to MarketOrder.

Closes #313

Test plan

  • Updated test_eod_order_cancel_daily to match corrected EODCancel behavior
  • Full test suite passes (3142 tests, 11 pre-existing pandas 2.3 failures)
  • flake8 clean on all modified files

…order params

Fix execute_daily_cancel_policy to cancel all orders for all assets,
not just the first order when multiple are open. Fix NoSlippage and
FixedSlippage to use order.open_amount instead of order.amount. Fix
VolumeShareSlippage to return (None, None) on null price. Wrap
before_trading_start in try/finally to reset _in_before_trading_start
flag on exception. Use 'is not None' for limit_price/stop_price checks
to allow price of 0.0.

Closes stefan-jansen#313
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: Simulation correctness bugs in slippage models, EOD cancel policy, and order parameter validation

1 participant