Combining Fundamental Stock Selection with Equal Weighting and Sector Risk Limits
Summary
This example shows how an algorithmic trading framework can connect a fundamental universe-selection process to portfolio construction and risk management. It sets daily data resolution, then supplies custom coarse and fine selection functions. The coarse function returns a small, hard-coded set of US equity symbols that changes on a specified date; the fine function passes through the securities it receives. A constant one-day upward price insight provides the alpha signal, and an equal-weight model allocates across selected holdings.
A maximum-sector-exposure risk model is added to constrain concentration by sector. The sample also logs filled orders and the corresponding absolute holding value. It illustrates how selection, a simple signal, allocation, sector risk control, and immediate execution fit together, but it does not explain the risk model’s threshold or provide backtest results. The universe is manually specified rather than selected using substantive fundamental criteria, and the short example period and constant directional signal do not establish investment merit or robustness.
Key ideas
- The framework separates universe selection, signal generation, portfolio construction, risk management, and execution.
- Coarse selection uses a date-dependent hard-coded list of US equities, while fine selection passes through the supplied securities.
- A constant one-day upward insight is paired with equal-weight portfolio construction.
- A maximum-sector-exposure model provides a portfolio-level concentration control.
- The example gives no sector limit details or performance evidence, and its selection and signal rules are illustrative.
Tags
Full text
# SectorExposureRiskFrameworkAlgorithm
# SectorExposureRiskFrameworkAlgorithm
This example algorithm defines its own custom coarse/fine fundamental selection model
### with equally weighted portfolio and a maximum sector exposure.
This example algorithm defines its own custom coarse/fine fundamental selection model with equally weighted portfolio and a maximum sector exposure. with equally weighted portfolio and a maximum sector exposure.'''
## 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 Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
from Alphas.ConstantAlphaModel import ConstantAlphaModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Risk.MaximumSectorExposureRiskManagementModel import MaximumSectorExposureRiskManagementModel
### <summary>
### This example algorithm defines its own custom coarse/fine fundamental selection model
### with equally weighted portfolio and a maximum sector exposure.
### </summary>
class SectorExposureRiskFrameworkAlgorithm(QCAlgorithm):
'''This example algorithm defines its own custom coarse/fine fundamental selection model
### with equally weighted portfolio and a maximum sector exposure.'''
def initialize(self):
# Set requested data resolution
self.universe_settings.resolution = Resolution.DAILY
self.set_start_date(2014, 3, 25)
self.set_end_date(2014, 4, 7)
self.set_cash(100000)
# set algorithm framework models
self.set_universe_selection(FineFundamentalUniverseSelectionModel(self.select_coarse, self.select_fine))
self.set_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1)))
self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
self.set_risk_management(MaximumSectorExposureRiskManagementModel())
def on_order_event(self, order_event):
if order_event.status == OrderStatus.FILLED:
self.debug(f"Order event: {order_event}. Holding value: {self.securities[order_event.symbol].holdings.absolute_holdings_value}")
def select_coarse(self, coarse):
tickers = ["AAPL", "AIG", "IBM"] if self.time.date() < date(2014, 4, 1) else [ "GOOG", "BAC", "SPY" ]
return [Symbol.create(x, SecurityType.EQUITY, Market.USA) for x in tickers]
def select_fine(self, fine):
return [f.symbol for f in fine]
```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.