Back

How can I backtest trades from market open to close?

Hi,

I'm trying to compare and contrast some different entry signals, and in a research ntoebook I've been using daily bars' close minus open as a proxy for rough profit. Now that I have some ideas, I've wanted to code them up in the algorithm side and see if the results replicate--here's where I run into a problem. 

I'm having a lot of trouble simulating  placing a MarketOnOpen and MarketOnClose order for the same day. If I run my algo at the daily resolution, I see the former orders but never the latter (see attached, though I'm not sure the individual trade log shows up). 

If I run at a minute resolution, I can use a consolidator to try to aggregate daily bars but they're not the same daily bars, the events that fire from the consolidator appear to happen at 9:31 am every day--too late to place a MarketOnOpen order. 

Ideas?

Update Backtest








You can't access the official market close price and trade on it in the same day (as the official is 4pm); best available would be accessing 3.58pm bars when using minute data. i.e. intraday move = 3.58pm - day open.

Exchange market close prices are special; they're marked ticks from the exchange and its impossible to send market orders to them so you can't get the same prices with a consolidator.

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.


Sorry, my intent was unclear--I'm trying to decide if I should hold a long position from open to close based on yesterday's daily bar. If I were going to hand-execute this algorithm, I would look at the official market close any time in the evening after 4pm, decide whether I will be long the entire next day, and then submit a market on open order sometime before the open (and then a market on close order sometime before the close). 

It's a bit of an artificial scenario as it intentionally ignores any intraday price movement, but helps to act as a neutral comparison basis for different entry signals and runs efficiently over long periods in python since it doesn't have to pull down data finer than daily granularity.

This seems like it is fairly easy to do by hand, but I am having trouble automating it. If I use daily data, I get numbers that match the research notebook but seemingly doesn't get events that allow me to hold a single day position (which is what my code attempts). I know the market open and close orders would be extremely unlikely to execute exactly at what would be retrospectively called the official open and close for the day, but the market on close orders aren't executing at all.

 If I use minute data, I have a hard time consolidating a daily bar that fires its daily event aligned with the after-hours window that I would run my calculations in by hand.

0

          Would this do what you want?
 

https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_520a5318c478ae93b8511ced3a5f1b68.html
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