# Long-short book: 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.** How much of this book's risk is factor bets, which names carry it, and what would it take to flatten the first factor?

## Method

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.

## 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 numbers

The 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 year

Where 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 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:

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

## 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/long_short_book/prompt.md. Terms: https://hedgefund.md/terms
