HEDGEFUND.md

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.

The paste-ready promptmodel.md

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

ok

220%of NAV

Long 120, short 100.

Net

ok

20%of NAV

Annual vol

24.05%

Square root of factor variance plus idiosyncratic variance.

Factor share of variance

breach

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

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

  2. factors.0.vol_pct

    12.09%now 16

    At this Market vol, factor share sits exactly at the 25% limit, with weights unchanged.

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

  • breach
    Factors are 31.73% of variance, over the limit of 25%. factor_share_over_limit
  • watch
    Net by weight is 20% of NAV, but exposure to Market is 72.5%. Net by weight doesn't show this. net_hides_factor
  • watch
    The hedge takes gross from 220% to 292.5%, past the limit of 250%. hedge_breaks_gross
  • watch
    The 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.
Share of book variance by position% of variance
01020Stock AStock CStock BStock DStock EStock GStock IStock FStock H
The data

Positions

nameweight_pctrisk_share_pctalpha_contribution_pctborrow_cost_pct
Stock A3027.511.80
Stock B2518.561.250
Stock C2525.6610
Stock D2010.990.60
Stock E209.08140.40
Stock F-301.47990.90.09
Stock G-303.5171.20.15
Stock H-250.1320.50.0625
Stock I-153.06310.91.2

Factors

namevol_pctexposure_pctshare_of_variance_pct
Market1672.521.21
Value8-412.3838
Momentum1069.58.1371

Hypothetical carry, percent of NAV a year

linevalue_pct
Alpha from the numbers sent8.55
Borrow on shorts-1.5025
Financing on longs above NAV-1.2
Cash on what longs leave0
Carry5.8475

Hedging Market

casehedge_pctvol_pctgross_pctnet_pct
No hedge024.0522020
Market to zero-72.521.63292.5-52.5
Least variance-66.1121.6286.11-46.11

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

inputs_hash c8eec413a63ea163

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.

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

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

Inputs

InputTypeRangeRequiredWhat it is
positionsarray1 to 200 itemsyesThe book, one line per name.
positions[].namestringyesA label for the position, such as Stock A.
positions[].weight_pctnumber-1000 to 1000yesSigned share of NAV. 30 is long 30% of NAV, -30 is short 30%.
positions[].betasarray1 to 12 itemsyesOne beta per factor, in the order of factors.
positions[].idio_vol_pctnumber0 to 500yesAnnual volatility not explained by the factors, in percent.
positions[].expected_alpha_pctnumber-500 to 500noThe stock's own hypothetical annual alpha, in percent. A short earns when this is negative. Default 0.
positions[].borrow_bpsnumber0 to 100000noAnnual borrow fee on a short, in basis points of the short. Ignored on longs. Default 0.
factorsarray1 to 12 itemsyesThe factors, in the order of each position's betas.
factors[].namestringyesA label for the factor, such as Market.
factors[].vol_pctnumber0 to 500yesAnnual factor volatility, in percent.
factor_corrarray1 to 12 itemsnoOptional factor correlation matrix. Default is identity: factors independent.
cash_rate_pctnumber-10 to 100yesAnnual rate earned on what longs leave of NAV, in percent.
financing_rate_pctnumber-10 to 100yesAnnual rate paid on longs above 100% of NAV, in percent.
max_gross_pctnumber0 to 10000noOptional limit on gross, in percent of NAV.
max_net_pctnumber0 to 10000noOptional limit on the size of net, in percent of NAV.
max_factor_share_pctnumber0 to 100noOptional 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.

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.