When is OnData(Slice) triggered?

Back

I thought it is triggered according to resolution of universe. But it is not triggered daily while my universe resolution is set to daily in my backtest below. What am I missing?

Update Backtest






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.



 
0

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.


Hi Bill. OnData is triggered whenever new data comes in which, in the case of your algorithm, really should be daily. What output are you looking at which suggests it's not triggered daily?

0

Hi Douglas.

In Logs menu in a backtest of my code OnData is triggered twice at 20070703 00:00:00 and 20070704 00:00:00 in July. (You can see it by looking for "Security changes: ..." in Logs.) 

But why is it not triggered on 20070701, 20070702 and 20070706, ...?

My guess is,

  • 20070701: It's Sunday so there is no new data and therefore OnData is NOT triggered. OK.
  • 20070702: It's Monday and there is new data from universe selection that happened yesterday. But OnData is NOT triggered on this day. Why?
  • 20070703: OnData IS triggerd on this day. But why?
  • 20070704: On this day there is no universe selection (because it is set to happen once a month on month start) but OnData IS triggered. Why?
  • 20070706 and later: On these days there is no universe selection so threr is no new data and threfore OnData is NOT tirggered. OK.

I need some clarification. Thanks.

0

Hi Bill! It takes a while to really understand the flow of time and when things are triggered but most of the time it helps to assume LEAN's correct and then think of what we might be forgetting. Common reasons are: holidays, splits-corporate events, weekends, universe data, fill forward etc etc.. You have to review your slice object to see more.   

Universe settings control the settings of data added *to* the universe, not the universe resolution itself.

 

https://www.quantconnect.com/data

 

1

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.


I am also confused at how frequent is onData() being called ... and this post does not help me by much. 

Would someone kindly post more resources on how Lean handles what's so called the 'event'? From my past experience, other engines seem to have such a function which can be called with a fixed rate (eg. daily, per minute, etc.)

0

yuying liu , The rate by which onData is called depends on the resolutions for your subscribed data. For example, if you are subscribed only to Resolution.Daily, it would be daily, giving you a daily tradebar for OHLC (and volume etc). Events are handled such that, say, if the market is not open that day, onData will not be triggered that day, etc. Thus, take your resolution arguments to be equivalent to specifying a fixed rate for the data.

0

Hi @Aaron, first of all, thanks for responding to my question! 

If I understand correctly, then the Debug message in this following code snippet should be printed out daily I suppose? (i.e. being printed out each day from 12/01/2018 to 12/10/2018?)

class BootCampTask(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2018, 12, 1)
self.SetEndDate(2018, 12, 10)
self.SetCash(100000)
spy = self.AddEquity("SPY", Resolution.Daily)

def OnData(self, data):
self.Debug("I suppose this message should be printed out daily ..?")

However, what I got from the console is the following after I hit the 'Backtest' button (i.e. the message "I suppose this message should be printed out daily ..?" is only printed out once on 191 | 18:44:23:):

185 | 18:44:15:

Backtesting Project ID: 5642653

186 | 18:44:16:

Successfully sent backtest request for 'Crying Sky Blue Dragonfly', (Compile Id: 921069ff12b5ad79d794932db1153ec5-92de8570a3c663641b5be897774b50ca)

187 | 18:44:21:

Initializing algorithm...

188 | 18:44:23:

Backtest deployed in 6.439 seconds

189 | 18:44:23:

Launching analysis for 0662e193cf0a576047635e4d9478188e with LEAN Engine v2.4.0.0.9464

190 | 18:44:23:

Algorithm (0662e193cf0a576047635e4d9478188e) Completed.

191 | 18:44:23:

I suppose this message should be printed out daily ..?

192 | 18:44:23:

Algorithm Id:(0662e193cf0a576047635e4d9478188e) completed in 0.50 seconds at 0k data points per second. Processing total of 49 data points.

193 | 18:44:24:

Your log was successfully created and can be retrieved from: https://www.quantconnect.com/backtest/93025/5642653/0662e193cf0a576047635e4d9478188e-log.txt

 

 

0

I'll have to look into the specifics, but both then algo manager  and the timeslice constructor are likely points of interest. Note that there exist many methods of optimization; I reckon the fact that the data is unused is the culprit (or, possibly, a limit on self.Debug). I'll try finding out which exactly when I get the chance.

1

Hi Yuying, 

the length of debug messages are limited. That's why you see only one message. 

I've attached a backtest with a shorter debug message showing OnData() is called every trading day between your start date and end date (5 times). 

Console Output:



Initializing algorithm...

Backtest deployed in 5.898 seconds

Launching analysis for 8abdff9ca9709140735f1b04ec11a3d1 with LEAN Engine v2.4.0.0.9471

2018-12-01 00:00:00

Algorithm (8abdff9ca9709140735f1b04ec11a3d1) Completed.

2018-12-04 00:00:00

2018-12-05 00:00:00

2018-12-07 00:00:00

2018-12-08 00:00:00

2018-12-11 00:00:00

 

2


Thank you both! 

Just for those who may have the same confusion, the reason is, as Arthur mentioned, 'self.Debug()' has some limitations: "If multiple IDENTICAL messages are sent within 1 second, we rate limit the messages to avoid crashing your browser." More info please refer to:

https://www.quantconnect.com/docs/algorithm-reference/logging-and-debug

 

With that being said, personally I think it may be a better idea to print out messages with the "self. Log()" and check the log file rather than use "self.Debug()".

 

 

0

Update Backtest





0

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.


Loading...

This discussion is closed