Repository navigation
Add StrategyScenario test harness (#625) - #647
Open
zorionarrillaga wants to merge 4 commits into
Open
zorionarrillaga wants to merge 4 commits into
zorionarrillaga wants to merge 4 commits into
Conversation
activate_event_memory routes repository calls into an existing EventMemoryState without owning it; event_memory_scope now builds on it. record_emission is the per-order body of RecordCooldownPhase, moved unchanged so other callers can record cooldown history.
StrategyScenario seeds a strategy test with cash, long and short trade lots, pending orders, stop-loss and take-profit rules, trailing state and cooldown history. Every seed goes through the production order and trade services, is validated before anything changes (ScenarioSetupError) and is followed by a consistency check of cash, positions, cost basis, lots and reservations (ScenarioStateError). Each scenario keeps its state in its own EventMemoryState and builds its App without create_app, storage or wiring, so scenarios share no state and touch no database, network, environment or files.
Release the strategy binding when a scenario is collected without close(), keep services reached through scenario.context scoped to the scenario, book pending reservations at the order's reservation price (STOP orders have no limit price), reject pair symbols, marks that predate earlier marks or rules, malformed constructor arguments and a start off the UTC hour, and track cooldown seeding order per symbol.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #647 +/- ##
==========================================
+ Coverage 82.62% 82.83% +0.20%
==========================================
Files 698 701 +3
Lines 70594 71349 +755
==========================================
+ Hits 58331 59104 +773
+ Misses 12263 12245 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <[email protected]>
This branch has not been deployed
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.
Closes #625.
What
StrategyScenario(ininvesting_algorithm_framework.testing, also exported at the top level) sets up the state astrategy test needs before its next evaluation:
How
Contextfollowed byOrderService.updateas the fill. Rules useContext.add_stop_loss/add_take_profit, with the same lookup asAttachRiskRulesPhase. Marks use theTradeService.updatecall the backtest evaluator makes. Cooldowns use theper-order body of
RecordCooldownPhase, extracted unchanged asrecord_emission. Cash, legs, cost basis, lots, FIFOSELL allocations and reservations therefore move as they do in a backtest.
ScenarioSetupError(anOperationalException) with the call, the numbers and a fix. Examples: not enough cash once fees and pendingreservations are counted; an opposite-direction lot in NETTING (pointing to
PositionMode.HEDGE); over-selling orover-covering; a mark that would already trigger a rule.
check_consistency()runs after every seed and raisesScenarioStateErrorlisting eachinvariant that does not hold:
Appand container withoutcreate_app, storage setup or wiring, and keepsall repository rows in its own
EventMemoryState(the store event backtests use withevent_state_backend="memory").It activates that store around every call through the new
activate_event_memoryhelper. No database, network,credentials,
.envor environment overrides are involved.close()(or leaving thewithblock) releases everything.Choices you may want to redirect (each lives in one place):
Sessionis module-global, so two SQL-backedapps in one process share it.
apply_strategy_rules=True).investing_algorithm_framework.testing.StrategyScenario, re-exported at the top level.Verified
tests/testing/test_strategy_scenario.py: 32 tests in under 1 s, oneTestCaseper acceptance criterion. It writes nofiles and runs with sockets patched to raise.
tests/app, the only two errors also occur onmainin my environment: the tqdm notebook display patch needsIPython.
Not included: evaluation steps (#626), results (#627) and examples (#628).
check_consistencybooks an order filledin chunks at different prices at its last price. The harness never creates that, but it should be revisited when #626
adds evaluation steps.