Back

The intrinsic lag created by the consolidator?

Dear All,

Copying from the SMA examples using consolidators, I played it on SPY. I noticed that there was an intrinsic one bar lag for the indicators. Looking at the output from the log  below

Log(consolidated.Close+"//" +fast+"//"+slow);

                               SPY        SMA(2)     SMA(4)

6/1/201612:00:01   208.693   208.6532  208.397

6/1/201612:30:01   208.872   208.7029  208.5686

6/1/201613:00:01   209.0411  208.7825  208.7178

6/1/201613:30:01   208.8919  208.9566  208.8298

Obviously 0.5*(208.693+208.872)=208.7825 which showed up in the third row instead of the second row. Thus we have an intrinsic lag created by using the consolidator.

I have encountered this problem long time ago and my previous solution was to rewrite the indicators all by myself to avoid the "instrinsic lag". My rewriting was working but I still want to see whether I used the consolidator and the built-in indicators in a wrong way. 

Thanks.

Update Backtest








Thanks for reporting, we'll look into it @Jiaqi. In the future please post possible issues to a more appropriate place like the Github issues list or support@quantconnect.com

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.


After going through the codes/disccussions I think the intrinsic lag is coming from thet fact that the indicator value would be available for our use until the next consolidator/data bar. My prevvious cumbersome work-around was to use a rolling window to keep track of the price history and calculate the indicator value in the consolidator function so I can get the instant indicator value. Another much simpler work-around I discovered is to put all the trading logics inside ondata function instead of the consolidator function as most people are suggesting in the forum. In my following example I use a minute data resolution for the ondata function while the consolidator is still 30 mins. Once I get a new 1 min data the indicators are updated and ready to use in the ondata function. The "delay" you are getting is only the data resolution but not the consolidator time frame now as is eveident from the log file. Hopefully this simple example would help.

0


Thank you for posting back your findings!

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 @Jiaqi,
the reason for the lag in the first algorithm you attached is because RegisterIndicator attaches an internal event handler to the consolidator for the DataConsolidated event (which updates the indicator value).
Your custom event handler with this line:

minConsolidator.DataConsolidated += OnFiveMinutes;

before calling RegisterIndicator, so the OnFiveMinutes method is called before the indicators have been updated.

The solution is very simple: move this line after the RegisterIndicator calls and it will work as expected (with no lags).

Hope this helps
Stefano

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.


Thanks a lot:-) That is making my life much easier.

0

@Jiaqi, the above proposal actually wouldn't fix it -- but Alex is working on a proposed fix for this here.

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 @Jiaqi, Stefano's proposal was our first reaction to that bug. After I try it, I found that it wouldn't fix the bug. Despite the theory, events were not being executed by the order they were registered.

While I was looking into it, Stefano proposed another fix that I promptly implemented. Now, the events that are internally subscribed to the consolidator by RegisterIndicator are called before events that are attached to it at algorithm.

If you are running Lean locally, please update it to the latest version. 

Best regards,
Alex

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.


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