# Market depth

This estimation determines how much mrgnlend liquidators could offlay based on available liquidity. Today, only Solana liquidity is considered. In the future, additional defi and cefi ecosystems will be included. Price impact bands are calculated based on a series of smoothing functions, focused on being conservative when liquidity estimates are trending upwards and quickly responsive when liquidity estimates are trending down. This calculation is done per asset.

A few steps are involved:

Overall, risk engines primarily rely on

**90-day**historical data, leveraging https://www.fibonacci.fi and https://www.birdeye.so.A profitable sliippage threshold

$h$

is set based on the liquidator fee mrgnlend awards liquidators for their service, $f$

. Today, $f$

is fixed at 2.5%, but will likely be dynamic in the future to further improve liquidator incentives.

$h_{t} = I(s,f)$

where:

$s:$

the amount of liquidity bought or sold

$f:$

slippage from the sale or purchaseA number of moving averages are calculated over a spectrum of time windows. Every combination of the following is calculated:

- Simple moving average (SMA)
- Exponential moving average (EMA)
- Triangular moving average (TMA)

- 1D
- 7D
- 14D
- 28D

The minimum of the above averages is taken for a conservative perspective over each time window. This allows smooth- ing algorithms to mitigate noise in the data but continue to be sensitive to lower thresholds of liquidator capacity further in the past (e.g. SMA), during intermediary points of history (e.g. TMA), and more recently (e.g. EMA):

$\text{MA}_1(k) = \min(\text{SMA}_{\text{28d}}(k), \text{EMA}_{\text{28d}}(k), \text{TMA}_{\text{28d}}(k)),$

$k = \{h_t, \ldots, h_{t-w}\}$

where

$w$

is the full rolling window used.The data is smoothed again, and mean and median are calculated over an additional array of rolling time windows:

- 6H
- 12H
- 1D
- 2D

Both the rolling mean and median are then discounted by a factor based on the variability of the data, as a further conservative measure. The discount factor is based off of the coefficient of variation and can be expressed as the following:

$df_{\text{28d}} = 1 - 0.05 \times \left(\frac{\text{CV} - \min(\text{CV})}{\max(\text{CV}) - \min(\text{CV})}\right),$

$\text{CV} = \frac{\sigma_{28d, t}}{\text{SMA}_{28d}(k)}, \text{ } \sigma_{28d, t} = \sqrt{\frac{1}{28}\sum_{i=t-27}^{t}(x_i - \mu_{28d, t})^2}\\$

The discount factor adjusts the values in the dataset based on their relative variability. Smaller values of the discount factor indicate higher variability and lower significance, while larger values indicate lower variability and higher significance.

The minimum of the mean and median is taken, then discounted.

$\text{MA}_3(m) = min(\text{MA}_2(m)) \cdot df_{\text{28d}}$

This discounted minimum is then rounded to the nearest

$r$

USD-valued range so as to translate the data into actionable risk parameters that can be factored into on-chain protocol updates that should happen relatively infrequently. Finally,

$\text{L} = r \cdot \lfloor \frac{\text{MA}_3(m)}{r} + 0.5 \rfloor$

The

*mode*of$L$

is taken of the last $n$

days to arrive at a more stable persepctive on profitability threshold. Currently, $n$

is 3 days.Last modified 7mo ago