# Options book (options_book)

Desk: Options. Page: https://hedgefund.md/models/options_book

**What it asks.** What are this option book's Greeks, where does it break even, and which shock hurts it most?

Prices a book of European options by Black-Scholes-Merton and gives value, delta, gamma, vega, theta and rho per leg and for the book, a full-reprice P and L grid across spot and vol shocks, the worst node against capital, and exact expiry break-evens. Every price, vol and rate comes from the caller. Not a quote, a margin figure or advice.

Results are hypothetical: arithmetic on the numbers sent, a made-up template or a stated default. Nobody achieved them, and they aren't a forecast, a recommendation, an offer or a record of real trading. Don't show any output to investors or clients, or use it to market an investment. Terms: https://hedgefund.md/terms

## Inputs

| Input | Type | Range | Required | What it is |
| --- | --- | --- | --- | --- |
| `spot` | number | 0.000001 to 1000000000 | yes | Spot price of the underlying. |
| `rate_pct` | number | -10 to 50 | yes | Continuously compounded interest rate. 4 means 4%. |
| `dividend_yield_pct` | number | -10 to 50 | yes | Continuous dividend yield on the underlying. 1 means 1%. |
| `capital` | number | 0.01 to 10000000000000 | yes | Capital the worst loss is measured against. |
| `legs` | array | 1 to 30 items | yes | The options in the book. Up to 30. |
| `legs[].type` | string | call \| put | yes | Call or put. |
| `legs[].qty` | number | -10000000 to 10000000 | yes | Contracts, signed. Negative is short. |
| `legs[].strike` | number | 0.000001 to 1000000000 | yes | Strike price. |
| `legs[].expiry_years` | number | 0 to 30 | yes | Years to expiry. 0 means expiring now. |
| `legs[].vol_pct` | number | 0 to 500 | yes | This leg's volatility. 20 means 20%. |
| `legs[].multiplier` | number | 0.000001 to 1000000 | no | Units of underlying per contract. Default 100. |
| `spot_shocks_pct` | array | 0 to 15 items | no | Instant spot moves for the grid. -10 means down 10%. Left out or empty uses -30 to +30. |
| `vol_shocks_pts` | array | 0 to 15 items | no | Vol shifts for the grid, in vol points on every leg. Left out or empty uses -5 to +20. |
| `loss_limit_pct` | number | 0.01 to 1000 | no | The caller's own loss line, as a share of capital, for flags and flips. Default 25. |

## Template

Made-up numbers that run as they stand, so you can see the shape of a result. They aren't market levels, typical values or estimates, and the names in them don't exist. Replace every number before you read anything into a run.

```json
{
  "spot": 100,
  "rate_pct": 4,
  "dividend_yield_pct": 1,
  "capital": 50000,
  "loss_limit_pct": 25,
  "legs": [
    {
      "type": "put",
      "qty": -10,
      "strike": 90,
      "expiry_years": 0.25,
      "vol_pct": 26,
      "multiplier": 100
    },
    {
      "type": "put",
      "qty": 10,
      "strike": 80,
      "expiry_years": 0.25,
      "vol_pct": 32,
      "multiplier": 100
    },
    {
      "type": "call",
      "qty": -10,
      "strike": 110,
      "expiry_years": 0.25,
      "vol_pct": 20,
      "multiplier": 100
    }
  ],
  "spot_shocks_pct": [-30, -20, -10, -5, 0, 5, 10, 20, 30],
  "vol_shocks_pts": [-5, 0, 5, 10, 20]
}
```

## What the template gives

On these numbers, the book is worth -1,916.83 at the vols sent, with delta -92.27 units, and its worst grid node (spot +30%, vol +20 points) loses 21,592.5, or 43.18% of capital. Expiry break-evens at 88.08 and 111.92.

- Book value: -1,916.83
- Delta: -92.27 units of underlying
- Gamma: -40.23 units per 1 of spot
- Vega: -207.42 per vol point
- Theta: 23.4 per calendar day
- Rho: -18.28 per 1% of rate
- Worst grid node: -21,592.5
- Worst node, share of capital: 43.18% (breach)

Where it flips, with the other inputs held:

- `spot_at_expiry` at 88.08316974: Expiry P and L is a loss below this spot and a gain above it.
- `spot_at_expiry` at 111.9168303: Expiry P and L is a gain below this spot and a loss above it.
- `spot_shock_pct` at 22.94921041: A spot rise of this size, at the vols sent, reaches an instant loss of 25% of capital, the loss line in use.
- `vol_shock_pts` at 54.37068462: A vol rise of this many points on every leg, at today's spot, reaches an instant loss of 25% of capital, the loss line in use.
- `spot` at 97.60749653: The book's delta changes sign at this spot, at the vols sent.

