LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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:
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.
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.
Hao Bin Zhang
1.4k Pro
,
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.Â
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
Brad Hallett
2.8k Pro
,
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)
Â
1
Yiyun Wu
2.3k Pro
,
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
Brad Hallett
2.8k Pro
,
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.
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...
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!