# Funding Rates

Funding rates act as a final controller to ensure our final objective

## Residual risk

While the AMM addresses the marginal risk from the change in inventory using premium and rebate, there remain some residual risks, one of which is caused by the change in the price process of the underlying asset. To cover for such risk, we charge funding periodically.
Given
$X_t$
is a function of an
$n$
dimensional vector
$\mathbf{q}$
, we need a way to define funding rate for each market such that the total funding accumulated across
$n$
$\rho(X_{t+\tau})-(P+L)$
. To achieve this, we use a risk attribution mechanism called Euler allocation.
Let
$X_{t,i}$
be the liability arising from
$i$
th market. Using Euler allocation, we calculate the amount of funding needed from
$i$
th market as
$\rho_{Euler}(X_{t+\tau,i}|X_{t+\tau})$
$j \in I_i$
with position size
$q_{i_j} \in \mathbb{R}$
where
$\sum_{j\in I_i}q_{i_j}=q_{i}$
, they are responsible for covering
$\rho_{Euler}(X_{t+\tau,i}|X_{t+\tau})\frac{q_{i_j}}{q_{i}}$
For example, if the market is long-heavy (
$q_{i} > 0$
$(q_{i_j}>0)$
$(q_{i_j}< 0)$
$F=\sum_{i=1}^n\sum_{j\in I_i}\rho_{Euler}(X_{t+\tau,i}|X_{t+\tau})\frac{q_{i_j}}{q_{i}}=\rho(X_{t+\tau})-(P+L)$
$X_{t+\tau}\leq P+L+F$