QuantConnect/Lean · error · ArgumentException
Long position must be allowed in RiskParityPortfolioConstruc
Error message
Long position must be allowed in RiskParityPortfolioConstructionModel.
What it means
RiskParityPortfolioConstructionModel (Python) rejects PortfolioBias.SHORT. Risk parity balances risk contributions, which requires long exposure; a short-only configuration is incompatible with the model's risk-budgeting math, so the constructor raises ArgumentException.
Source
Thrown at Algorithm.Framework/Portfolio/RiskParityPortfolioConstructionModel.py:44
lookback = 1,
period = 252,
resolution = Resolution.DAILY,
optimizer = None):
"""Initialize the model
Args:
rebalance: Rebalancing parameter. If it is a timedelta, date rules or Resolution, it will be converted into a function.
If None will be ignored.
The function returns the next expected rebalance time for a given algorithm UTC DateTime.
The function returns null if unknown, in which case the function will be called again in the
next loop. Returning current time will trigger rebalance.
portfolio_bias: Specifies the bias of the portfolio (Short, Long/Short, Long)
lookback(int): Historical return lookback period
period(int): The time interval of history price to calculate the weight
resolution: The resolution of the history price
optimizer(class): Method used to compute the portfolio weights"""
super().__init__()
if portfolio_bias == PortfolioBias.SHORT:
raise ArgumentException("Long position must be allowed in RiskParityPortfolioConstructionModel.")
self.lookback = lookback
self.period = period
self.resolution = resolution
self.sign = lambda x: -1 if x < 0 else (1 if x > 0 else 0)
self.optimizer = RiskParityPortfolioOptimizer() if optimizer is None else optimizer
self._symbol_data_by_symbol = {}
# If the argument is an instance of Resolution or Timedelta
# Redefine rebalancing_func
rebalancing_func = rebalance
if isinstance(rebalance, int):
rebalance = Extensions.to_time_span(rebalance)
if isinstance(rebalance, timedelta):
rebalancing_func = lambda dt: dt + rebalance
if rebalancing_func:View on GitHub (pinned to d2c3659f87)
Solutions
- Use PortfolioBias.LONG or PortfolioBias.LONGSHORT with this model.
- For a short-tilted risk strategy, build a custom model rather than forcing the built-in risk-parity model into short-only.
Example fix
# before
self.set_portfolio_construction(RiskParityPortfolioConstructionModel(
portfolio_bias=PortfolioBias.SHORT)) # raises
# after
self.set_portfolio_construction(RiskParityPortfolioConstructionModel(
portfolio_bias=PortfolioBias.LONGSHORT)) Defensive patterns
Strategy: validation
Validate before calling
from AlgorithmImports import *
valid = {PortfolioBias.LONG, PortfolioBias.LONGSHORT}
if portfolio_bias not in valid:
raise ValueError('RiskParityPortfolioConstructionModel requires Long or LongShort bias')
model = RiskParityPortfolioConstructionModel(portfolio_bias=portfolio_bias) Type guard
def supports_risk_parity(bias: PortfolioBias) -> bool:
return bias in (PortfolioBias.LONG, PortfolioBias.LONGSHORT) Prevention
- PortfolioBias.SHORT forbids longs — risk parity needs long exposure.
- Mind the attribute casing: this model checks portfolio_bias, not portfolioBias.
When it happens
Trigger: Constructing RiskParityPortfolioConstructionModel(..., portfolio_bias=PortfolioBias.SHORT). Note this model checks the SHORT (uppercase) attribute name, unlike the camelCase variant in some sibling models.
Common situations: Assuming PortfolioBias.SHORT permits shorts (it forbids longs), or porting a short-biased config from another model.
Related errors
- Long position must be allowed in MeanReversionPortfolioConst
- Expected open order for emitted insight
- Unexpected open order for emitted insight: {order}
- Total must be > 0 for Euclidean Projection onto the Simplex.
- MaximumSectorExposureRiskManagementModel: the maximum sector
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/dfcc28f603e71d68.
Report an issue: GitHub.