Skip to content
All library documents

Using Risk Parity Portfolio Construction in a QuantConnect Algorithm

Article Strategy library · Author: QuantConnect

Summary

This short example shows how to connect a risk parity portfolio construction model to an algorithmic trading workflow. The algorithm initializes a historical run, sets starting cash, adds two daily equity securities, and supplies a constant upward price insight with a one-day horizon. It then assigns portfolio construction to a risk parity model, which determines allocations from the supplied securities and insights.

The example illustrates framework wiring rather than explaining the risk parity calculation itself. It provides no allocation output, risk estimates, benchmark comparison, or backtest results, and the brief date range and two-stock universe do not establish the approach's effectiveness. Readers can learn where the model fits in a modular algorithm, but would need the model's implementation and additional tests to assess its assumptions, diversification behavior, and practical portfolio risks.

Key ideas

  • The example assigns portfolio construction to a risk parity model within an algorithm framework.
  • It supplies two daily equities and constant upward price insights with a one-day horizon.
  • The code demonstrates integration and initialization rather than the underlying risk parity mathematics.
  • No portfolio weights or performance evidence are reported.

Tags

Full text
# RiskParityPortfolioAlgorithm


# RiskParityPortfolioAlgorithm









Example algorithm of using RiskParityPortfolioConstructionModel

## 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.RiskParityPortfolioConstructionModel import *

class RiskParityPortfolioAlgorithm(QCAlgorithm):
    '''Example algorithm of using RiskParityPortfolioConstructionModel'''

    def initialize(self):
        self.set_start_date(2021, 2, 21)  # Set Start Date
        self.set_end_date(2021, 3, 30)
        self.set_cash(100000)  # Set Strategy Cash
        self.set_security_initializer(lambda security: security.set_market_price(self.get_last_known_price(security)))

        self.add_equity("SPY", Resolution.DAILY)
        self.add_equity("AAPL", Resolution.DAILY)

        self.add_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1)))
        self.set_portfolio_construction(RiskParityPortfolioConstructionModel())

```

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.