Models / Equities / long_short_book
Long-short book
How much of this book's risk is factor bets, which names carry it, and what would it take to flatten the first factor?
Splits a long-short book into gross, net, factor exposures and each position's share of variance, adds hypothetical carry, and sizes the hedge that takes the first factor to zero. Weights, betas, vols and rates all come from the caller. It is arithmetic on those numbers, not an optimizer, a forecast or a trade idea.
On these numbers, the book is 220% gross and 20% net, runs 24.05% annual vol, and 31.73% of its variance comes from factors. Taking Market to zero would take a hedge of -72.5% of NAV, which is arithmetic, not a trade to make.
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.
Gross
ok220%of NAV
Long 120, short 100.
Net
ok20%of NAV
Annual vol
24.05%
Square root of factor variance plus idiosyncratic variance.
Factor share of variance
breach31.73%
Exposure to Market
72.5%of NAV
Sum of signed weight times beta.
Hedge to take Market to zero
-72.5%of NAV
Vol goes to 21.63%, gross to 292.5%, net to -52.5%.
Largest risk share: Stock A
27.51%
Hypothetical carry
5.8475%of NAV a year
From the alphas sent, after borrow and financing. A rebate on short proceeds at the cash rate would add 4 and isn't counted.
What flips it
The value of one input where the outcome changes, with the others held.
hedge_on_first_factor_pct
-17.7
A Market hedge of this size, as a percent of NAV, puts factor share exactly at the 25% limit.
factors.0.vol_pct
12.09%now 16
At this Market vol, factor share sits exactly at the 25% limit, with weights unchanged.
financing_rate_pct
35.24%now 6
At this financing rate the hypothetical carry is zero. Above it, carry is negative.
Flags
What went past a line, and what to read before you trust the rest.
- breachFactors are 31.73% of variance, over the limit of 25%. factor_share_over_limit
- watchNet by weight is 20% of NAV, but exposure to Market is 72.5%. Net by weight doesn't show this. net_hides_factor
- watchThe hedge takes gross from 220% to 292.5%, past the limit of 250%. hedge_breaks_gross
- watchThe hedge takes net from 20% to -52.5%, past the limit of 30%. hedge_breaks_net
What this leaves out
What the formula leaves out, by name.
- Short rebate: sale proceeds earn nothing here. The note on the carry reading shows what a rebate at the cash rate would add.
- Recall risk on borrowed names, and borrow rates that move.
- Fat tails and stress: this is variance only, with no skew and no gap moves.
- Betas and factor vols that change over time.
- Margin requirements, liquidity, and the time it takes to close a position.
- Slippage, commissions, fees and taxes.
What it took as given (6)
What it took as given to get here.
- Weights are signed shares of NAV. Vols, alphas and rates are annual.
- Idiosyncratic risks are independent of the factors and of each other.
- expected_alpha_pct is the stock's own alpha, so the book's alpha is the sum of signed weight times alpha, and a short earns when alpha is negative.
- Financing is charged only on longs above 100% of NAV. Cash earns only on what longs leave of NAV. Short sale proceeds earn nothing and fund nothing.
- Risk shares are each position's weight times its covariance with the book, over book variance, so they add to 100%, and a share below zero means the position offsets the rest.
- The first-factor hedge is a pure instrument: beta 1 to that factor, 0 to the others, no idiosyncratic risk, no cost. Its size adds to gross and to net.
The data
Positions
| name | weight_pct | risk_share_pct | alpha_contribution_pct | borrow_cost_pct |
|---|---|---|---|---|
| Stock A | 30 | 27.51 | 1.8 | 0 |
| Stock B | 25 | 18.56 | 1.25 | 0 |
| Stock C | 25 | 25.66 | 1 | 0 |
| Stock D | 20 | 10.99 | 0.6 | 0 |
| Stock E | 20 | 9.0814 | 0.4 | 0 |
| Stock F | -30 | 1.4799 | 0.9 | 0.09 |
| Stock G | -30 | 3.517 | 1.2 | 0.15 |
| Stock H | -25 | 0.132 | 0.5 | 0.0625 |
| Stock I | -15 | 3.0631 | 0.9 | 1.2 |
Factors
| name | vol_pct | exposure_pct | share_of_variance_pct |
|---|---|---|---|
| Market | 16 | 72.5 | 21.21 |
| Value | 8 | -41 | 2.3838 |
| Momentum | 10 | 69.5 | 8.1371 |
Hypothetical carry, percent of NAV a year
| line | value_pct |
|---|---|
| Alpha from the numbers sent | 8.55 |
| Borrow on shorts | -1.5025 |
| Financing on longs above NAV | -1.2 |
| Cash on what longs leave | 0 |
| Carry | 5.8475 |
Hedging Market
| case | hedge_pct | vol_pct | gross_pct | net_pct |
|---|---|---|---|---|
| No hedge | 0 | 24.05 | 220 | 20 |
| Market to zero | -72.5 | 21.63 | 292.5 | -52.5 |
| Least variance | -66.11 | 21.6 | 286.11 | -46.11 |
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/long_short_book.md.
# Long-short book: 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.** How much of this book's risk is factor bets, which names carry it, and what would it take to flatten the first factor?## Methode_k = sum w_i beta_ik. F_jk = corr_jk vol_j vol_k. variance = e' F e + sum (w_i sigma_i)^2. share_i = w_i (beta_i' F e + w_i sigma_i^2) / variance. carry = sum w_i alpha_i - sum over shorts |w_i| borrow_i - max(0, long - 1) financing + max(0, 1 - long) cash.## Conventions- Weights are signed shares of NAV. Vols, alphas and rates are annual.- Idiosyncratic risks are independent of the factors and of each other.- expected_alpha_pct is the stock's own alpha, so the book's alpha is the sum of signed weight times alpha, and a short earns when alpha is negative.- Financing is charged only on longs above 100% of NAV. Cash earns only on what longs leave of NAV. Short sale proceeds earn nothing and fund nothing.- Risk shares are each position's weight times its covariance with the book, over book variance, so they add to 100%, and a share below zero means the position offsets the rest.- The first-factor hedge is a pure instrument: beta 1 to that factor, 0 to the others, no idiosyncratic risk, no cost. Its size adds to gross and to net.## 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{ "positions": [ { "name": "Stock A", "weight_pct": 30, "betas": [1.3, -0.2, 0.5], "idio_vol_pct": 30, "expected_alpha_pct": 6 }, { "name": "Stock B", "weight_pct": 25, "betas": [1.2, -0.1, 0.4], "idio_vol_pct": 28, "expected_alpha_pct": 5 }, { "name": "Stock C", "weight_pct": 25, "betas": [1.4, -0.3, 0.6], "idio_vol_pct": 35, "expected_alpha_pct": 4 }, { "name": "Stock D", "weight_pct": 20, "betas": [1.1, 0.2, 0.2], "idio_vol_pct": 25, "expected_alpha_pct": 3 }, { "name": "Stock E", "weight_pct": 20, "betas": [1, 0.3, 0.1], "idio_vol_pct": 22, "expected_alpha_pct": 2 }, { "name": "Stock F", "weight_pct": -30, "betas": [0.7, 0.4, -0.2], "idio_vol_pct": 20, "expected_alpha_pct": -3, "borrow_bps": 30 }, { "name": "Stock G", "weight_pct": -30, "betas": [0.8, 0.3, -0.3], "idio_vol_pct": 24, "expected_alpha_pct": -4, "borrow_bps": 50 }, { "name": "Stock H", "weight_pct": -25, "betas": [0.6, 0.5, -0.1], "idio_vol_pct": 18, "expected_alpha_pct": -2, "borrow_bps": 25 }, { "name": "Stock I", "weight_pct": -15, "betas": [0.9, 0.1, -0.4], "idio_vol_pct": 40, "expected_alpha_pct": -6, "borrow_bps": 800 } ], "factors": [ { "name": "Market", "vol_pct": 16 }, { "name": "Value", "vol_pct": 8 }, { "name": "Momentum", "vol_pct": 10 } ], "factor_corr": [ [1, 0.1, -0.1], [0.1, 1, -0.3], [-0.1, -0.3, 1] ], "cash_rate_pct": 4, "financing_rate_pct": 6, "max_gross_pct": 250, "max_net_pct": 30, "max_factor_share_pct": 25}```Work them out with the method above. Yours should match these within 0.5%.- Gross: 220 % of NAV- Net: 20 % of NAV- Annual vol: 24.0536 %- Factor share of variance: 31.7269 %- Exposure to Market: 72.5 % of NAV- Hedge to take Market to zero: -72.5 % of NAV- Largest risk share: Stock A: 27.5123 %- Hypothetical carry: 5.8475 % of NAV a yearWhere the outcome flips, with the other inputs held:- hedge_on_first_factor_pct at -17.7025: A Market hedge of this size, as a percent of NAV, puts factor share exactly at the 25% limit.- factors.0.vol_pct at 12.0932: At this Market vol, factor share sits exactly at the 25% limit, with weights unchanged.- financing_rate_pct at 35.2375: At this financing rate the hypothetical carry is zero. Above it, carry is negative.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:- Short rebate: sale proceeds earn nothing here. The note on the carry reading shows what a rebate at the cash rate would add.- Recall risk on borrowed names, and borrow rates that move.- Fat tails and stress: this is variance only, with no skew and no gap moves.- Betas and factor vols that change over time.- Margin requirements, liquidity, and the time it takes to close a position.- Slippage, commissions, fees and taxes.## 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/long_short_book/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/long_short_book.
curl -s https://hedgefund.md/api/v1/long_short_book \ -H 'content-type: application/json' \ -d '{"positions":[{"name":"Stock A","weight_pct":30,"betas":[1.3,-0.2,0.5],"idio_vol_pct":30,"expected_alpha_pct":6},{"name":"Stock B","weight_pct":25,"betas":[1.2,-0.1,0.4],"idio_vol_pct":28,"expected_alpha_pct":5},{"name":"Stock C","weight_pct":25,"betas":[1.4,-0.3,0.6],"idio_vol_pct":35,"expected_alpha_pct":4},{"name":"Stock D","weight_pct":20,"betas":[1.1,0.2,0.2],"idio_vol_pct":25,"expected_alpha_pct":3},{"name":"Stock E","weight_pct":20,"betas":[1,0.3,0.1],"idio_vol_pct":22,"expected_alpha_pct":2},{"name":"Stock F","weight_pct":-30,"betas":[0.7,0.4,-0.2],"idio_vol_pct":20,"expected_alpha_pct":-3,"borrow_bps":30},{"name":"Stock G","weight_pct":-30,"betas":[0.8,0.3,-0.3],"idio_vol_pct":24,"expected_alpha_pct":-4,"borrow_bps":50},{"name":"Stock H","weight_pct":-25,"betas":[0.6,0.5,-0.1],"idio_vol_pct":18,"expected_alpha_pct":-2,"borrow_bps":25},{"name":"Stock I","weight_pct":-15,"betas":[0.9,0.1,-0.4],"idio_vol_pct":40,"expected_alpha_pct":-6,"borrow_bps":800}],"factors":[{"name":"Market","vol_pct":16},{"name":"Value","vol_pct":8},{"name":"Momentum","vol_pct":10}],"factor_corr":[[1,0.1,-0.1],[0.1,1,-0.3],[-0.1,-0.3,1]],"cash_rate_pct":4,"financing_rate_pct":6,"max_gross_pct":250,"max_net_pct":30,"max_factor_share_pct":25}' \ | jq '{summary, flags, flips, not_modeled, inputs_hash}'The tool is long_short_book 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":"long_short_book","arguments":{"positions":[{"name":"Stock A","weight_pct":30,"betas":[1.3,-0.2,0.5],"idio_vol_pct":30,"expected_alpha_pct":6},{"name":"Stock B","weight_pct":25,"betas":[1.2,-0.1,0.4],"idio_vol_pct":28,"expected_alpha_pct":5},{"name":"Stock C","weight_pct":25,"betas":[1.4,-0.3,0.6],"idio_vol_pct":35,"expected_alpha_pct":4},{"name":"Stock D","weight_pct":20,"betas":[1.1,0.2,0.2],"idio_vol_pct":25,"expected_alpha_pct":3},{"name":"Stock E","weight_pct":20,"betas":[1,0.3,0.1],"idio_vol_pct":22,"expected_alpha_pct":2},{"name":"Stock F","weight_pct":-30,"betas":[0.7,0.4,-0.2],"idio_vol_pct":20,"expected_alpha_pct":-3,"borrow_bps":30},{"name":"Stock G","weight_pct":-30,"betas":[0.8,0.3,-0.3],"idio_vol_pct":24,"expected_alpha_pct":-4,"borrow_bps":50},{"name":"Stock H","weight_pct":-25,"betas":[0.6,0.5,-0.1],"idio_vol_pct":18,"expected_alpha_pct":-2,"borrow_bps":25},{"name":"Stock I","weight_pct":-15,"betas":[0.9,0.1,-0.4],"idio_vol_pct":40,"expected_alpha_pct":-6,"borrow_bps":800}],"factors":[{"name":"Market","vol_pct":16},{"name":"Value","vol_pct":8},{"name":"Momentum","vol_pct":10}],"factor_corr":[[1,0.1,-0.1],[0.1,1,-0.3],[-0.1,-0.3,1]],"cash_rate_pct":4,"financing_rate_pct":6,"max_gross_pct":250,"max_net_pct":30,"max_factor_share_pct":25}}}' \ | 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 long_short_book > mine.json # replace every number in itnode hedgefund.mjs run long_short_book mine.json | jq '{summary, flags, flips, not_modeled, inputs_hash}'Made-up numbers that run as they stand. Replace every one.
{ "positions": [ { "name": "Stock A", "weight_pct": 30, "betas": [1.3, -0.2, 0.5], "idio_vol_pct": 30, "expected_alpha_pct": 6 }, { "name": "Stock B", "weight_pct": 25, "betas": [1.2, -0.1, 0.4], "idio_vol_pct": 28, "expected_alpha_pct": 5 }, { "name": "Stock C", "weight_pct": 25, "betas": [1.4, -0.3, 0.6], "idio_vol_pct": 35, "expected_alpha_pct": 4 }, { "name": "Stock D", "weight_pct": 20, "betas": [1.1, 0.2, 0.2], "idio_vol_pct": 25, "expected_alpha_pct": 3 }, { "name": "Stock E", "weight_pct": 20, "betas": [1, 0.3, 0.1], "idio_vol_pct": 22, "expected_alpha_pct": 2 }, { "name": "Stock F", "weight_pct": -30, "betas": [0.7, 0.4, -0.2], "idio_vol_pct": 20, "expected_alpha_pct": -3, "borrow_bps": 30 }, { "name": "Stock G", "weight_pct": -30, "betas": [0.8, 0.3, -0.3], "idio_vol_pct": 24, "expected_alpha_pct": -4, "borrow_bps": 50 }, { "name": "Stock H", "weight_pct": -25, "betas": [0.6, 0.5, -0.1], "idio_vol_pct": 18, "expected_alpha_pct": -2, "borrow_bps": 25 }, { "name": "Stock I", "weight_pct": -15, "betas": [0.9, 0.1, -0.4], "idio_vol_pct": 40, "expected_alpha_pct": -6, "borrow_bps": 800 } ], "factors": [ { "name": "Market", "vol_pct": 16 }, { "name": "Value", "vol_pct": 8 }, { "name": "Momentum", "vol_pct": 10 } ], "factor_corr": [ [1, 0.1, -0.1], [0.1, 1, -0.3], [-0.1, -0.3, 1] ], "cash_rate_pct": 4, "financing_rate_pct": 6, "max_gross_pct": 250, "max_net_pct": 30, "max_factor_share_pct": 25}Inputs
| Input | Type | Range | Required | What it is |
|---|---|---|---|---|
| positions | array | 1 to 200 items | yes | The book, one line per name. |
| positions[].name | string | yes | A label for the position, such as Stock A. | |
| positions[].weight_pct | number | -1000 to 1000 | yes | Signed share of NAV. 30 is long 30% of NAV, -30 is short 30%. |
| positions[].betas | array | 1 to 12 items | yes | One beta per factor, in the order of factors. |
| positions[].idio_vol_pct | number | 0 to 500 | yes | Annual volatility not explained by the factors, in percent. |
| positions[].expected_alpha_pct | number | -500 to 500 | no | The stock's own hypothetical annual alpha, in percent. A short earns when this is negative. Default 0. |
| positions[].borrow_bps | number | 0 to 100000 | no | Annual borrow fee on a short, in basis points of the short. Ignored on longs. Default 0. |
| factors | array | 1 to 12 items | yes | The factors, in the order of each position's betas. |
| factors[].name | string | yes | A label for the factor, such as Market. | |
| factors[].vol_pct | number | 0 to 500 | yes | Annual factor volatility, in percent. |
| factor_corr | array | 1 to 12 items | no | Optional factor correlation matrix. Default is identity: factors independent. |
| cash_rate_pct | number | -10 to 100 | yes | Annual rate earned on what longs leave of NAV, in percent. |
| financing_rate_pct | number | -10 to 100 | yes | Annual rate paid on longs above 100% of NAV, in percent. |
| max_gross_pct | number | 0 to 10000 | no | Optional limit on gross, in percent of NAV. |
| max_net_pct | number | 0 to 10000 | no | Optional limit on the size of net, in percent of NAV. |
| max_factor_share_pct | number | 0 to 100 | no | Optional limit on the factor share of variance, in percent. |
Hypothetical, and on made-up numbers until you replace them. Nobody traded this, and nothing here is on offer.