Hi,
TLDR: how do i generate a signal on close based on daily data and have the algorithm execute immediately on the same day?
I'm building a strategy that calculates a signal on all equities in my universe and then executes a single trade. My idea was to have that signal be calculated on close and then immediately buy or sell based on the signal given.
My problem is that the order execution is completely delayed. the order signal is generated at close (as i am using close prices) but the execution only happens 2 days later on market open when i'm using self.SetHoldings. This completely skews the performance.
I understand that on a daily timeframe the close prices are only available at close and orders have to be placed after that. I'd be happy if execution happens the next day on open, but it would be even better if it would be possible to get a price only once a day at 10 minutes before markets close and use that price as my closing price to execute the same day.
I haven't found a solution that isn't based on consolidating hour or minute data. The problem is that the strategy calculates a value for over 3000 assets and i am already running low on RAM on my backtesting machine so switching to lower timeframes and consolidating is not really an option.
Any help is appreciated.
Jodok Boehm
Ok, i found a work around that gives prices close to the market price on close. i schedule a limit order one minute after close that gets filled in extended hours. maybe this helps someone else:
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(16,1), self.execute)
quantity = self.CalculateOrderQuantity(symbol, 1)
open_orders = self.Transactions.GetOpenOrders(symobl)
if (self.Portfolio[symbol].Quantity < 1):
if len(open_orders) == 0:
self.LimitOrder(symbol, quantity, (self.Securities[symbol].Close))
Jodok Boehm
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.
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!