Skip to content

fix(runtime): publish position metrics under the precision rules - #151

Merged
kcrmin merged 1 commit into
developfrom
feature/parity-position-metric-rounding
Aug 8, 2026
Merged

fix(runtime): publish position metrics under the precision rules#151
kcrmin merged 1 commit into
developfrom
feature/parity-position-metric-rounding

Conversation

@kcrmin

@kcrmin kcrmin commented Aug 8, 2026

Copy link
Copy Markdown
Member

Paired with backtest-engine's counterpart. Together they make the two runtimes publish the same number for the same position.

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.

Testability

PositionTracker becomes package-private, as ExecutionGate beside it already is, so the metrics can be tested directly rather than only through the whole evaluation loop.

PositionTrackerTest pins:

  • the rounding — fails against develop with expected: <0.00000002> but was: <0.00000003>
  • the peak carried across bars, so a fall from it is a drawdown rather than a loss
  • the entry bar counting as the first held bar
  • trading days being elapsed rather than inclusive, which is why the catalog can offer 당일 장 마감 as a distinct option from a one-trading-day hold

Verification

./gradlew build — BUILD SUCCESSFUL, whole repo.

🤖 Generated with Claude Code

`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>
@kcrmin
kcrmin merged commit f806f0c into develop Aug 8, 2026
2 checks passed
@kcrmin
kcrmin deleted the feature/parity-position-metric-rounding branch August 8, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant