Skip to content

Replace f64 with Decimal or Positive in Options Struct and Methods #83

@joaquinbejar

Description

@joaquinbejar

Description

Update the Options struct and its associated methods to replace f64 fields with Decimal or Positive where applicable. This change ensures higher precision and enforces positive values for fields that should not accept negative numbers.


Tasks

Code Changes

  • Replace the implied_volatility field type from f64 to Decimal.
  • Replace the risk_free_rate field type from f64 to Decimal.
  • Replace the dividend_yield field type from f64 to Decimal.
  • Ensure compatibility between Positive and Decimal for calculations involving Positive fields.

Method Updates

  • Refactor methods to accommodate Decimal or Positive changes.
    • Update calculations involving implied_volatility, risk_free_rate, or dividend_yield to use Decimal math operations.
    • Validate that fields and calculations respect precision requirements.
  • Add error handling or validations where necessary to ensure no invalid conversions occur between types.

Testing

  • Write or update unit tests to verify:
    • Correct instantiation of Options struct with Decimal and Positive fields.
    • Accurate calculations in methods using the updated field types.
    • Validation of edge cases such as zero or invalid input values.
  • Run tests to confirm that the refactored code works as intended.

Documentation

  • Update documentation or comments for the Options struct to reflect the new types.
  • Provide examples of how to use the updated struct and its methods.

Additional Notes

  • Ensure all dependencies for Decimal and Positive are properly imported and configured.
  • Consider the potential performance implications of switching from f64 to Decimal and optimize where necessary.
  • Verify that the changes align with the project's broader goals for precision and data validation.

Labels

enhancement, refactor, precision, data-validation, 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