Skip to content
All library documents

Combining RSI and EMA Crossover Alpha Models in a Framework

Article Strategy library · Author: QuantConnect

Summary

This example shows how a framework-based trading algorithm can combine two alpha models: one based on RSI and another on EMA crossovers. It manually registers several US equities, then uses a manual universe selection model to include those securities. The composite alpha model is passed to the algorithm as a single component, while equal weighting handles portfolio construction, immediate execution places orders, and a null risk model supplies no additional risk controls.

The source sets a short sample date range and starting cash, but provides no performance report or evidence that the combined signals are profitable. It is primarily an architectural example of assembling framework components, rather than a complete trading method. It does not explain how the RSI and EMA models generate or reconcile their individual insights, nor does it address transaction costs, position limits, or risk management beyond naming the selected default models.

Key ideas

  • A composite alpha model can combine RSI and EMA crossover signal generators.
  • A manually selected universe can be built from securities registered directly in the algorithm.
  • Portfolio construction, execution, and risk management are separate framework components.
  • The example demonstrates component assembly but gives no evidence about trading performance.

Tags

Full text
# CompositeAlphaModelFrameworkAlgorithm


# CompositeAlphaModelFrameworkAlgorithm









Show cases how to use the CompositeAlphaModel to define.

Show cases how to use the CompositeAlphaModel to define.

## Source (Apache-2.0)

```python
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from AlgorithmImports import *

from Alphas.RsiAlphaModel import RsiAlphaModel
from Alphas.EmaCrossAlphaModel import EmaCrossAlphaModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel

### <summary>
### Show cases how to use the CompositeAlphaModel to define.
### </summary>
class CompositeAlphaModelFrameworkAlgorithm(QCAlgorithm):
    '''Show cases how to use the CompositeAlphaModel to define.'''

    def initialize(self):
        self.set_start_date(2013,10,7)   #Set Start Date
        self.set_end_date(2013,10,11)    #Set End Date
        self.set_cash(100000)           #Set Strategy Cash

        # even though we're using a framework algorithm, we can still add our securities
        # using the AddEquity/Forex/Crypto/ect methods and then pass them into a manual
        # universe selection model using securities.keys()
        self.add_equity("SPY")
        self.add_equity("IBM")
        self.add_equity("BAC")
        self.add_equity("AIG")

        # define a manual universe of all the securities we manually registered
        self.set_universe_selection(ManualUniverseSelectionModel())

        # define alpha model as a composite of the rsi and ema cross models
        self.set_alpha(CompositeAlphaModel(RsiAlphaModel(), EmaCrossAlphaModel()))

        # default models for the rest
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
        self.set_execution(ImmediateExecutionModel())
        self.set_risk_management(NullRiskManagementModel())

```

Shown in full with attribution under the source's licence. Licence: Apache-2.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.