# Funding Rates

Perpetual futures contracts employ a funding rate mechanism to ensure the *mark price* stays close to the *index price*. Please see [quoted-index-and-mark-prices](https://docs.variational.io/omni/trading/quoted-index-and-mark-prices "mention") for an overview of the different prices. In summary, the index price is computed by aggregating the spot prices across different exchanges. The mark price is the fair value of the perpetual futures contract and is not used in the computations to derive the funding rate.

A positive funding rate means longs pay shorts; a negative funding rate means shorts pay longs.

The funding window is variable, and it may be from 1h to 8h. Please see [#calculation-window](#calculation-window "mention") for details.

### Formulas

`Funding Rate (F) = Average Premium Index (P) + clamp (interest rate - Average Premium Index (P), -0.0005, 0.0005)`&#x20;

The premium is computed every 60s and then averaged over the calculation window using the weighting scheme described below.

`premium = impact_price_difference / index_price`

`impact_price_difference = max(impact_bid_px - index_price, 0) - max(index_price - impact_ask_px, 0)`

The `impact_bid_px` is the bid price returned for a RFQ of size defined by [#impact-margin-notional](#impact-margin-notional "mention").

The `impact_ask_px` is the ask price obtained for a RFQ of size defined by [#impact-margin-notional](#impact-margin-notional "mention").&#x20;

The `interest rate` is fixed at 0.00125% / hour, and the funding rate is capped at 2% per hour, except in certain special circumstances where a manual override is necessary.&#x20;

### Weighting scheme

We sample the premium `P` every 60s, leading to samples `P_1, P_2, ... P_i, ...P_N`. Then each sample `P_i` has weight $$\frac{2i}{N(N+1)}$$

### Calculation window

The calculation window is designed to match centralized exchanges, the waterfall works as follows:

1. If the market exists on Bybit, the calculation window will match Bybit's.&#x20;
2. Else if the market exists on Binance, the calculation window will match Binance's.&#x20;
3. Else the calculation window is 1 hour.

Example:

BTC perp market exists on Bybit and has a 8 hour calculation window. This means in hours 1-7, the hourly funding rate will be 0. In hour 8, the funding rate will be computed off the previous 8 hours of data.

### Impact margin notional&#x20;

The impact margin notional is generally $7500, except in special circumstances where it is manually configured. Furthermore, the impact prices only include the base spread, subtracting out any spreads included for hedging costs.&#x20;

`total_spread = base_spread + hedging_costs`&#x20;

### Numerical example

Let's take

```
index_price = $10,000
impact_bid_px = $10,100
impact_ask_px = $10,200
```

Step 1: compute the `impact_price_difference`

```
impact_price_difference = max($10,100 - $10,000, 0) - max($10,000 - $10,200, 0)
                        = max($100, 0) - max(-$200, 0)
                        = $100 - $0
                        = $100
```

Step 2: compute the `premium`

```
premium = $100 / $10,000
        = 0.01
```

Step 3: compute the funding rate

```
Funding Rate (F) = 0.01 + clamp(0.00001 - 0.01, -0.0005, 0.0005)
                 = 0.01 + clamp(-0.00999, -0.0005, 0.0005)
                 = 0.01 - 0.0005
                 = 0.0095
```
