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

Fix warming up bug in Stochastic indicator #8422

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Marinovsky
Copy link
Collaborator

Description

When a stochastic indicator was registered with a consolidator whose resolution differed the symbol one, the method QCAlgorithm.WarmUpIndicator() failed warming it up. Since PeriodCountConsolidatorBase class was used, it skipped the last bar from history, so the indicator received only WarmingUpPeriod - 1 points. Thus, the indicator was left unready. Following the pattern of RelativeStrenghtIndex indicator, I increased Stochastic.WarmUpPeriod by one to solve this bug. I also added unit and regression tests to cover these changes.

Related Issue

Closes #8405

Motivation and Context

With this change, Stochastic indicators registered with different resolution consolidators, will be warmed up by QCAlgorithm.WarmUpIndicator()

Requires Documentation Change

N/A

How Has This Been Tested?

Since I increased Stochastic's WarmUpPeriod by one, I had to update the unit test StochasticTestsWarmsUpProperly(). On the other hand, as a regression algorithm, I added the algorithm shared by the user reproducing the bug and asserted the bug was solved.

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>

@Martin-Molinero Martin-Molinero requested review from jhonabreul and removed request for jhonabreul November 22, 2024 20:20
@Marinovsky Marinovsky closed this Nov 25, 2024
@Marinovsky Marinovsky reopened this Nov 27, 2024
Copy link
Collaborator

@jhonabreul jhonabreul left a comment

Choose a reason for hiding this comment

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

Good! Nice catch on the actual root issue. Leaving a couple comments

Comment on lines +3154 to +3157
var symbols = new[] { symbol };
CheckPeriodBasedHistoryRequestResolution(symbols, resolution, null);
historyRequest = CreateBarCountHistoryRequests(symbols, periods, resolution, dataNormalizationMode: GetIndicatorHistoryDataNormalizationMode(indicator)).Single();
return GetSlicesFromHistoryRequests(historyRequest);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using the History() API might be enough, if you only need the request end time you could use QCAlgorithm.Time or UtcTime and convert it to the security's time zone to do the final consolidator scan

RegisterIndicator(_spy, _rsiHistory, dailyConsolidator);
RegisterIndicator(_spy, _stoHistory, dailyConsolidator);

var history = History(_spy, 15, Resolution.Daily);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit - for clarity, might use Max(_rsi.WarmupPeriod, _sto.WarmupPeriod) instead of 15. And then tp update the indicators might use something like history.TakeLast(indicator.WarmupPeriod)

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.

warm_up_indicator fails to warm up Stochastic indicator
2 participants