Math behind the demand spread

Demand-driven component to spread as input takes several variables:

  • Liquidity depth in the liquidity pools

  • amount of collateral deposited by the swap takers

  • amount of notional exposure on each leg (pay-fixed or receive-fixed)

As well as configuration params from the risk oracle:

  • Max Collateral Factor

  • Max Leverage

The demand part is calculated in a couple of steps:

  1. first, the depth of the pools is assessed by adding the liquidity available in the pools and the absolute value of the difference between collateral on both legs.

lpDepth=LPCollateralCollateralpayFixCollaterealrecFixlpDepth = LPCollateral - |Collateral_{payFix} - Collatereal_{recFix}|
  1. Next, with help from the risk oracle the notional depth can be calculated. It is necessary later on to compile. MaxLeverage and MaxLPCollateralFactorPerLeg are fetched from the risk oracle

notionalDepth=lpDepthMaxLeverageMaxLPCollateralFactorPerLegnotionalDepth = lpDepth \cdot MaxLeverage \cdot MaxLPCollateralFactorPerLeg
  1. As the swaps get open their notional value is added and forms Time Weighted Notional (TWN) per leg. This value is kept separately per each asset and tenor.

TWNt,tenor,leg=TWNt,tenor,leg+NswapTWN_{t,tenor,leg} = TWN_{t, tenor,leg} + N_{swap}
  1. As the time passes the effect of a swap on the TWN is decaying to 0 at maturity. This value is calculated on the fly and used to measure the dynamic exposure of the pool to a given leg.

TWNt,tenor,leg=TWNt1,tenor,leg(tenor[s]ΔT)tenor[s]TWN_{t, tenor,leg} = \frac{TWN_{t-1, tenor, leg} \cdot (tenor[s] - \Delta T)}{tenor[s]}
  1. In the next step the values of each tenor-specific TWN are added

TWNt,leg=tenorTWNt,legTWN_{t, leg} = \sum_{tenor}TWN_{t,leg}
  1. Next it has to be determined, which leg is overweight and which one is underweight. This can be done by subtracting the TWN on each leg

overweightpayFixed=TWNpayFixedTWNreceiveFixedoverweight_{payFixed} = TWN_{payFixed} - TWN_{receiveFixed}
overweightreceiveFixed=TWNreceiveFixedTWNpayFixedoverweight_{receiveFixed} = TWN_{receiveFixed} - TWN_{payFixed}
  1. Once it can be determined which leg is overweight, the spread can be applied to IT depending on the size of the difference. Formula for both legs is identical.

ratiopayFixed={overweightpayFixednotionalDepthoverweightpayFixed>00overweightpayFixced0ratio_{payFixed} = \begin{cases} \frac{overweight_{payFixed}}{notionalDepth} & overweight_payFixed > 0 \\ 0 & overweight_{payFixced} \le 0 \end{cases}
  1. Finaly the demand spread can be calculated with help of simple step function. Linear step function presented below is subject to configuration and the final values of slope and base are to be set by the DAO.

demandSpreadleg={0.005ratioratio<0.10.01ratio+0.005ratio<0.20.015ratio+0.005ratio<0.30.02ratio+0.015ratio<0.40.05ratio+0.03ratio<0.50.33(3)ratio+0.15ratio<0.80.5ratio+0.2ratio<1demandSpread_{leg} = \begin{cases} 0.005 \cdot ratio & ratio < 0.1 \\ 0.01 \cdot ratio + 0.005 & ratio < 0.2 \\ 0.015 \cdot ratio + 0.005 & ratio < 0.3 \\ 0.02 \cdot ratio + 0.015 & ratio < 0.4 \\ 0.05 \cdot ratio + 0.03 & ratio < 0.5 \\ 0.33(3) \cdot ratio + 0.15 & ratio < 0.8 \\ 0.5 \cdot ratio + 0.2 & ratio < 1 \\ \end{cases}
  1. Now that the demand spread for leg is calculated same operations is repeated only this time notional of the new position that is to be opened is added to the "overweight" value. Afterwards simple average is calculated and final spread is returned. The last step is necessary in order to account for the slippage caused by the position and it removes the incentive of splitting position into multiple smaller swaps to potentially get a better rate

Last updated