Hello everyone:
I am trying to find a “event flow diagram” that could describe the flow of framework events: such as OnData, AfterMarketOpen, BeforeMarketClose, OrderSubmitted, OrderExecuted, InsightEmitted, PortfolioConstructed……
Such a diagram will greatly help me understand the execution of the framework. Could anyone tell me if there is such diagram in documentations? Thanks!
Varad Kabade
Hi Code quant,
We have been working on new documentation. Adding a event flow is a great suggestion. Thank you.
The OnData method is the primary data handler; all subscribed data are received in a Slice object. Refer to the docs on Handling data for more information.
Each order generates events over its life as the status changes. These events are passed to the OnOrderEvent() method, which you can use for information about your order states. The event handler is passed an OrderEvent object, which has information about the order status. Refer to the following docs for more information.
Scheduled events need a DateRules and TimeRules pair to set a specific time. When the event is triggered, the action block is executed. AfterMarketOpen and BeforeMarketClose are the TimeRules class method, which specifies at what time the event should be executed.
Moving forward, we recommend completing the Bootcamp lessons to understand the QC API in depth.
Best,
Varad Kabade
Code quant
Hi Varad,
Thank you for you quick reply and It's good news that you are working on new documentations.
The examples you mentioned in your comment are the event flow inside one singe concept area, but the main difficulty is event flow between DIFFERENT concept areas. The event flow inside the single one concept area is clearly documented and is understandable. For example, event flow inside “Order” concept area is clearly documented, and event flow inside “Scheduled event” concept area is also clearly documented, but when things are mixed, it's hard to understand.
For example: I use scheduled event method to setup a callback which will be called at 5mins before the market is closed, will this event be invoked before OnData event? or it will be invoked after OnData event?
This is another example: I setup the framework by calling SetUniverseSelection + SetAlpha + SetPortfolioConstruction + SetExecution + SetRiskManagement in the Initialize() method and I understand the whole flow that the universe selection + alpha create + portfolio constructon, and so on. But when will this flow occur? Is it occured inside OnData event? or after OnData event? how about if I called EmitInsights?
In summary, I need a “whole picture” of the overall event architecture, and some details of event flow between different concept areas. Thanks!
Varad Kabade
Hi Code quant,
The OnData method is the last method that gets executed if multiple events are happening at the same time. The events are ranked as follows:
1.Check if there are realtime events in the past which didn't fire because at the scheduled times there was no data
2. Set the algorithm and real time handler's time
3. Update the current slice
4. Cancel all open orders for Symbol Changed event
5. Add and remove securities(try)
6. Update the securities properties with universe data
7. Poke each cash object to update from the recent security data
8. Process fill models on the updated data before entering algorithm
9. Process end of day delistings
10. Process split warnings for options
11. Perform margin calls
12. Perform check for settlement of unsettled funds
13. Let the algorithm know about universe changes
14.Apply dividends
15. Apply splits
16. Update registered consolidators for this symbol index
17. Fire custom event handlers
18. After we've fired all other events in this second, fire the pricing events(TradeBars,ticks etc)
Refer to the following source code.The Update method of the AlphaModel class works similarly to the OnData method. Still, instead of sending orders, it emits insights(signals) that the PortfolioConstructionModel consumes to determine the portfolio target(i.e, position size), which are sent to the ExecutionModel, which creates the orders. All of the above processes is handled by the event handlers of the respective framework component. If you use emit Insight, it will trigger the PCM to create targets. For better understanding of the event flow in the framework, we recommend going through the BootCamp lesson: The Algorithm Framework.
Best,
Varad Kabade
Code quant
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!