> For the complete documentation index, see [llms.txt](https://docs.nexus.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexus.xyz/math-engine/funding-rate.md).

# Funding Rate

Perpetual futures never expire, so a periodic cash transfer between longs and shorts — funding — anchors the contract's mark price to the oracle (spot) price. During each funding interval the Exchange samples the instantaneous premium index $$(P\_{mark} - P\_{oracle})/P\_{oracle}$$ and accumulates it weighted by the time elapsed since the previous sample. At any point in the interval the funding rate is the time-weighted average premium, clamped to a symmetric cap $$\pm c$$. At settlement, each position pays or receives an amount proportional to its notional value at the mark price: with a positive rate, longs pay shorts; with a negative rate, shorts pay longs. The construction is exactly zero-sum between matched long and short open interest.

![The funding rate is a fan-in of the premium accumulator and the interval clock, and settlement feeds back both into a fresh accumulator and into the positioning pressure that moves the next premium.](/files/fhOhTBi5KwZFG60k6O6S)

*The funding rate is a fan-in of the premium accumulator and the interval clock, and settlement feeds back both into a fresh accumulator and into the positioning pressure that moves the next premium.*

## Setting

| Symbol          | Name                 | Description                                                                                                                                                                                                                      | Units                                         | Domain             |
| --------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ------------------ |
| $$P\_{oracle}$$ | oracle\_price        | External index (oracle) price of the underlying asset. Samples with a non-positive oracle price are skipped by the implementation, so the effective domain is strictly positive.                                                 | USDX per unit of asset                        | (0, ∞)             |
| $$P\_{mark}$$   | mark\_price          | The Exchange's mark price for the perpetual market at the sample or settlement time.                                                                                                                                             | USDX per unit of asset                        | (0, ∞)             |
| $$\Delta t$$    | time\_delta\_secs    | Seconds elapsed since the previous sample in the interval. Samples at or before the previous sample time are ignored, so the effective domain is strictly positive. Derived in code from millisecond timestamps divided by 1000. | seconds                                       | (0, ∞)             |
| $$A$$           | accumulated\_premium | Running sum of premium-index samples weighted by their time deltas, $$\sum\_i p\_i , \Delta t\_i$$, over the current funding interval. Reset to zero at each interval boundary.                                                  | dimensionless-seconds (premium × seconds)     | unbounded          |
| $$T$$           | total\_time\_secs    | Total elapsed time in the current interval, from the interval start to the most recent sample. Derived, not stored: when zero (no samples yet) the implementation short-circuits and returns a zero rate rather than dividing.   | seconds                                       | (0, ∞)             |
| $$c$$           | funding\_rate\_cap   | Per-market symmetric cap on the funding rate, stored in market parameters. The specified value is 0.5% per settlement window.                                                                                                    | dimensionless (fraction per funding interval) | (0, ∞)             |
| $$f$$           | funding\_rate        | The clamped funding rate applied to positions at settlement; always lies in $$\[-c, +c]$$.                                                                                                                                       | dimensionless (fraction per funding interval) | \[-0.0075, 0.0075] |
| $$S$$           | size                 | Absolute position size in units of the underlying asset (always non-negative; direction is carried separately by the position side).                                                                                             | units of asset                                | \[0, ∞)            |
| $$\sigma$$      | side\_sign           | Direction indicator for the position: $$+1$$ for a long position, $$-1$$ for a short position. Encodes the match on position side in the implementation.                                                                         | dimensionless                                 | \[-1, 1]           |

## The mechanism

### Premium Index Sampling

Each oracle tick produces one sample of the instantaneous premium index: the relative deviation of the mark price from the oracle price. A positive premium means the perpetual trades rich to the index (longs are crowded); a negative premium means it trades cheap. The implementation skips any sample whose oracle price is not strictly positive, leaving the interval state unchanged, so the division is always well defined.

$$
p = \frac{P\_{mark} - P\_{oracle}}{P\_{oracle}} \tag{F.1}
$$

Samples arrive at an irregular cadence, so each premium index (F.1) is weighted by the time elapsed since the previous sample before being added to the interval accumulator $$A$$. This makes the accumulator the exact time integral of the (piecewise-constant) premium index over the interval, independent of sampling frequency: 1-minute and 5-second cadences produce identical averages for the same premium path. Samples with a timestamp at or before the previous sample time are ignored, so $$\Delta t$$ is strictly positive.

$$
A \leftarrow A + p \cdot \Delta t \tag{F.2}
$$

### Funding Rate

The funding rate at any point in the interval is the time-weighted average premium — the accumulator (F.2) divided by the total elapsed time $$T$$ — clamped to the symmetric per-market cap $$\pm c$$. The clamp bounds the wealth transfer per settlement window regardless of how dislocated the mark price becomes. When no time has elapsed in the interval ($$T = 0$$, i.e. no samples yet), the implementation returns zero rather than dividing by zero. The predicted funding rate published mid-interval is defined to be this same value: the current average is the best estimate of the final rate.

$$
f = \operatorname{clamp}!\left(\frac{A}{T},; -c,; +c\right) \tag{F.3}
$$

### Funding Payments

At settlement each open position exchanges cash proportional to its notional value at the mark price. The signed amount is the position's notional $$S \cdot P\_{mark}$$ times the funding rate (F.3), with the sign flipped for shorts via $$\sigma$$. The convention is: a positive amount means the account pays; a negative amount means the account receives. So with a positive rate ($$f > 0$$, perpetual rich to index) longs pay and shorts receive, and with a negative rate shorts pay and longs receive. For equal long and short size at the same mark and rate, the two amounts cancel exactly.

$$
\Pi = \sigma \cdot S \cdot P\_{mark} \cdot f \tag{F.4}
$$

## Invariants

* The funding rate is always bounded: $$-c \le f \le +c$$ for every interval state ((F.3)).
* Zero premium implies zero rate: if $$P\_{mark} = P\_{oracle}$$ for the whole interval, then $$A = 0$$ and $$f = 0$$.
* When not clamped, the sign of the rate matches the sign of the average premium: a perpetual trading rich to the index yields $$f > 0$$, trading cheap yields $$f < 0$$.
* Funding is exactly zero-sum for matched open interest: for equal long and short size at the same mark price and rate, $$\Pi\_{long} + \Pi\_{short} = 0$$ ((F.4)); verified by property-based testing across the full rate range.
* Payments are linear in position size: tripling $$S$$ triples $$\Pi$$ exactly.
* The rate is well defined at all times: with no samples in the interval ($$T = 0$$) the rate is exactly $$0$$, never a division error.
* Samples with non-positive oracle price or non-increasing timestamps leave the interval state unchanged.
* The TWAP is sampling-cadence invariant for a constant premium: any positive sampling frequency yields $$f$$ equal to the constant premium index (when below the cap).

## Worked example

Consider the BTC perpetual over one 8-hour funding interval with the oracle steady at $$P\_{oracle} = 50{,}000$$. For the first 4 hours the mark price is $$50{,}020$$, a premium index of $$p\_1 = 20/50{,}000 = 0.0004$$ per (F.1); for the last 4 hours the mark is $$50{,}035$$, so $$p\_2 = 35/50{,}000 = 0.0007$$. Sampling once per minute, each phase contributes its premium times its duration to the accumulator per (F.2): $$A = 0.0004 \times 14{,}400 + 0.0007 \times 14{,}400 = 5.76 + 10.08 = 15.84$$ premium-seconds.

The interval spans $$T = 28{,}800$$ seconds, so the raw time-weighted average premium is $$A/T = 15.84 / 28{,}800 = 0.00055$$. With a cap of $$c = 0.0075$$ this is far inside the band, so the clamp in (F.3) does not bind and the settled funding rate is $$f = 0.00055$$ — exactly the duration-weighted mean of the two premium phases, $$(0.0004 + 0.0007)/2$$.

Now settle a 2 BTC long at mark $$50{,}035$$. Its notional is $$2 \times 50{,}035 = 100{,}070$$ USDX, so per (F.4) the payment is $$\Pi = +1 \times 100{,}070 \times 0.00055 \approx 55.04$$ USDX — positive, so the long pays. A 2 BTC short at the same mark has $$\Pi \approx -55.04$$ USDX and receives the same amount: the transfer is exactly zero-sum. Had the market instead sustained a 10% premium all interval, the raw average $$0.10$$ would have been clamped to the cap and every position would settle at $$f = c$$.

## Analysis

### Sensitivity

Elasticities ε = (∂y/∂x)·(x/y), computed numerically from the verified expressions at each worked-example point. |ε| > 1 means the output moves more than proportionally with that input.

| Expression            | Input                | Elasticity ε |
| --------------------- | -------------------- | ------------ |
| `premium_index`       | mark\_price          | 1.43e+03     |
| `premium_index`       | oracle\_price        | -1.43e+03    |
| `sample_contribution` | mark\_price          | 1.43e+03     |
| `sample_contribution` | oracle\_price        | -1.43e+03    |
| `sample_contribution` | time\_delta\_secs    | 1            |
| `funding_rate`        | accumulated\_premium | 1            |
| `funding_rate`        | total\_time\_secs    | -1           |
| `funding_rate`        | funding\_rate\_cap   | 0            |
| `funding_payment`     | side\_sign           | 1            |
| `funding_payment`     | size                 | 1            |
| `funding_payment`     | mark\_price          | 1            |
| `funding_payment`     | funding\_rate        | 1            |

![Sensitivity tornado — Premium index](/files/0rmlq9xOdNUQCEyMqtoG)

![Sensitivity tornado — Funding rate (clamped TWAP)](/files/D5A0l56shLjrGV6vccNq)

![Sensitivity tornado — Funding payment](/files/4NjHeksTEZDaxcAiyABd)

### Response curves

![The instantaneous premium index is linear in the mark price and crosses zero exactly where mark equals the fixed $50,000 oracle price.](/files/1SUb1mnSA8fBVdGHRDph)

*The instantaneous premium index is linear in the mark price and crosses zero exactly where mark equals the fixed $50,000 oracle price.*

![Over a full 8-hour interval (T = 28,800 s) the funding rate rises linearly with the accumulated premium until the average hits the ±0.0075 cap, where it saturates.](/files/tqWwYRMIzFSX3NdUVsJg)

*Over a full 8-hour interval (T = 28,800 s) the funding rate rises linearly with the accumulated premium until the average hits the ±0.0075 cap, where it saturates.*

![At a positive 0.05% rate and $50,000 mark price, payments scale linearly with size and are exactly mirrored between long and short, so matched open interest nets to zero.](/files/D9Gh9DRfsPPKs892Ov1G)

*At a positive 0.05% rate and $50,000 mark price, payments scale linearly with size and are exactly mirrored between long and short, so matched open interest nets to zero.*

### Parameter space

Joint parameter effects evaluated from the verified expressions over 2-D grids.

![The clamp carves wedge-shaped saturation zones where |accumulated premium / time| exceeds the ±0.75% cap, so short accumulation windows saturate at far smaller premiums; cap held at 0.0075.](/files/ji9aNK1hpC7XtKG2JwFF)

*The clamp carves wedge-shaped saturation zones where |accumulated premium / time| exceeds the ±0.75% cap, so short accumulation windows saturate at far smaller premiums; cap held at 0.0075.*

![The bilinear size × rate interaction produces hyperbolic level sets of equal payment, with the sign flip at rate = 0 splitting payers from receivers; mark price held at 50,000 for a long position.](/files/NAwQ05XWubuRagsGi4Av)

*The bilinear size × rate interaction produces hyperbolic level sets of equal payment, with the sign flip at rate = 0 splitting payers from receivers; mark price held at 50,000 for a long position.*

## References

* Derived from and adversarially verified against the Exchange's Rust implementation and its test suite.
* Sibling model: [insurance-fund](/math-engine/insurance-fund.md)
* Sibling model: [liquidation-engine](/math-engine/liquidation-engine.md)
* Sibling model: [margin-math](/math-engine/margin-math.md)
* Sibling model: [oracle](/math-engine/oracle.md)
* Sibling model: [order-book](/math-engine/order-book.md)
* Sibling model: [position-tracker](/math-engine/position-tracker.md)
* Sibling model: [settlement](/math-engine/settlement.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.nexus.xyz/math-engine/funding-rate.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
