fix(memory): keep future-resolved lessons out of point-in-time prompts - #1254
Open
hudsonwa wants to merge 1 commit into
Open
fix(memory): keep future-resolved lessons out of point-in-time prompts#1254hudsonwa wants to merge 1 commit into
hudsonwa wants to merge 1 commit into
Conversation
Decision-log reflections are grounded on realized outcomes and are re-injected as past_context for the portfolio manager. Recall was keyed only by ticker and recency, so a run for date D1 could be conditioned on a lesson derived from an outcome resolved on D2 > D1. Out-of-order or repeated backtests therefore leaked future information and could inflate apparent alpha (TauricResearch#1251). get_past_context() now accepts an optional as_of_date; entries whose tag date is later (or unparseable) are excluded, and _run_graph() passes the current trade_date through. Without as_of_date the behaviour is unchanged. Adds five regression tests covering future exclusion, same-day inclusion, cross-ticker lessons, back-compat, and malformed dates.
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.
Hi! First time contributing here, so thanks in advance for your patience with me.
Thank you as well to whoever wrote up #1251 so carefully; the file pointers made it genuinely easy to dig into, and out-of-order backtests are such an easy trap to fall into when you're iterating on dates.
I've had a go at a small fix. The idea:
get_past_context()now takes an optionalas_of_date, and any lesson whose outcome resolved after that date simply doesn't get shown to the agents. Same-day lessons stay in, since those are fair game.trading_graph.pypasses the run's trade date through automatically, so nobody has to remember to opt in. And if you don't pass a date at all, nothing changes, existing behaviour stays exactly as it was.Entries with unparseable dates are excluded rather than trusted, which seemed the safer side to land on, but happy to flip that if you'd prefer it to fail loud instead.
Tests: five new ones covering future exclusion, same-day inclusion, cross-ticker lessons, backwards compatibility, and malformed dates. Confirmed they fail against main without the change and pass with it, and the full suite is green (581 passed, 2 pre-existing skips).
Really enjoy what this project is building. Happy to tweak whatever doesn't fit the direction you want here. Cheers!