fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Equal Risk Contribution

Install and import#

bash
npm install fintech-algorithms
ts
import { equalRiskContributionWeights } from "fintech-algorithms/portfolio-construction/risk-allocation/equal-risk-contribution";

Signature#

equalRiskContributionWeights(assetIds, covariance)

Solves for the weights that give every asset the same contribution to portfolio volatility, which equal capital weights do not.

Parameters#

NameTypeNotes
assetIdsreadonly unknown[]
covariancereadonly unknown[]

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

assetIds
["A", "B", "C"]
covariance
[
  [0.01, 0.016, 0.0015],
  [0.016, 0.04, -0.006],
  [0.0015, -0.006, 0.0225]
]

Call#

equalRiskContributionWeights(assetIds, covariance)

Returns#

object with 13 fields: assetIds, weights, componentRiskContributions, componentRiskShares, portfolioVariance, portfolioVolatility, sumWeights, riskShareResidual, …

{
  "assetIds": ["A", "B", "C"],
  "weights": [0.3778302517370716, 0.23412526094592215, 0.3880444873170063],
  "componentRiskContributions": [0.031952220115817255, 0.03195222012249683, 0.031952220117888716],
  "componentRiskShares": [0.3333333333029024, 0.33333333337258536, 0.3333333333245123],
  "portfolioVariance": 0.00918849933464442,
  "portfolioVolatility": 0.0958566603562028,
  "sumWeights": 1,
  "riskShareResidual": 3.925204605792487e-11,
  "iterations": 20,
  "method": "equal-risk-contribution",
  "solver": "cyclical-coordinate-descent-volatility-eq7",
  "covarianceScale": 0.04,
  "status": "ok"
}

Diagrams#

Equal Risk Contribution — erc risk comparison

Calculation flow#

Diagram
flowchart TD
    A[Ordered asset IDs and covariance] --> B{Shape, finite, exact symmetry?}
    B -- no --> X[invalid-input or invalid-covariance]
    B -- yes --> C{Positive diagonal and strict PD?}
    C -- no --> X
    C -- yes --> D[Normalize by actual max absolute covariance]
    D --> E[Set y = ones and budget b = 1/N]
    E --> F[Cycle asset coordinates with volatility Eq. 7 positive root]
    F --> G[Compute covariance component shares]
    G --> H{Max share residual <= 1e-10?}
    H -- no, under 10000 sweeps --> F
    H -- no, at limit --> Y[convergence-failure]
    H -- yes --> I[Normalize y to fully invested weights]
    I --> J[Recompute variance, volatility, contributions, and shares from w]
    J --> K[Return ERC result and diagnostics]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • Maillard, Roncalli, and Teïletche, “On the Properties of Equally-Weighted Risk Contributions Portfolios”
  • Griveau-Billion, Richard, and Roncalli, “A Fast Algorithm for Computing High-dimensional Risk Parity Portfolios”
  • Maillard, Roncalli, and Teïletche, SSRN record / DOI
  • Palomar, Portfolio Optimization: Theory and Application, risk-based portfolios
  • Prior input-integrity methods
  • Claim and licensing boundary

The rest of the Risk Allocation family#