Back

Schedule Single Event on Backtest Start Date

I'm attempting to schedule a single event on the backtest start date. Here was my attempt, but it does not work when the backtest the start date is not a trading day:

self.Schedule.On(self.DateRules.On(self.Time.year, self.Time.month, self.Time.day),
self.TimeRules.BeforeMarketClose(self.tickers[0], 15),
self.Rebalance)

Please let me know if there is a way to set the date to be the next trading day.

Thanks!

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.


Hi,

You can try this: 

self.DateRules.EveryDay("SPY") 

#Trigger an event every day a specific symbol is trading.

If you are trading in the SPY universe you can set it so it would only trade if the market is open. 

For reference: 

https://www.quantconnect.com/docs/algorithm-reference/scheduled-events

 

0

Thanks for your response, Hao. I believe this will perform the task every day whereas I am looking for it to perform the task on a single day.

0

Hi, 

Perhaps try this?


self.Schedule.On(self.DateRules.On(2013, 10, 7), \
self.TimeRules.At(13, 0), \
self.SpecificTime)
def SpecificTime(self):
self.Log("SpecificTime: Fired at : {0}".format(self.Time))

This will trigger on the day at a specific time. 

0

Thanks for this, Hao. Unfortunately, this code will only work if it is fired on a day that the market is open. I'm hoping to have the code detect if the market is open...

0

Here is my solution:

upcoming_trading_days = self.TradingCalendar.GetDaysByType(TradingDayType.BusinessDay, self.Time, self.Time+timedelta(days=5))
for dates in upcoming_trading_days:
next_trading_day = dates.Date
break
self.Schedule.On(self.DateRules.On(next_trading_day.year, next_trading_day.month, next_trading_day.day),
self.TimeRules.BeforeMarketClose(self.tickers[0], 15),
self.Rebalance)

 

0

Hi Brad,

Do you mind specify how you want to use the schedule event? Or you can attach your backtesting here, then we can find out if there could be a better way to solve your problem.

Thanks

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.


Hello,

My goal is to input my initial trades at the end of the first trading day after the algorithm has started. The code above has solved this but I am open to any recommendations for improvement to my code.

Thanks,

Brad

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