Back

Scheduling a function on market hours only

Hello everyone, 

when backtesting, the functions of my algorithm run the whole day instead of on market hours only. Especially with the function that runs every ten seconds this is a annoying as there are a lot of invalid orders submitted this way which might slow down backtesting a lot. Is there a way to schedule a function on market hours only? Or does someone have another idea what I could do to solve this?

Thank you in advance.

Kind regards,

Christian Lauer

Update Backtest








While I'm not aware of how to eliminate the calls outside market hours (which would be nice for backtest performance), you can check if security is trading through Security.Exchange.ExchangeOpen (boolean).

Don't click link, for some reason forum interprets the above as a link...

1

+1 for Petter's solution. That's the simplest answer. i.e. 

self.exchange = self.Securities["AAPL"].Exchange;
if exchange.ExchangeOpen
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.


Thank you for the quick answers. That is a good solution indeed. I think the backtests are significantly quicker now.

Kind regards,

Christian Lauer

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