Hello, I am trying to use the RateOfChangePercent indicator, but instead of setting a period to calculate the two values, I want to determine the rate of change from the opening price of the day to the current price at any minute during the day. For example, an open price at 9:30 am of $20.00 compared to a price at 10:30 of $22,00 which would be a percent change of 10%, then later in the day, the price at 1:30 pm of $19.50 is a percent change of -5%. This would reset the calculation every morning at the market open. Looking to do this with minute resolution.
I have been able to do this calculation in the OnData section, but have not been able to figure out how to do it in the Initialize section.
Any help would be great, thank you.
Shile Wen
Hi Tate,
One way to do this would be to create a dict of opening prices keyed by Symbols, which can either be updated using a Scheduled Event or the first bar of the day from OnData, then divide the current price from OnData by the opening price from the dict. Please note that this will only work with resolutions below Daily resolution.
Best,
Shile Wen
Tate Linzel
So there is no way to do this in the initialize section? as I was looking to use the indicator features in the initialize area like moving averages. Here is what I was able to accomplish, but again this is done in the On Data section.
Derek Melchin
Hi Tate,
The RateOfChange indicator calculates the return over a fixed lookback period. Since the goal is to compute the return from the market open, we can instead determine the rate of change manually.
if data.Time.day != self.day: self.open_price = data[self.symbol].Open self.day = data.Time.day close_price = data[self.symbol].Close roc_since_open = (close_price - self.open_price) / self.open_price
See the attached backtest for reference.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Tate Linzel
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!