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:
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.
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
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.
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.
In the next step the values of each tenor-specific TWN are added
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
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.
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.
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