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

warm_up_indicator fails to warm up Stochastic indicator #8405

Open
4 tasks done
alexschwantes opened this issue Nov 14, 2024 · 0 comments · May be fixed by #8422
Open
4 tasks done

warm_up_indicator fails to warm up Stochastic indicator #8405

alexschwantes opened this issue Nov 14, 2024 · 0 comments · May be fixed by #8422
Assignees
Labels

Comments

@alexschwantes
Copy link

Expected Behavior

self.warm_up_indicator(symbol, indicator, timedelta(hours=1) warms up the Stochastic indicator.

Actual Behavior

self.warm_up_indicator(symbol, indicator, timedelta(hours=1) does not warm up the Stochastic indicator.

Potential Solution

Stochastic indicator extends IIndicatorWarmUpPeriodProvider so it is expected to work
potentially similar to #8246

Reproducing the Problem

Below is code and output of warming up RSI and STO indicators with a manual history request (which works) and the warm_up_indicator() method, which works on the RSI but not the STO...

warmup-bug

from datetime import timedelta
from AlgorithmImports import *


class FT1Indexes(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 1, 1)  # monday = holiday..
        self.set_end_date(2024, 2, 1)
        self.set_cash(100000)

        self.spy = self.add_equity("SPY", Resolution.HOUR).symbol

        self.daily_consolidator = TradeBarConsolidator(timedelta(days=1))

        self._rsi = RelativeStrengthIndex(14, MovingAverageType.WILDERS)
        self._sto = Stochastic(14, 3, 3)
        self.register_indicator(self.spy, self._rsi, self.daily_consolidator)
        self.register_indicator(self.spy, self._sto, self.daily_consolidator)

        # warm_up indicator
        self.warm_up_indicator(self.spy, self._rsi, timedelta(days=1))
        self.warm_up_indicator(self.spy, self._sto, timedelta(days=1))


        self._rsi_history = RelativeStrengthIndex(14, MovingAverageType.WILDERS)
        self._sto_history = Stochastic(14, 3, 3)
        self.register_indicator(self.spy, self._rsi_history, self.daily_consolidator)
        self.register_indicator(self.spy, self._sto_history, self.daily_consolidator)

        # history warm up
        history = self.history[TradeBar](self.spy, 20, Resolution.DAILY)
        for bar in history:
            self._rsi_history.update(bar.end_time, bar.close)
            self._sto_history.update(bar)

    def on_data(self, data: Slice):
        if self.is_warming_up:
            return

        if data.contains_key(self.spy):
            chart_name = "warm_up_indicator"
            self.plot(chart_name, "RSI", self._rsi.current.value, Color.Red)
            self.plot(chart_name, "STO K", self._sto.stoch_k.current.value)
            self.plot(chart_name, "STO D", self._sto.stoch_d.current.value)

            chart_name = "History Warmup"
            self.plot(chart_name, "RSI", self._rsi_history.current.value)
            self.plot(chart_name, "STO K", self._sto_history.stoch_k.current.value)
            self.plot(chart_name, "STO D", self._sto_history.stoch_d.current.value)

System Information

cloud

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants