# Hierarchical Risk Parity

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

Full page: https://docs.thefintechbuilder.com/portfolio-construction/risk-allocation/hierarchical-risk-parity/
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 { hierarchicalRiskParityWeights } from "fintech-algorithms/portfolio-construction/risk-allocation/hierarchical-risk-parity";
```

## Signature

```ts
hierarchicalRiskParityWeights(assetIds, covariance)
```

Allocates capital by clustering assets on a correlation-derived profile distance, then splitting capital down the tree by branch variance, without inverting the covariance matrix.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `assetIds` | `readonly unknown[]` | yes |  |
| `covariance` | `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", "D"]
```

`covariance`:

```json
[
  [0.04, 0.036, 0.004, 0.002],
  [0.036, 0.04, 0.003, 0.001],
  [0.004, 0.003, 0.01, 0.008]
]
```

Showing 3 of 4 elements.

### Call

```ts
hierarchicalRiskParityWeights(assetIds, covariance)
```

### Returns

object with 18 fields: assetIds, weights, componentRiskContributions, componentRiskShares, portfolioVariance, portfolioVolatility, sumWeights, quasiDiagonalOrder, …

```json
{
  "assetIds": ["A", "B", "C", "D"],
  "weights": [
    0.10688050930460334,
    0.10688050930460334,
    0.5443192948090109,
    0.2419196865817826
  ],
  "componentRiskContributions": [
    0.012087521651000223,
    0.01120624850215681,
    0.046390190600378356,
    0.025670836878125575
  ],
  "componentRiskShares": [
    0.12676364431805753,
    0.11752160122498084,
    0.4865008552540336,
    0.26921389920292804
  ],
  "portfolioVariance": 0.009092537431375017,
  "portfolioVolatility": 0.09535479763166098,
  "sumWeights": 1.0000000000000002,
  "quasiDiagonalOrder": [0, 1, 2, 3],
  "correlationMatrix": [
    [1, 0.8999999999999999, 0.2, 0.06666666666666667],
    [0.8999999999999999, 1, 0.15, 0.03333333333333333],
    [0.2, 0.15, 1, 0.5333333333333333]
  ],
  "distanceMatrix": [
    [0, 0.3170569112290949, 1.0116748865867387, 1.0853926811234083],
    [0.3170569112290949, 0, 1.030619181950856, 1.0983382141884035],
    [1.0116748865867387, 1.030619181950856, 0, 0.6863742401099239]
  ],
  "merges": [
    {
      "left": [0],
      "right": [1],
      "distance": 0.3170569112290949
    },
    {
      "left": [2],
      "right": [3],
      "distance": 0.6863742401099239
    },
    {
      "left": [0, 1],
      "right": [2, 3],
      "distance": 1.0116748865867387
    }
  ],
  "method": "hierarchical-risk-parity",
  "linkage": "single",
  "distance": "euclidean-distance-between-sqrt((1-correlation)/2)-profiles"
}
```

Showing 14 of 18 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/hierarchical-risk-parity/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/portfolio-construction/risk-allocation/hierarchical-risk-parity/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/portfolio-construction/llms.txt
