fix(runtime): make the live runtime agree with the official backtest - #150
Merged
Conversation
Two places where a released bot did not do what its own backtest showed. `session.close` came from the clock, not the calendar. It was true only when the market hour read 16:00, but the market closes at 13:00 ET the day after Thanksgiving, on Christmas Eve, and on July 3. On those days live never published the flag at all, so a SESSION_CLOSE exit silently did not run while the backtest, which reads the session's real closesAt, exited as written. The flag now follows the daily candle, which is finalized at the session close, so one calendar governs both runtimes and early closes need no special case. RSI_14 had a second implementation. The interpreter recomputed it from the closes series at 18 significant digits with HALF_UP and never quantized, while `rsi:1.0.0` is 34 digits with HALF_EVEN quantized to 8 and the backtest reads the series that definition published. Two implementations that merely agree are not one feature: a window whose value sat a rounding step from the threshold crossed it on one side and not the other. RSI_14 now delegates to OfficialFeatureCatalog, so the definition has exactly one implementation, and periods the catalog does not define use the same procedure at the same precision rather than a looser one. OfficialFeatureCatalog.quantize is public for that reason -- one quantizer, not a copy of it. Both are pinned by tests that fail without the change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Two places where a released bot did not do what its own backtest showed. Paired with backtest-engine #68.
session.closecame from the clock, not the calendarIt was true only when the market hour read 16:00. The market closes at 13:00 ET the day after Thanksgiving, on Christmas Eve, and on July 3. On those days live never published the flag at all, so a
SESSION_CLOSEexit silently did not run, while the backtest reads the session's realclosesAtand exited as written.The flag now follows the daily candle, which the gateway finalizes at the session close (
FinalizedCandleBoundaryPlannercaps the last boundary atsession.closesAt()). One calendar governs both runtimes and early closes need no special case — no protocol change, sinceclosed1dis already on the wire.RSI_14 had a second implementation
BasicPlanInterpreterrecomputed it from the closes series at 18 significant digits withHALF_UP, never quantized.rsi:1.0.0is 34 digits withHALF_EVENquantized to 8, and the backtest reads the series that definition published.Two implementations that merely agree are not one feature: a window whose value sat a rounding step from the threshold crossed it on one side and not the other. RSI_14 now delegates to
OfficialFeatureCatalog, so the definition has exactly one implementation. Periods the catalog does not define — it defines only 14 — use the same procedure at the same precision rather than a looser one.OfficialFeatureCatalog.quantizeis public for that reason: one quantizer, not a copy of it.Verification
rsi14IsTheOfficialCatalogValueRatherThanASecondImplementationasserts the value live publishes equals the catalog's exactly, for both the current and previous window. It fails againstdevelop.session.closecases added, covering the 2025-11-28 early close, the usual 16:00 hour when the day has not ended, and a regular close../gradlew build— BUILD SUCCESSFUL, whole repo.🤖 Generated with Claude Code