Skip to content

Replace f64 with Decimal in DeltaInfo Struct #105

@joaquinbejar

Description

@joaquinbejar

Description

Refactor the DeltaInfo struct to replace all instances of the f64 type with the Decimal type. This change aims to improve numerical precision and reduce the risk of floating-point inaccuracies, especially in financial calculations where precision is critical. Ensure that all associated methods, logic, and tests are updated to accommodate this change.


Tasks

Implementation:

  • Replace the f64 fields in the DeltaInfo struct with Decimal:
    • net_delta: Decimal
    • individual_deltas: Vec<Decimal>
    • neutrality_threshold: Decimal
  • Update any methods or logic that rely on these fields to use the Decimal type.
  • Ensure compatibility with the Positive type for underlying_price.

Testing:

  • Update existing unit tests to use Decimal values instead of f64.
  • Add new tests to validate the behaviour with precise decimal inputs, including edge cases:
    • Very small and very large values.
    • Decimal rounding scenarios.

Documentation:

  • Update documentation for the DeltaInfo struct to reflect the change to Decimal.
  • Add comments to explain the choice of Decimal for enhanced precision.

Additional Notes

  • Consider using the rust_decimal crate for the Decimal implementation.
  • Ensure that any external interfaces or serialization/deserialization mechanisms (e.g., JSON) are compatible with the Decimal type.
  • Verify performance implications of using Decimal in calculations and provide benchmarks if necessary.

Labels

refactor, precision, enhancement, testing, documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions