Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle DivisionByZero exception in indicators #7788

Conversation

Marinovsky
Copy link
Collaborator

Description

Prevent DivisionByZero exceptions in LEAN indicators when input data is extremely low, using a safe division method. This method returns a default or given value if the denominator of the division is zero. Additionally, it handles double-to-decimal cast exceptions.

Related Issue

Closes #7782

Motivation and Context

With this change indicators won't throw division by zero exceptions when the given values are extremely low

Requires Documentation Change

N/A

How Has This Been Tested?

Each indicator was pumped with extreme low values and asserted it to not throw any divide by zero exception. Besides, the Extensions.SafeDivision() method was tested in different scenarios that could raise division by zero or casting exceptions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Indicators/LogReturn.cs Outdated Show resolved Hide resolved
Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@Martin-Molinero Martin-Molinero merged commit 6f6fbee into QuantConnect:master Feb 19, 2024
5 of 6 checks passed
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.

System.Exception: Attempted to divide by zero. in LogReturn indicator
3 participants