-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
base: master
Are you sure you want to change the base?
Fix warming up bug in Stochastic indicator #8422
Conversation
There was a problem hiding this 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
var symbols = new[] { symbol }; | ||
CheckPeriodBasedHistoryRequestResolution(symbols, resolution, null); | ||
historyRequest = CreateBarCountHistoryRequests(symbols, periods, resolution, dataNormalizationMode: GetIndicatorHistoryDataNormalizationMode(indicator)).Single(); | ||
return GetSlicesFromHistoryRequests(historyRequest); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
Description
When a stochastic indicator was registered with a consolidator whose resolution differed the symbol one, the method
QCAlgorithm.WarmUpIndicator()
failed warming it up. SincePeriodCountConsolidatorBase
class was used, it skipped the last bar from history, so the indicator received onlyWarmingUpPeriod - 1
points. Thus, the indicator was left unready. Following the pattern ofRelativeStrenghtIndex
indicator, I increasedStochastic.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
Checklist:
bug-<issue#>-<description>
orfeature-<issue#>-<description>