Selecting an Equity Universe with Moving-Average Crossovers
Summary
This framework example uses a moving-average crossover universe-selection model to choose assets, then applies a constant upward price insight and equal-weight portfolio construction. Its configuration sets daily data resolution, leverage of 2.0, an initial cash balance of 100,000, and fast and slow average periods of 100 and 300. The selector is configured to return a count of 10, while the alpha model expresses a one-day upward outlook for selected assets.
The document is a compact implementation example rather than a complete trading thesis: it does not specify the universe’s underlying asset criteria, crossover evaluation details, or security-level exit rules. It provides no backtest results or evidence that the selection and equal-weighting choices outperform alternatives. Readers can learn how universe selection, alpha generation, and portfolio construction are combined in a framework, but should not infer investment performance from the sample configuration alone.
Key ideas
- A moving-average crossover model selects the assets included in the universe.
- The example uses 100-period and 300-period averages and selects a configured count of assets.
- A constant one-day upward price insight is applied to selected assets.
- Portfolio construction assigns equal weights, with daily resolution and leverage configured in the example.
- No performance results or detailed selection and exit rules are provided.
Tags
Full text
# EmaCrossUniverseSelectionFrameworkAlgorithm
# EmaCrossUniverseSelectionFrameworkAlgorithm
Framework algorithm that uses the EmaCrossUniverseSelectionModel to select the universe based on a moving average cross.
Framework algorithm that uses the EmaCrossUniverseSelectionModel to select the universe based on a moving average cross.
## 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.ConstantAlphaModel import ConstantAlphaModel
from Selection.EmaCrossUniverseSelectionModel import EmaCrossUniverseSelectionModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
### <summary>
### Framework algorithm that uses the EmaCrossUniverseSelectionModel to
### select the universe based on a moving average cross.
### </summary>
class EmaCrossUniverseSelectionFrameworkAlgorithm(QCAlgorithm):
'''Framework algorithm that uses the EmaCrossUniverseSelectionModel to select the universe based on a moving average cross.'''
def initialize(self):
self.set_start_date(2013,1,1)
self.set_end_date(2015,1,1)
self.set_cash(100000)
fast_period = 100
slow_period = 300
count = 10
self.universe_settings.leverage = 2.0
self.universe_settings.resolution = Resolution.DAILY
self.set_universe_selection(EmaCrossUniverseSelectionModel(fast_period, slow_period, count))
self.set_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1), None, None))
self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
```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.