Skip to content

Conversation

nicolad
Copy link
Member

@nicolad nicolad commented Aug 26, 2025

The decode_multiplier function was using floating-point arithmetic (value as f64 / 1e9)
followed by string formatting, which introduced precision loss for financial calculations.
This could lead to incorrect multipliers affecting P&L, position sizing, and risk calculations.

Changes:

  • Replace floating-point division with exact integer arithmetic
  • Handle fixed-point scaling (1e-9) using integer operations only
  • Preserve exact decimal representation without rounding errors
  • Add comprehensive test coverage for edge cases
  • Remove unused DATABENTO_FIXED_SCALAR constant

The fix ensures multipliers are decoded with perfect precision, maintaining consistency
with other decode functions that use exact integer arithmetic for financial values.

…recision loss

The decode_multiplier function was using floating-point arithmetic (value as f64 / 1e9)
followed by string formatting, which introduced precision loss for financial calculations.
This could lead to incorrect multipliers affecting P&L, position sizing, and risk calculations.

Changes:
- Replace floating-point division with exact integer arithmetic
- Handle fixed-point scaling (1e-9) using integer operations only
- Preserve exact decimal representation without rounding errors
- Add comprehensive test coverage for edge cases
- Remove unused DATABENTO_FIXED_SCALAR constant

The fix ensures multipliers are decoded with perfect precision, maintaining consistency
with other decode functions that use exact integer arithmetic for financial values.
@nicolad nicolad requested a review from cjdsellers August 26, 2025 03:12
@nicolad nicolad self-assigned this Aug 26, 2025
@nicolad nicolad changed the title fix: Use precise integer arithmetic in decode_multiplier to prevent p… Use precise integer arithmetic in decode_multiplier to prevent precision loss Aug 26, 2025
@cjdsellers
Copy link
Member

Thanks for the improvement @nicolad 👌

@cjdsellers cjdsellers merged commit cd699e9 into develop Aug 26, 2025
13 checks passed
@cjdsellers cjdsellers deleted the fix/databento-decode-multiplier-precision branch August 26, 2025 05:48
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.

2 participants