Hi, I am new to Quantconnect and am having really hard time understanding how daily resolution timing logic works. Please correct if my below understanding is wrong regarding daily resolution:
- I will have price bar of 1st bar on start of day 2nd(00:00) when algorithm runs on 2nd midnight.
- If I place order based on it, when will it be placed? My assumption was it will be placed as OnMarketOpen order on 2nd 00:00(12 AM) and will be filled on the same day.
But it seems the behavior is diff when I am checking the orders tab. Please find attached backtest for the reference. For example, for CRNT order tab is showing like this:
So here if on 30-01-2019 my algorithm actually runs on 29-01-2019 bar data(is it correct?), then why MarketOnOpen order is not place on same day 30-01-2019 and instead is filled on 2019-01-31? However when I check fill price on chart it does seem it gets filled on 2019-01-30 only:
It is extremely frustrating and time consuming to understand how timing logic in Quantconnect actually works, the documentation also is not much of a help, let alone boot camp. I have already spent too many days trying to wrap my head around it, It is extremely disappointing to write here that I have spent more time in understanding the algorithm framework/timing than I have actually implementing my idea.
Log Up
Below is a relate discussion highlighting another timing problem which I also faced during History requests where bar data is not in sync with the date, For example, due to algorithm structure(maybe) data for bar 1 Jan shows date of 2 Jan in history requests, which unnecessarily creates confusion and introducing code bugs which takes hours to resolve.
Fred Painchaud
Hi Log Up,
Sorry to read you have a hard time understanding. Hope this helps:
1- Daily bars arrive at 00:00 the next day. So daily bar for 2019-10-04 arrives at 00:00 on 2019-10-05 (that's the very first instant of 2019-10-05). You understood that.
2- If you trade based on that daily bar, you do so on 2019-10-05 or later. Let"s say you do so on 2019-10-05. You also understood that part I believe.
3- In backtesting, you always trade in-between bars. Since you trade daily bars, if you place an order on 2019-10-05, your order can only be executed right after the current bar, and thus, on 2019-10-06 00:00.
4- In your example, you put a MOO on 2019-01-30, based on data from 2019-01-29. It gets executed on 2019-01-31 00:00 (right after the 2019-01-30 bar), at the open price (Market-On-Open…) for 2019-01-30.
This is pretty common to all backtesting engines I've seen, on daily resolution.
If you want your orders to be executed in the same day, you need to use intra-day resolutions, like hour, minute, second…
Hope this helps you understand,
Fred
Log Up
Hi Fred Painchaud Thanks for the reply, for point 4 I have follow up question:
If I place MOO order on MOO on 2019-01-30 00:00, shouldn't it be executed on same day 2019-01-30? and if it is being executed on 2019-01-31, then why do I see filled price of 2019-01-30 open in orders tab?
Fred Painchaud
Hi Log Up,
In other words…
This is specific to MOO and daily bars. The logic is that if you place a MOO on 2019-01-30, the backtest/simulation needs the open price on 2019-01-30. This makes sense right? But when do you get the open price for 2019-01-30 at daily resolution? When the bar for 2019-01-30 gets generated. And when does it get generated? On 2019-01-31 00:00 (thus right after 2019-01-30).
If you were, say, at minute resolution, you would get the open price for 2019-01-30 at 09:31, if talking about equity assets for which the market opens at 9h30, regular hours.
Fred
Log Up
Hi Fred Painchaud that makes sense. Please tell me if I am interpreting it right? you mean to say my algorithm will get 2019-01-30 open price on 2019-01-31 00:00 so it will go into past(to simulate MOO order) and fill the orders at 2019-01-30 open price? If it is so, why not show orders filled on 2019-01-30 only in orders tab instead of 2019-01-31?
Fred Painchaud
Fred
Log Up
Hi Fred Painchaud what do you mean here by filled? My assumption is filled means when transaction/my buy/sell is executed, I agree that algorithm has no way to find out it is executed on 2019-01-30 open price till it;s daily bar ends and 2019-01-31 bar starts at 00:00, but does it make sense to show it is filled on 2019-01-31 00:00? as it causes confusion as to why we can see prices it being filled at is 2019-01-30 open, still order fill is shown as 2019-01-31. Why I am emphasizing on this is although now I understand it fairly well after you explained, new developers will need to go lot of debugging, checking charts etc. before they realize that its just the way algorithm works and not the actual fill date. On top of that, if your time zone is different than the securities you including in your algo, it adds more to the confusion. Thanks.
Fred Painchaud
By filled, I mean this:
and this:
You are right however that algo-trading is not trivial to understand so when you are a new-comer, it is confusing. And yes, if on top of it you are new to software development, it's even more difficult. I'm a old-time developer so the development part is not a problem anymore (except of course with new frameworks/technologies, etc - I need to learn them but with some background helping) but yes, when I was new to algo-trading, all that trading part was first confusing to me too. When I really understood EXACTLY what is a backtest, I understood A LOT all in a sudden… It looks like a stupid question to understand “what is a backtest” but the answer is really multi-pages and is totally necessary…
Anyway, don't give up!
Fred
Log Up
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!