# Funding payments

The funding rate for a given period is calculated as the percentage deviation of the index price TWAP and the market price TWAP (also known as the Mark Price). Funding rates are calculated for every block with at least one trade over 24h. This means that a 1% deviation of the mark price from the index price will lead to a funding rate of 1% over 1 day.

$$
{premium} = \frac{TWAP_{market} - TWAP_{index}}{TWAP_{index}}
$$

$$
{fundingRate} = \frac{sensitivity * premium * timeElapsed}{24 h}
$$

If the funding rate is positive, it means that the mark price is higher than the index price, so longs pay shorts. Conversely, a negative funding rate indicates that mark prices are trading below index price, so shorts pay longs. With `sensitivity`, we can control how strongly the funding rate reacts to price deviations.

The funding payment is derived from the funding rate. To encourage the price of the perpetual to trade close to the price of the underlying, funding payments are exchanged between long and short traders.

Unlike traditional 8-hour periods of funding payement settlement, the computed funding payment on Increment is added to any incurred PnL whenever there is a transaction in the system that changes trader positions, adds liquidity, or removes liquidity, but is not settled until the position is closed.

$$
fundingPayment = fundingRate * position * indexPrice
$$
