Perpetual contracts are inspired by traditional futures contracts, but differ in that there is no expiry date and therefore no final settlement or delivery. Funding payments are therefore used to incentivize the price of the perpetual to trade at the price of the underlying.

Funding is calculated like an interest rate, and is determined by a funding rate which is calculated algorithmically based on the price of the underlying and market prices for the perpetual. When the rate is positive, traders who are long will make payments to traders who are short. When the rate is negative, this is reversed and shorts will pay longs. Traders make or receive payments in proportion to the size of their market position. These payments are exchanged solely between traders, and are neither paid nor received by the exchange.

### Funding Interval

Funding payments are exchanged continuously every second. The funding rate is updated every hour, but is represented as an 8-hour rate, indicating the amount of funding accounts may expect to pay/receive over an 8-hour period.

### Funding Payment Calculation

The funding amount paid or received by an account over some period of time of length T is calculated according to the formula:

- F = (-1) * R * (T / 8 hours) * B * X

Where:

- F is the change in account balance over the given period
- R is the funding rate as an 8-hour rate
- B is the position balance of the account (positive or negative)
- X is the on-chain index price

Note that funding payments do not compound.

### Funding Rate Calculation

Rates are represented as 8-hour rates unless stated otherwise.

The main component of the funding rate is the premium. The premium takes into account market activity for the perpetual. It is calculated at the start of every minute based on the current order book and off-chain index price according to the formula:

- Premium = (Max(0, Impact Bid Price - Index Price) - Max(0, Index Price - Impact Ask Price)) / Index Price

Where the impact bid and impact ask prices are defined as:

- Impact Bid Price = Average execution price for a market sell of the impact notional value
- Impact Ask Price = Average execution price for a market buy of the impact notional value

And the impact notional amount is defined as:

- Impact Notional Value = 3000 USDC / Initial Margin Requirement

For example, at a 10% initial margin requirement, the impact notional value is 30,000 USDC.

At the end of each hour, the 1-hour premium is calculated as the simple average (i.e. TWAP) of the 60 premiums calculated over the course of the last hour.

**If the dampening factor for the market is zero, then the funding rate is equal to the 1-hour premium. If the dampening factor is non-zero, then the following additional calculations involving the interest rate component apply.**

The interest rate component aims to account for the interest rate differential between the base and quote currencies, and is set to a fixed rate for each perpetual market:

- Interest Rate Component (BTC-USD and ETH-USD markets) = 0.01%
- Interest Rate Component (LINK-USD market) = 0%

The funding rate is calculated by applying a dampening factor to the 1-hour premium, pushing the rate towards the interest rate component by ±D (a percentage fraction).

- Funding Rate = 1-Hour Premium + clamp(Interest Rate Component - 1-Hour Premium, -D, D)

Where D is the dampening factor for the market and clamp is defined as:

- clamp(x, y, z) = min(max(x, y), z)

### Index Price for Funding

Funding payments occur on-chain, so the calculation of funding payments from the funding rate makes use of an on-chain index price given by a MakerDAO v2 oracle. The funding rate itself is calculated off-chain, and makes use of an off-chain index which is updated more frequently than the on-chain index.

The off-chain index prices are calculated as follows:

- BTC-USD index (median-weighted): Bitstamp, Bittrex, Coinbase Pro, Gemini, Kraken
- ETH-USD index (median-weighted): Binance, Bitstamp, Coinbase Pro, Gemini, Kraken
- LINK-USD index (median-weighted): Binance, Coinbase Pro, Huobi, Kraken, OKEx

### Funding Rate Updates

After the funding rate is calculated by dYdX, it is immediately sent to the funding rate smart contract. The smart contract will apply bounding as described below, and the rate will be rounded, toward zero, to the nearest value representable on the smart contract. Once the Ethereum transaction is mined, the new funding rate takes effect and is used to update account balances every second.

### Funding Rate Bounding

The minimum funding rate is -0.75% and the maximum funding rate is 0.75%. For decentralization purposes, there is a limit to how quickly the admin can change the funding rate, but this does not take effect during normal operation.