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?
QUANTCONNECT COMMUNITY
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?
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.
Douglas Stridsberg
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?
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,
I need some clarification. Thanks.
Jared Broad
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
Â
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.
Yuying liu
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.)
Aaron Janeiro Stone
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.
Yuying liu
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
Â
Â
Aaron Janeiro Stone
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.
Arthur Asenheimer
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
Â
Yuying liu
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()".
Â
Â
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!