Algorithm Framework



Since QuantConnect was formed in 2013 we've seen more than 1-million algorithms created by the community. Although they all seek to achieve different results they can all be abstracted into the same core features. The Algorithm Framework is an attempt by QuantConnect to provide this well defined structure to the community; encouraging good design and making your work more reusable.

These core "modules" Universe Selection, Alpha Creation, Portfolio Construction, Execution and Risk Management form the basis of all investment strategies.

  • 1. Universe Selection - Select your assets.
  • 2. Alpha Creation - Generate trading signals.
  • 3. Portfolio Construction - Determine position size targets.
  • 4. Execution - Place trades to reach your position sizes.
  • 5. Risk Management - Manage the market risks.

In the following sections we'll go into each of these sections in more detail.

System Architecture

The Algorithm Framework is built on top of the QCAlgorithm class; giving your strategy access to all the normal methods you use for algorithm development. You should be able to copy and paste your algorithms across without any changes. Algorithms which implement the framework extend the QCAlgorithmFramework class.

Algorithm Framework Class Heirachy

The framework data output of each module flows into the next predictably.Assets selected by the Universe Selection Model are fed into your Alpha Model to generate trade signals. The trade signals (Insights) are converted into Portfolio Targets by the Portfolio Construction Model. The Portfolio Targets hold a target share quantity we'd like the algorithm to hold. To execute these targets efficiently the Execution module fills the targets efficiently over time. Finally; the Risk Management Model ensures our targets are still within safe risk parameters and adjusts the portfolio targets if required.

QuantConnect Algorithm Framework Architecture.
public class MyFrameworkAlgorithm : QCAlgorithmFramework {
      public void Initialize() {
           // Setup Requested Modules
class MyFrameworkAlgorithm(QCAlgorithmFramework):
     def Initialize(self):
           # Setup Requested Modules 

For simply strategies this may seem like overkill; however even simple strategies can benefit from reusing the ecosystem of modules available in QuantConnect. Imagine pairing your EMA-cross with a better execution system? Or simply plugging in an open sourced trailing stop risk management model?

Important Terminology

Term Definition
Universe Selection Model Framework component for selecting assets for your algorithm.
Alpha Creation Model Framework component for that generates trade signals; on the assets in your universe for your algorithm.
Insight A trade signal generated by your algorithm Alpha Model. An Insight indicates the Direction, Magnitude, Confidence and Period of your signal.
Portfolio Construction Model Framework component that constructs a target portfolio from Insight signals created by the Alpha Model.
Portfolio Target A target quantity of holdings (e.g. shares, contracts) the algorithm desires to reach. This target is created by the Portfolio Construction Model.
Execution Framework component responsible for fulfilling the Portfolio Targets set by the Portfolio Construction Model. Execute trades to reach the desired portfolio make up.
Risk Model Framework component that manages ongoing market and portfolio risk; ensuring the algorithm remains in target parameters.

Framework Advantages

The Algorithm Framework is now the recommended way to design strategies in QuantConnect. Following this well defined structure gives many advantages over conventional design:

Pluggable Algorithm Modules

By using the algorithm framework your code will be able to instantly utilize all modules built within the framework. The modules clip together in well defined ways which enable them to be shared and swapped interchangeably.

Focus On Your Strengths

By writing code in modules you can focus on your strengths. If you are great at building universes; you can build universe modules. If you’ve got risk-management experience, you could write reusable risk monitoring technology.

Reduce Development By Using Community Modules

Easily share modules you've made between algorithms; or pull in ones produced by the community. The strict separation of duties makes the Algorithm Framework perfect for reusing code between strategies.

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?