The Funding Rate is comprised of two main parts: the Interest Rate and the Premium / Discount.
Interest Rate Component
Every contract traded on DueDEX consists of two instruments: a Base currency and a Quote currency. For example, on BTCUSD, the Base currency is BTC while the quote currency is USD. The Interest Rate is a function of interest rates between these two currencies:
Interest Rate (I) = (Interest Quote Index - Interest Base Index) / Funding Interval
Interest Base Index = The Interest Rate for borrowing the Base currency
Interest Quote Index = The Interest Rate for borrowing the Quote currency
Funding Interval = 3 (Since funding occurs every 8 hours)
The perpetual swap may trade at a significant premium or discount to the Mark Price. In a bull market, the perpetual contact probably might be traded at a premium to the Mark Price. While in a bear market, the perpetual swap might be traded at a discount to Mark Price. In those situations, a Premium Index will be used to raise or lower the next Funding Rate to levels consistent with where the contract is trading.
Premium Index (P) = (Max(0, Impact Bid Price - Mark Price) - Max(0, Mark Price - Impact Ask Price)) / Spot Price + Fair Basis used in Mark Price
Impact Bid Price = The average fill price to execute the Impact Margin Notional on the Bid side
Impact Ask Price = The average fill price to execute the Impact Margin Notional on the Ask side
The Impact Margin Notional is the notional available to trade with 0.1 BTC worth of margin (i.e. 0.1 BTC / Initial Margin) and is used to determine how deep in the order book to measure either the Impact Bid or Ask Price. For example, the Impact Margin Notional of BTCUSD= 0.1 BTC / 0.01 = 10 BTC