I am on a FREE plan. I observe that even though I set resolution to be at Minute level, I don't see OnData being called every minute. My logs indicate that many times it's getting called after 6-7 hours. Why is that?
from AlgorithmImports import *
from datetime import *
from Globals import MyGlobals
class IronButterflyAlgorithm(QCAlgorithm):
last_time_ondata_called: datetime = datetime.min
def Initialize(self):
self.SetStartDate(2018, 7, 1)
self.SetEndDate(2023, 7, 1)
self.SetCash(100000)
ticker = "SPY"
option: Option = self.AddOption(ticker, Resolution.Minute)
equity_symbol = self.AddEquity(ticker, Resolution.Minute).Symbol
def OnData(self, slice):
if self.IsWarmingUp:
# self.Debug(f"{slice.Time} - Warming up")
return
if (self.last_time_ondata_called == datetime.min):
# first time OnData called
self.last_time_ondata_called = slice.Time
else:
# check for being called after 5 minutes
if (slice.Time - self.last_time_ondata_called).seconds > (5 * 60):
self.Debug(
f"{slice.Time} OnData being called after {(slice.Time - self.last_time_ondata_called).seconds/60.0} minutes")
self.last_time_ondata_called = slice.Time
Output snippet
434
|
8:54:06
:
2020-02-10 09:31:00 OnData being called after 1051.0 minutes
435
|
8:54:06
:
2020-02-11 09:31:00 OnData being called after 1051.0 minutes
436
|
8:54:10
:
2020-02-12 09:31:00 OnData being called after 1051.0 minutes
437
|
8:54:10
:
2020-02-13 09:31:00 OnData being called after 1051.0 minutes
438
|
8:54:10
:
2020-02-14 09:31:00 OnData being called after 1051.0 minutes
439
|
8:54:10
:
2020-02-18 09:31:00 OnData being called after 1051.0 minutes
440
|
8:54:10
:
2020-02-19 09:31:00 OnData being called after 1051.0 minutes
441
|
8:54:14
:
2020-02-20 09:31:00 OnData being called after 1051.0 minutes
442
|
8:54:14
:
2020-02-21 00:00:00 OnData being called after 480.0 minutes
443
|
8:54:14
:
2020-02-21 09:31:00 OnData being called after 571.0 minutes
444
|
8:54:14
:
2020-02-22 00:00:00 OnData being called after 480.0 minutes
445
|
8:54:14
:
2020-02-24 09:31:00 OnData being called after 571.0 minutes
446
|
8:54:14
:
2020-02-25 09:31:00 OnData being called after 1051.0 minutes
447
|
8:54:17
:
2020-02-26 09:31:00 OnData being called after 1051.0 minutes
448
|
8:54:17
:
2020-02-27 09:31:00 OnData being called after 1051.0 minutes
Mia Alissi
The
OnData
method in your algorithm is the primary event handler for receiving financial data events. It is triggered sequentially at the point in time the data is available; in backtesting and live. For daily data, this means the event is processed at midnight in backtesting or 6am the following day in live trading (source).However, it's important to note that the
OnData
event handler will be called regularly even if there was no new data. This is the default behavior when fill-forward is enabled for your asset.In your case, you are subscribing to minute-level data for the "SPY" equity and its options. The
OnData
method should be called every minute when there is data for these assets. However, it seems like theOnData
method is being called at the start of each trading day (9:31 AM) and then not being called again until the next trading day. This could be due to the lack of data for the assets you are subscribing to.If you are using custom data or certain types of options data, it's possible that the data is not available at every minute. For example, if you are using US Index Options data, the
Slice
may not contain data for your Index Option at every time step (source).To debug this issue, you could log the data that is available in the
Slice
object in theOnData
method. This will help you understand what data is available at each time step. Here is an example of how to do this:This will log all the data that is available in the
Slice
at each time step. If you see that there is no data for the "SPY" equity or its options at certain time steps, this could explain why theOnData
method is not being called every minute.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.
Prashd
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!