Models / Macro / risk_parity
Risk parity
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?
Solves equal risk contribution weights for the vols and correlations sent, shows the leverage that reaches a vol target and what financing it costs, then moves every correlation up 0.3 with weights held and shows the new vol and the leverage cut. The vols and correlations come from the caller, and the 0.3 move is fixed. It is arithmetic on those estimates, not an allocation to follow and not a forecast.
On these numbers, equal risk weights put 40.66% in Bond sleeve, leverage of 1.67x reaches the 10% target, and every correlation up 0.3 takes vol to 12.53% with weights and leverage held.
Hypothetical, and on made-up numbers until you replace them. Nobody traded this, and nothing here is on offer.
Readings
The numbers, with their units.
Vol before leverage
5.9894%
Leverage to reach target
1.6696x
Target 10%.
Financing cost
2.6784%of NAV a year
On leverage above 1 only.
Vol with correlations up 0.3
watch12.53%
Same weights, same leverage. Before leverage: 7.5%.
Leverage cut to get back to target
0.3371x
From 1.67x to 1.33x.
Solver residual
ok5.50e-11
Largest gap between a risk share and 1 / n, after 9 sweeps.
Hypothetical return
5.5919%a year
From the returns sent, levered, after financing.
Reference top risk share: Stock sleeve
watch92.13%
Reference weights run 10.13% vol.
What flips it
The value of one input where the outcome changes, with the others held.
target_vol_pct
5.9894%now 10
At this target the book needs no leverage. Above it, leverage is above 1 and financing starts.
financing_rate_pct
4.9535%now 4
At this financing rate leverage adds nothing to the hypothetical return. Above it, leverage takes away.
Flags
What went past a line, and what to read before you trust the rest.
- watchWith every correlation up 0.3 and weights held, vol at the same leverage goes from 10% to 12.53%. Getting back to the target takes leverage from 1.67x to 1.33x. correlation_stress
- watchStock sleeve carries 92.13% of the reference weights' variance. reference_concentrated
What this leaves out
What the formula leaves out, by name.
- 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.
What it took as given (7)
What it took as given to get here.
- 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%.
- Equal risk weights, %
- Reference weights, %
The data
- Equal risk, %
- Reference, %
The data
Weights and risk
| name | vol_pct | weight_pct | levered_weight_pct | risk_share_pct | reference_weight_pct | reference_risk_share_pct | weight_gap_pct |
|---|---|---|---|---|---|---|---|
| Stock sleeve | 16 | 15.28 | 25.51 | 25 | 60 | 92.13 | -44.72 |
| Bond sleeve | 6 | 40.66 | 67.89 | 25 | 40 | 7.8652 | 0.6605 |
| Commodity sleeve | 18 | 14.31 | 23.89 | 25 | 0 | 0 | 14.31 |
| Inflation bond sleeve | 7 | 29.75 | 49.68 | 25 | 0 | 0 | 29.75 |
Correlation stress, weights held
| case | vol_before_leverage_pct | vol_at_leverage_pct | leverage_for_target |
|---|---|---|---|
| As sent | 5.9894 | 10 | 1.6696 |
| Correlations up 0.3 | 7.5047 | 12.53 | 1.3325 |
Paste it into your agent
No connection needed. This prompt carries the method, the conventions and what this site's engine gives on the made-up numbers, so your agent can check its own work before it touches real ones. Every prompt, with its hash, is listed at /prompts.json. A copy that stays fixed for this version, for a stack to point at: /v/1.0/models/risk_parity.md.
# Risk parity: a prompt from hedgefund.mdPaste 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?## MethodSigma_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 numbersThe 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 numbersReplace every input with the person's own. Ask for any number you don't have, and don't invent one.## Step 3: reportGive 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.## LimitsResults 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/termsCall it
The same code answers on this page, over HTTP, over MCP and on your own machine, and the same inputs give the same bytes. No key, and nothing is stored. Send positions by POST or run the library, because a URL can land in a server log. model.md holds all of this for your agent.
POST the inputs to /api/v1/risk_parity.
curl -s https://hedgefund.md/api/v1/risk_parity \ -H 'content-type: application/json' \ -d '{"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]}' \ | jq '{summary, flags, flips, not_modeled, inputs_hash}'The tool is risk_parity on https://hedgefund.md/mcp.
curl -s https://hedgefund.md/mcp \ -H 'content-type: application/json' -H 'accept: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"risk_parity","arguments":{"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]}}}' \ | jq '.result.structuredContent | {summary, flags, flips, not_modeled, inputs_hash}'One file with no dependencies, and nothing is sent anywhere.
curl -fsSL https://hedgefund.md/hedgefund.mjs -o hedgefund.mjs # read it before you run itnode hedgefund.mjs template risk_parity > mine.json # replace every number in itnode hedgefund.mjs run risk_parity mine.json | jq '{summary, flags, flips, not_modeled, inputs_hash}'Made-up numbers that run as they stand. Replace every one.
{ "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]}Inputs
| Input | Type | Range | Required | What it is |
|---|---|---|---|---|
| assets | array | 1 to 40 items | yes | The assets, up to 40. |
| assets[].name | string | yes | A label for the asset, such as Bond sleeve. | |
| assets[].vol_pct | number | 0.01 to 500 | yes | Annual volatility, in percent. Must be above zero. |
| assets[].expected_return_pct | number | -100 to 500 | no | Optional hypothetical annual return, in percent. Send it for all assets or none. |
| corr | array | 1 to 40 items | yes | Correlation matrix, in the order of assets. |
| target_vol_pct | number | 0.01 to 200 | yes | Annual vol target for the levered book, in percent. |
| financing_rate_pct | number | -10 to 100 | yes | Annual rate on leverage above 1, in percent. |
| reference_weights_pct | array | 0 to 40 items | no | Optional weights to compare against, in percent, in the order of assets. |
Hypothetical, and on made-up numbers until you replace them. Nobody traded this, and nothing here is on offer.