# Hedge Calculator

## Hedge Calculator (Funding Rate Swap / CFI v2.1)

This calculator sizes a **CFI v2** hedge for a perp position so you can convert floating funding into paying (or receiving) the **fixed leg**.

CFI v2 hedge property:

* For a long perp notional `N_perp`, a long CFI hedge notional `N_hedge` offsets floating funding and leaves you paying fixed. :contentReference\[oaicite:18]{index=18}
* With a volatility multiplier `L` in the oracle mapping, the hedge notional becomes:\
  `N_hedge = N_perp / L` :contentReference\[oaicite:19]{index=19}

***

### Inputs

#### Position

* **Underlying perp direction:** Long or Short
* **Underlying perp notional (USD):** `N_perp`

#### CFI market parameters

* **Volatility multiplier:** `L` (default 12.75 in Profile H1) :contentReference\[oaicite:20]{index=20}
* **CFI swap price (USDC):** `P_swap` (current mark/oracle in the orderbook UI)

#### Hedge preference

* **Hedge fraction:** `h` (0 to 1; default 1.0 for “full lock”)

***

### Step 1 — Compute hedge notional (USD)

**Full hedge (locks funding to fixed leg):** `N_hedge = (N_perp / L) · h` :contentReference\[oaicite:21]{index=21}

**Direction rule**

* If you are **LONG** the underlying perp → take **LONG** the CFI swap
* If you are **SHORT** the underlying perp → take **SHORT** the CFI swap

(Reason: the swap position offsets the sign of floating funding payments so the combined exposure becomes fixed-leg.)

***

### Step 2 — Convert hedge notional to contract size

On Hyperliquid-style perps, notional is approximately:

`notional ≈ |size| × price`

So the CFI contract size is:

`size_swap ≈ N_hedge / P_swap`

***

### Worked examples

#### Example A — From the CFI v2 spec

Underlying perp notional: `N_perp = $10,000,000`\
Profile H1: `L = 12.75` :contentReference\[oaicite:22]{index=22}

Hedge notional: `N_hedge = 10,000,000 / 12.75 ≈ 784,314`

If swap price `P_swap = 75,000`: `size_swap ≈ 784,314 / 75,000 ≈ 10.457 contracts`

#### Example B — Smaller account

Underlying perp notional: `$100,000`\
L = 12.75\
Swap price = 75,000

`N_hedge ≈ 7,843`\
`size_swap ≈ 0.105`

***

### Spreadsheet formulas (copy/paste)

Assume:

* A2 = Underlying notional (USD)
* B2 = L
* C2 = Hedge fraction h
* D2 = Swap price

HedgeNotional (USD): `= (A2 / B2) * C2`

SwapSize (contracts): `= HedgeNotional / D2`

Direction:

* If underlying is Long → swap is Long
* If underlying is Short → swap is Short

***

```js
function cfiHedge({ underlyingNotionalUSD, L, hedgeFraction, swapPrice }) {
  const Nhedge = (underlyingNotionalUSD / L) * hedgeFraction;
  const size = Nhedge / swapPrice;
  return { hedgeNotionalUSD: Nhedge, swapSizeContracts: size };
}

// Example:
console.log(
  cfiHedge({
    underlyingNotionalUSD: 10_000_000,
    L: 12.75,
    hedgeFraction: 1.0,
    swapPrice: 75_000
  })
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nunchi.trade/hedge-calculator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
