Back

How to set an insight's duration to end right before close of trading day?

I tried using the DateTime constructor and passing algorithm.Time date values plus the hour and minute values for right before close but that didn't work, got messages saying the date was in the past.

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.


Hey Fabien,

We can create insights with specific expiration DateTimes. We can set our insights to expire at 2 minutes before market close, so that our algorithm can submit liquidate targets at 3:59 PM.

var now = algorithm.Time;
// close insight 2 minutes before market close
var nextClose = algorithm.Securities[symbol].Exchange.Hours.GetNextMarketClose(algorithm.Time, false).AddMinutes(-2);
var insight = Insight.Price(symbol, close, InsightDirection.Up);

I've attached a simple example of this in action. In the example, I also restricted the algorithm to create insights for a symbol only if that symbol hasn't yet been invested in and to not create insights if the current time is after 3:58 PM.

Best
Rahul

2

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