# Funding Calculation

### Funding Fee:

$F=-1*R*\frac{T}{8 \ hours} * B*X$
• R: 8-hour rate
• B: Net position (+, -)
• X: On-chain price;
• T: Interval time between funding fees (8 hours)
The funding rate is updated every minute and paid on an 8-hour basis.

### Funding Rate (R) Calculation:

$r = Premium + clamp(IR-Premium, -D, D)$
$R=clamp(r, -0.75*M_{i}, 0.75*M_{i})$
where:
• $Clamp$
: Clamp(x, min, max) represents when X<min, then X=min; if x>max, then X=max; If
$max\ge a \ge min$
,then return X.
• $D$
: A dampening factor, D=0.05%
• $IR$
: Interest Rate = 0.01%
• $M_{i}$
: maintenance margin rate
• $Premium$
We need to calculate the premium first to get the funding rate R. The premium rate is calculated every minute based on the current distribution of price in the order book:
$Premium(mins)=\frac{(Max(0, \ Impact\ Bid\ Price – Index \ Price) - Max(0, Index\ Price - Impact\ Ask\ Price)) }{Index\ Price}$
At the end of every 8-hour period, we first calculate the premium of each minute(Premium(mins)), and then take the arithmetic mean of the sum of Premium(mins) to get the 8-hour premium(Premium(hours)).
$Premium(hours) = mean(\sum premium(mins))$
where:
• Index Price: Off-chain price, the average of the index prices of major exchanges
• Impact Bid Price: Calculated based on Impact notional value (INV) of the bid-side order book
• Impact Ask Price: Calculated based on the Impact notional value (INV) and the ask-side order book
• Impact Notional Value(INV): A system default effective impact amount. Different trading pairs may have different INV. Current INV is
$\frac{3000}{Maintence \ Margin\ Rate}$

Level
Price
Quantity
Notional Quantity
Accumulated Notional Quantity
1
$p_{1}$
$q_{1}$
$p_{1}*q_{1}$
$p_{1}*q_{1}$
2
$p_{2}$
$q_{2}$
$p_{2}*q_{2}$
$p_{1}*q_{1}+p_{2}*q_{2}$
3
$p_{3}$
$q_{3}$
$p_{3}*q_{3}$
$p_{1}*q_{1}+p_{2}*q_{2}+p_{3}*q_{3}$
...
...
...
...
...
n
$p_{n}$
$q_{n}$
$p_{n}*q_{n}$
$\sum p_{n}*q_{n}$
Find the first X level such that
$\sum_{i=1}^{X} p_{i}*q_{i}
, e.g. If the first level satisfied the condition, then the Impact Ask Price =
$P_{1}$
.
$\frac{INV}{\sum_{i=1}^{X}q_{i}+\frac{INV-\sum_{i=1}^{X} p_{i}*q_{i}}{P_{x+1}} }$