# Risk Budgeting

`D14-F02-A03` · Portfolio Construction → Risk Allocation · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/portfolio-construction/risk-allocation/risk-budgeting/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
riskBudgetingWeights(assetIds, covariance, riskBudgets)
```

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

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `assetIds` | `readonly unknown[]` | yes |  |
| `covariance` | `readonly unknown[]` | yes |  |
| `riskBudgets` | `readonly unknown[]` | yes |  |

## Worked example

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`:

```json
["A", "B", "C"]
```

`covariance`:

```json
[
  [0.01, 0.016, 0.0015],
  [0.016, 0.04, -0.006],
  [0.0015, -0.006, 0.0225]
]
```

`riskBudgets`:

```json
[0.5, 0.3, 0.2]
```

### Call

```ts
riskBudgetingWeights(assetIds, covariance, riskBudgets)
```

### Returns

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

```json
{
  "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.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.2.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/portfolio-construction/risk-allocation/risk-budgeting/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/portfolio-construction/risk-allocation/risk-budgeting/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/portfolio-construction/llms.txt
