Questions about sequence algorithm functions are called in with a given data resolution

I've been writing some test code to try and understand in what order Universe selection, security change events, ondata events, and order events are called given different data resolutions.  I am still confused as to how all of these things fit together.  To try and fix this I want to ask four questions about the test code I've attached that I think will help me get a breakthrough.   

1.  Why are my MarketOrders being filled at midnight following the morning that they should have theoretically been filled?  

2.  What is the difference between the log timestamp value and the UtcTime stamps I used to track when the functions are being called? 

3.  On the first day the coarse universe selection function is being called even though it doesn't look like any data has actually been given to the algorithm yet and the actual security change event doesnt get thrown until the midnight following.  Why is this happening?  

4.  Why is Ondata() called at midnight as well?  

Update Backtest

The coarse universe selection is called at the beginning of the algorithm. This is what selects the universe of symbols that need to be subscribed to so that there is data during the first time loop of the algorithm.

Because the resolution of the data entered into the algorithm is daily, the algorithm runs at midnight every night using the TradeBars of the past day. This the reason why OnData() runs at midnight and why the MarketOrders are submitted at midnight. The MarketOrders are converted to MarketOnOpen orders for the following morning because the order was submitted while the market was closed.

The reason why there is a difference between the log timestamp values and Utc timestamps is because self.Time is set the Timezones.NewYork. The log is showing the same time but at different time zones.


Update Backtest


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.


This discussion is closed