## Formula

d1 = (ln(S/K) + (r - q + v^2/2) T) / (v sqrt(T)), d2 = d1 - v sqrt(T). Call = S e^(-qT) N(d1) - K e^(-rT) N(d2). Put = K e^(-rT) N(-d2) - S e^(-qT) N(-d1). Greeks are the closed-form partials, times qty and multiplier. A grid node's P and L is the full reprice at the shocked spot and vol, minus today's value.

## Assumptions

- European exercise. One flat vol per leg, with a continuous rate and a continuous dividend yield.
- Delta is per unit of underlying, times qty and multiplier. Gamma is the change in that delta per 1 of spot. Vega is per one vol point. Theta is per calendar day: annual theta over 365. Rho is per one percent of rate.
- Grid shocks are instant. No time passes, the rate and yield stay put, and every leg's vol moves by the same points, floored at zero.
- Zero time is intrinsic on the spot, with no time left to earn or lose, so vega, theta and rho are zero.
- Zero vol with time left is intrinsic on the discounted forward: a call is max(S e^-qT - K e^-rT, 0), a put the mirror. Gamma is reported as zero there.
- A leg with zero vol exactly at its forward, or zero time exactly at its strike, takes N(d1) = one half, the limit of the formula.
- Values come from the vols sent, not from trade prices. Expiry P and L is the payoff minus today's model value, with no interest on that value.
- The sleeve's gross and net are delta times spot over capital, summed by leg. Its tail is the worst grid node.

## Not modeled

- Early exercise of American options.
- Skew and term-structure moves: every leg's vol shifts by the same points.
- Discrete dividends and jumps. The spot is lognormal between shocks.
- Delta hedging and its costs. The grid is a one-time shock, not a path.
- Bid-ask spreads, commissions, slippage, margin and financing of the premium.
- Assignment, pin risk and settlement details at expiry.
- Taxes.

## Call it

Every result has the same fields: summary, readings, tables, charts, flags, flips, formula, assumptions, not_modeled, hypothetical and inputs_hash. Read flags, flips and not_modeled with the summary, and pass them along together.

### HTTP

No key. The tools keep nothing you send. Send positions by POST, because a URL can land in a server log.

```bash
curl -s https://hedgefund.md/api/v1/options_book \
  -H 'content-type: application/json' \
  -d '{"spot":100,"rate_pct":4,"dividend_yield_pct":1,"capital":50000,"loss_limit_pct":25,"legs":[{"type":"put","qty":-10,"strike":90,"expiry_years":0.25,"vol_pct":26,"multiplier":100},{"type":"put","qty":10,"strike":80,"expiry_years":0.25,"vol_pct":32,"multiplier":100},{"type":"call","qty":-10,"strike":110,"expiry_years":0.25,"vol_pct":20,"multiplier":100}],"spot_shocks_pct":[-30,-20,-10,-5,0,5,10,20,30],"vol_shocks_pts":[-5,0,5,10,20]}' \
  | jq '{summary, flags, flips, not_modeled, inputs_hash}'
```

### MCP

The tool is `options_book` on the server at https://hedgefund.md/mcp.

```bash
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":"options_book","arguments":{"spot":100,"rate_pct":4,"dividend_yield_pct":1,"capital":50000,"loss_limit_pct":25,"legs":[{"type":"put","qty":-10,"strike":90,"expiry_years":0.25,"vol_pct":26,"multiplier":100},{"type":"put","qty":10,"strike":80,"expiry_years":0.25,"vol_pct":32,"multiplier":100},{"type":"call","qty":-10,"strike":110,"expiry_years":0.25,"vol_pct":20,"multiplier":100}],"spot_shocks_pct":[-30,-20,-10,-5,0,5,10,20,30],"vol_shocks_pts":[-5,0,5,10,20]}}}' \
  | jq '.result.structuredContent | {summary, flags, flips, not_modeled, inputs_hash}'
```

### The library

The same code on your own machine, with no dependencies, and nothing is sent anywhere.

```bash
curl -fsSL https://hedgefund.md/hedgefund.mjs -o hedgefund.mjs   # read it before you run it
node hedgefund.mjs template options_book > mine.json           # replace every number in it
node hedgefund.mjs run options_book mine.json | jq '{summary, flags, flips, not_modeled, inputs_hash}'
```

In a script:

```js
import { run, template } from "./hedgefund.mjs";

const inputs = template("options_book"); // replace every number in it
const { summary, flags, flips, not_modeled } = run("options_book", inputs);
```
