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

Risk Budgeting

Install and import#

bash
npm install fintech-algorithms
ts
import { riskBudgetingWeights } from "fintech-algorithms/portfolio-construction/risk-allocation/risk-budgeting";

Signature#

riskBudgetingWeights(assetIds, covariance, riskBudgets)

Solves for weights whose risk contributions match a declared budget per asset, generalizing equal risk contribution to unequal targets.

Parameters#

NameTypeNotes
assetIdsreadonly unknown[]
covariancereadonly unknown[]
riskBudgetsreadonly 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]
]
riskBudgets
[0.5, 0.3, 0.2]

Call#

riskBudgetingWeights(assetIds, covariance, riskBudgets)

Returns#

object with 15 fields: assetIds, riskBudgets, weights, componentRiskContributions, componentRiskShares, portfolioVariance, portfolioVolatility, sumWeights, …

{
  "assetIds": ["A", "B", "C"],
  "riskBudgets": [0.5, 0.3, 0.2],
  "weights": [0.518650848634501, 0.19040488031965186, 0.29094427104584725],
  "componentRiskContributions": [0.04741515164850507, 0.028449090994357995, 0.018966060654301783],
  "componentRiskShares": [0.4999999999991843, 0.3000000000549249, 0.19999999994589085],
  "portfolioVariance": 0.008992786423432273,
  "portfolioVolatility": 0.09483030329716484,
  "sumWeights": 1,
  "riskShareResidual": 5.492484245195328e-11,
  "riskShareRelativeResidual": 2.7054608553456205e-10,
  "iterations": 17,
  "method": "risk-budgeting",
  "solver": "cyclical-coordinate-descent-volatility-eq7",
  "covarianceScale": 0.04
}

Showing 14 of 15 fields.

Diagrams#

Risk Budgeting — risk budgeting comparison

Calculation flow#

Risk budgeting flow
flowchart LR
  A[Validate IDs, covariance, budgets] --> B[Scale Sigma by actual max abs entry]
  B --> C[Initialize positive y]
  C --> D[CCD positive root using b_i]
  D --> E{Absolute and relative share residuals pass?}
  E -- no --> D
  E -- 10,000 sweeps --> F[convergence-failure]
  E -- yes --> G[Normalize y to w]
  G --> H[Recompute q, volatility, RC, shares]
  H --> I[Render weights and risk-budget diagnostics]
  J[Stale/split/FX evidence] -. separate upstream route .-> A

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#

  • Claim classification

The rest of the Risk Allocation family#