HEDGEFUND.md

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.

The paste-ready promptmodel.md

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

watch

12.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

ok

5.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

watch

92.13%

Reference weights run 10.13% vol.

What flips it

The value of one input where the outcome changes, with the others held.

  1. target_vol_pct

    5.9894%now 10

    At this target the book needs no leverage. Above it, leverage is above 1 and financing starts.

  2. 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.

  • watch
    With 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
  • watch
    Stock 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%.
Weights% before leverage
  • Equal risk weights, %
  • Reference weights, %
0204060Stock sleeveBond sleeveCommodity sleeveInflation bond sleeve
The data
Share of variance% of variance
  • Equal risk, %
  • Reference, %
020406080Stock sleeveBond sleeveCommodity sleeveInflation bond sleeve
The data

Weights and risk

namevol_pctweight_pctlevered_weight_pctrisk_share_pctreference_weight_pctreference_risk_share_pctweight_gap_pct
Stock sleeve1615.2825.51256092.13-44.72
Bond sleeve640.6667.8925407.86520.6605
Commodity sleeve1814.3123.89250014.31
Inflation bond sleeve729.7549.68250029.75

Correlation stress, weights held

casevol_before_leverage_pctvol_at_leverage_pctleverage_for_target
As sent5.9894101.6696
Correlations up 0.37.504712.531.3325

Hypothetical, computed from the numbers sent and any stated default, with hindsight. Nobody traded it, and costs and liquidity are only as assumed. Not a forecast, a recommendation, an offer, or a record of real trading. Don't use it to market an investment.

formula 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.

inputs_hash a341776cf113406a

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.

prompt.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/terms

Call 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.

terminal
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}'

Inputs

InputTypeRangeRequiredWhat it is
assetsarray1 to 40 itemsyesThe assets, up to 40.
assets[].namestringyesA label for the asset, such as Bond sleeve.
assets[].vol_pctnumber0.01 to 500yesAnnual volatility, in percent. Must be above zero.
assets[].expected_return_pctnumber-100 to 500noOptional hypothetical annual return, in percent. Send it for all assets or none.
corrarray1 to 40 itemsyesCorrelation matrix, in the order of assets.
target_vol_pctnumber0.01 to 200yesAnnual vol target for the levered book, in percent.
financing_rate_pctnumber-10 to 100yesAnnual rate on leverage above 1, in percent.
reference_weights_pctarray0 to 40 itemsnoOptional 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.

1.0Use at your own risk: hedgefund.md is not a fund, not an offer of any security, token or fund interest, and not advice. Results are hypothetical, may be wrong, and are not a record of real trading. Don't use them to market an investment. See the terms.