fix: round 2 backtest engine correctness and performance fixes#37
Merged
Conversation
…filter, NaN benchmark, bounded locks, _bare_code helper, _to_tv_date simplification
…ify eviction logic, tighten test assertion
Copilot
AI
changed the title
fix: EasyQuant 第二轮优化 — ORDER_TARGET partial fill, ORDER_TIMEOUT filter, NaN benchmark, bounded locks, _bare_code, _to_tv_date
fix: round 2 backtest engine correctness and performance fixes
May 28, 2026
Copilot created this pull request from a session on behalf of
AlanFokCo
May 28, 2026 08:18
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second optimization pass on the EasyQuant backtest framework, targeting correctness bugs in order execution and attribution, plus memory/performance improvements.
Bug fixes
engine.py): Remaining order after partial fill now keeps the originaltarget_amount. The engine already computesdelta = target - current_positionon the next bar, so subtracting filled shares caused systematic undershoot.ORDER_TIMEOUT crashes attribution (
attribution.py):_calc_trade_win_rate()and_calc_profit_loss_ratio()now skip non-BUY/SELL entries. ORDER_TIMEOUT log entries lackprice/amountkeys, causingKeyError.NaN propagation in excess metrics (
attribution.py):_calc_excess_metrics()appliesfillna(0)on benchmark returns before subtraction, preventing NaN from poisoning all downstream excess return metrics.Performance / memory
Unbounded
_file_locksdict (data_cache.py): Capped at 1024 entries with eviction of unlocked entries. Previously grew monotonically in long-running services._to_tv_date()simplification (report.py): Collapsed 5isinstancechecks to 1 —datetime.datecoversdatetime.datetimeandpd.Timestampvia inheritance._bare_code()helper (engine.py): Extracted the repeated.replace(".XSHG","").replace(".XSHE","")pattern (6 call sites) into a single function.Tests
17 new tests in
test_round2_fixes.pycovering all fixes. 391 total pass (374 + 17).