fix(runtime): publish position metrics under the precision rules - #151
Merged
Conversation
`position.returnPercent` and the peak and drawdown beside it were rounded HALF_UP at scale 8. `precision:1.0.0` is HALF_EVEN at scale 8, and the official backtest quantizes these HALF_EVEN accordingly, so an exact tie at the ninth decimal published two different numbers for one position. These are the values a POSITION_RETURN, PEAK_RETURN or DRAWDOWN_FROM_PEAK step compares against its threshold, and their rendered form reaches the step trace -- so the disagreement was both in what the strategy decided at the boundary and in what the two runtimes recorded having decided. PositionTracker becomes package-private, as ExecutionGate beside it already is, so the metrics can be tested directly. PositionTrackerTest pins the rounding, the peak carried across bars, the entry bar counting as the first held bar, and trading days being elapsed rather than inclusive -- the last of these matching the backtest, which is why the catalog can offer `당일 장 마감` as a distinct option from a one-trading-day hold. 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.
Paired with backtest-engine's counterpart. Together they make the two runtimes publish the same number for the same position.
position.returnPercentand the peak and drawdown beside it were rounded HALF_UP at scale 8.precision:1.0.0is HALF_EVEN at scale 8, and the official backtest quantizes these HALF_EVEN accordingly — so an exact tie at the ninth decimal published two different numbers for one position.These are the values a
POSITION_RETURN,PEAK_RETURNorDRAWDOWN_FROM_PEAKstep compares against its threshold, and their rendered form reaches the step trace. So the disagreement was both in what the strategy decided at the boundary and in what the two runtimes recorded having decided.Testability
PositionTrackerbecomes package-private, asExecutionGatebeside it already is, so the metrics can be tested directly rather than only through the whole evaluation loop.PositionTrackerTestpins:developwithexpected: <0.00000002> but was: <0.00000003>당일 장 마감as a distinct option from a one-trading-day holdVerification
./gradlew build— BUILD SUCCESSFUL, whole repo.🤖 Generated with Claude Code