Skip to content

Fix generate_delta_increasing_adjustments to Handle Zero Delta in DeltaNeutrality Trait #126

@joaquinbejar

Description

@joaquinbejar

Description

The current implementation of generate_delta_increasing_adjustments in the DeltaNeutrality trait does not properly handle cases where delta is zero. The calculation:

let qty = Positive((net_delta.abs() / delta).abs());

can lead to a division-by-zero error when delta == 0. This issue aims to implement a safeguard to prevent this error and ensure stability in delta-neutral adjustments.


Tasks

Implementation:

  • Modify the calculation to handle the case where delta == 0.
  • Introduce a conditional check to avoid division by zero.
  • Determine an appropriate fallback mechanism, such as:
    • Skipping adjustments.
    • Using a small epsilon value to prevent zero division.
    • Logging a warning or returning an error.

Testing:

  • Add test cases for generate_delta_increasing_adjustments that include:
    • delta == 0
    • delta with very small values approaching zero.
    • Normal delta values for regression testing.

Documentation:

  • Update the method documentation to explain how zero delta cases are handled.
  • Add comments in the code to clarify the fix.

Additional Notes

  • Ensure the fix does not introduce unintended side effects in delta adjustments.
  • The implementation should follow the project's error handling and logging conventions.
  • Consider discussing with the team whether a fallback strategy (e.g., a minimal default value) is preferable over skipping adjustments.

Labels

bug, delta-neutrality, error-handling, 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