# Risk parity: a prompt from hedgefund.md

Paste this into your AI agent. It needs no connection to hedgefund.md. An agent that can run code should write and run it, and shouldn't work a long series by hand.

**Question.** What weights give each asset the same share of risk, how much leverage reaches the vol target, and what does a jump in correlation do to it?

## Method

Sigma_ij = corr_ij vol_i vol_j. Cyclical coordinate descent: x_i = (-b + sqrt(b^2 + 4 a c)) / (2 a), a = Sigma_ii, b = sum over j != i of x_j Sigma_ij, c = 1 / n. w = x / sum x. Risk share_i = w_i (Sigma w)_i / w' Sigma w. Leverage k = target / sqrt(w' Sigma w). Return = k sum w_i mu_i - max(0, k - 1) financing. Stress: corr_ij + 0.3, capped at 0.99, with w and k held.

## Conventions

- Weights are long only and add to 100% before leverage. Equal risk contribution has one solution for a positive definite matrix.
- Descent stops when every risk share is within 1e-10 of 1 / n. The residual shows how close it got.
- If 2000 sweeps haven't got there, which happens when the matrix is close to singular, Newton steps on the same objective finish it. The objective has one minimum, so the route doesn't change the answer.
- Above a leverage of 1, financing is charged on the amount above 1. Below 1, the rest sits idle and earns nothing.
- Stress adds 0.3 to every off-diagonal correlation, capped at 0.99, and never lowers one already above 0.99.
- The leverage cut is the fall in leverage that brings stressed vol back to the target.
- Reference weights are used as sent, without scaling to 100%.

## Step 1: check your method on these made-up numbers

The numbers and names below are made up. They aren't market levels, typical values or anyone's real figures.

```json
{
  "assets": [
    { "name": "Stock sleeve", "vol_pct": 16, "expected_return_pct": 7 },
    { "name": "Bond sleeve", "vol_pct": 6, "expected_return_pct": 4.5 },
    {
      "name": "Commodity sleeve",
      "vol_pct": 18,
      "expected_return_pct": 5
    },
    {
      "name": "Inflation bond sleeve",
      "vol_pct": 7,
      "expected_return_pct": 4.5
    }
  ],
  "corr": [
    [1, 0.1, 0.3, 0.1],
    [0.1, 1, -0.1, 0.6],
    [0.3, -0.1, 1, 0.2],
    [0.1, 0.6, 0.2, 1]
  ],
  "target_vol_pct": 10,
  "financing_rate_pct": 4,
  "reference_weights_pct": [60, 40, 0, 0]
}
```

Work them out with the method above. Yours should match these within 0.5%.

- Vol before leverage: 5.9894 %
- Leverage to reach target: 1.6696 x
- Financing cost: 2.6784 % of NAV a year
- Vol with correlations up 0.3: 12.53 %
- Leverage cut to get back to target: 0.3371 x
- Solver residual: 5.502487355e-11
- Hypothetical return: 5.5919 % a year
- Reference top risk share: Stock sleeve: 92.1348 %

Where the outcome flips, with the other inputs held:

- target_vol_pct at 5.989421: At this target the book needs no leverage. Above it, leverage is above 1 and financing starts.
- financing_rate_pct at 4.9535: At this financing rate leverage adds nothing to the hypothetical return. Above it, leverage takes away.

If yours differ, stop and tell the person which ones and by how much. Don't go on to real numbers until they match, or until the person has seen the difference. These values come from one engine and can be wrong too.

## Step 2: run it on the person's numbers

Replace every input with the person's own. Ask for any number you don't have, and don't invent one.

## Step 3: report

Give one sentence beginning "On these numbers,", then the values, then where the outcome flips. Always add what this leaves out:

- Error in the vols and correlations themselves. Small changes in them can move these weights.
- Vol and correlation that change over time, except for the one stress here.
- Interest on idle cash, financing spreads that widen under stress, margin calls and forced selling.
- Rebalancing costs, slippage, fees and taxes.
- Fat tails: this works on variance alone.

## Limits

Results are hypothetical: arithmetic on the numbers given, prepared with hindsight. Nobody achieved them, and costs and liquidity are only as assumed. They aren't a forecast, a recommendation, an offer or a record of real trading. Don't say what to buy, sell or hold, and don't use them to market an investment. Whether a person may hold or trade an instrument is a legal question for counsel.

Provided as is, at your own risk, by hedgefund.md, which is not a fund and isn't anyone's adviser. Version 1.0. Source: https://hedgefund.md/models/risk_parity/prompt.md. Terms: https://hedgefund.md/terms
