Math deep dive

Position constructing

EVβˆ’equityΒ value;DVβˆ’debtΒ value;PVβˆ’sumΒ valueΒ ofΒ assetsΒ inΒ liquidityΒ poolΒ ,associatedΒ withΒ position;Cβˆ’collateralΒ value;lβˆ’leverage;Sβˆ’currentΒ assetΒ price;S0βˆ’assetΒ priceΒ atΒ positionΒ opening;rBβˆ’borrowingΒ rate;rYβˆ’yieldΒ farmingΒ rate;Tβˆ’timeΒ fromΒ openingβ€…β€ŠBottomΒ indexesΒ correspondΒ toΒ 1β€²stΒ andΒ 2β€²ndΒ subβˆ’positionsEV - equity\ value;\\ DV - debt\ value;\\ PV - sum\ value\ of\ assets\ in\ liquidity\ pool\ , associated\ with\ position;\\ C - collateral\ value;\\ l - leverage; \\ S - current\ asset\ price; S_{0} - asset\ price\ at\ position\ opening;\\ r_{B} - borrowing\ rate; r_{Y} - yield\ farming\ rate;\\ T - time\ from\ opening\; \\ \\ Bottom\ indexes\ correspond\ to\ 1'st\ and\ 2'nd\ sub-positions

1'st subPosition (borrowing notional)

DV1=C1Γ—(lβˆ’1)Γ—exp{rB1Γ—T365};PV1=C1Γ—lΓ—SS0;FarmingYieldValue1=C1Γ—lΓ—exp{rYβ€ΎΓ—T365};Delta1=βˆ‚EV1βˆ‚S=βˆ‚PV1βˆ‚S=C1Γ—lΓ—12SΓ—S0DV_{1}=C_{1}\times(l-1)\times exp\{\frac{r_{B1}\times T}{365}\};\\ PV_{1} = C_{1} \times l \times \sqrt{\frac{S}{S_{0}}};\\ Farming Yield Value_{1} = C_{1} \times l \times exp\{\frac{\overline{r_{Y}}\times T}{365}\};\\ Delta_{1} = \frac{\partial{EV_{1}}}{\partial{S}} = \frac{\partial{PV_{1}}}{\partial{S}} = C_{1} \times l \times \frac{1}{2\sqrt{S\times S_{0}}}

2'nd subPosition (borrowing asset)

DV2=C2Γ—(lβˆ’1)Γ—exp{rB2Γ—T365}Γ—SS0;PV2=C2Γ—lΓ—SS0;FarmingYieldValue2=C2Γ—lΓ—exp{rYβ€ΎΓ—T365};Delta2=βˆ‚EV2βˆ‚S=βˆ‚PV2βˆ‚S=C2Γ—l2SΓ—S0βˆ’C2Γ—(lβˆ’1)S0Γ—exp{rB2Γ—T365};DV_{2}=C_{2}\times(l-1)\times exp\{\frac{r_{B2}\times T}{365}\} \times \frac{S}{S_{0}};\\ PV_{2} = C_{2} \times l \times \sqrt{\frac{S}{S_{0}}};\\ Farming Yield Value_{2} = C_{2} \times l \times exp\{\frac{\overline{r_{Y}}\times T}{365}\};\\ Delta_{2} = \frac{\partial{EV_{2}}}{\partial{S}} = \frac{\partial{PV_{2}}}{\partial{S}} = \frac{C_{2} \times l} {2\sqrt{S\times S_{0}}} - \frac{C_{2}\times (l-1)}{S_{0}}\times exp\{\frac{r_{B2}\times T}{365}\};

Delta-neutrality condition

Delta=Delta1+Delta2;Delta=lΓ—(C1+C2)2SS0βˆ’C2Γ—(lβˆ’1)S0Γ—exp{rB2Γ—T365};Delta = Delta_{1} + Delta_{2};\\ Delta = \frac{l \times (C_{1}+C_{2})}{2\sqrt{S S_{0}}} - \frac{C_{2}\times (l-1)}{S_{0}}\times exp\{\frac{r_{B2}\times T}{365}\};

Taken Delta = 0 at opening (T=0):

that's why we put N/4 in first subPosition and 3N/4 in second.

C1C2=lβˆ’2l\frac{C_{1}}{C_{2}} = \frac{l-2}{l}

Generalized equation for delta of position​

Delta=CΓ—l2S0Γ—(S0Sβˆ’exp{rB2Γ—T365})Delta = \frac{C \times l}{2S_{0}}\times(\sqrt{\frac{S_{0}}{S}} - exp\{\frac{r_{B2}\times T}{365}\})

Rebalancing

Definitions in terms of typical LYF-protocol interface (Tulip, Francium, Alpaca, Tarot)

PositionΒ 1βˆ’positionΒ withΒ borrowedΒ stablecoin;PositionΒ 2βˆ’positionΒ withΒ borrowedΒ asset;PV1βˆ’positionΒ 1Β valueΒ (inΒ stablecoins);Β DV1βˆ’positionΒ 1Β debtΒ valueΒ (inΒ stablecoins);PV2βˆ’positionΒ 2Β valueΒ (inΒ assetΒ quantity);Β DV2βˆ’positionΒ 2Β debtΒ valueΒ (inΒ assetΒ quantity);Sβˆ’spotΒ price;Position\ 1 - position\ with\ borrowed\ stablecoin;\\ Position\ 2 - position\ with\ borrowed\ asset;\\ PV_{1} - position\ 1\ value\ (in\ stablecoins);\ DV_{1} - position\ 1\ debt\ value\ (in\ stablecoins);\\ PV_{2} - position\ 2\ value\ (in\ asset\ quantity);\ DV_{2} - position\ 2\ debt\ value\ (in\ asset\ quantity);\\ S - spot\ price;

​

Positions' and debts' values after rebalancing:

PV1βˆ—=PV1+Ξ”PV1;Β DV1βˆ—=DV1+Ξ”DV1;PV2βˆ—=PV2+Ξ”PV2;Β DV2βˆ—=DV2+Ξ”DV2; PV_{1}^{*} = PV_{1} +\Delta PV_{1};\ DV_{1}^{*} = DV_{1} + \Delta DV_{1};\\ PV_{2}^{*} = PV_{2} +\Delta PV_{2};\ DV_{2}^{*} = DV_{2} + \Delta DV_{2};\\

How to calculate those value changes:

DV1βˆ—PV1βˆ—=23;Β (subPOS1Β leverageΒ ==Β 3Β afterΒ rabalance)DV2βˆ—PV2βˆ—=23;Β (subPOS2Β leverageΒ ==Β 3Β afterΒ rabalance)PV2βˆ—2+PV1βˆ—2Sβˆ’DV2βˆ—=0Β (Deltaβˆ’neutralityΒ condition)Ξ”PV1+Ξ”PV2βˆ—Sβˆ’Ξ”DV1βˆ’Ξ”DV2βˆ—S=0Β (WeΒ donβ€²tΒ addΒ cashΒ fromΒ outside) \frac{DV_{1}^{*}}{PV_{1}^{*}} = \frac{2}{3};\ (subPOS1\ leverage\ ==\ 3\ after\ rabalance)\\ \frac{DV_{2}^{*}}{PV_{2}^{*}} = \frac{2}{3};\ (subPOS2\ leverage\ ==\ 3\ after\ rabalance)\\ \frac{PV_{2}^{*}}{2} + \frac{PV_{1}^{*}}{2S} - DV_{2}^{*} = 0\ (Delta-neutrality\ condition)\\ \Delta PV_{1} + \Delta PV_{2}*S - \Delta DV_{1} - \Delta DV_{2}*S =0 \ (We\ don't\ add\ cash\ from\ outside)\\

The result

Ξ”PV1=34(βˆ’13PV1βˆ’DV1+PV2Γ—Sβˆ’DV2Γ—S)Ξ”DV1=12(PV1βˆ’3DV1+PV2Γ—Sβˆ’DV2Γ—S)Ξ”PV2=94S(PV1βˆ’DV1+59PV2Γ—Sβˆ’DV2Γ—S)Ξ”DV2=32S(PV1βˆ’DV1+PV2Γ—Sβˆ’53DV2Γ—S)\Delta PV_{1} = \frac{3}{4}(-\frac{1}{3}PV_{1}-DV_{1}+PV_{2}\times S - DV_{2}\times S)\\ \Delta DV_{1} = \frac{1}{2}(PV_{1} - 3DV_{1} + PV_{2}\times S - DV_{2}\times S)\\ \Delta PV_{2} = \frac{9}{4S}(PV_{1} - DV_{1} + \frac{5}{9}PV_{2}\times S - DV_{2}\times S)\\ \Delta DV_{2} = \frac{3}{2S}(PV_{1} - DV_{1} + PV_{2}\times S - \frac{5}{3}DV_{2}\times S)\\

This cash flows totally define the algorythm of rebalancing in general. It can be implemented in any LYF protocol after fitting to protocol's interface.

Here is the backtesting result of sample strategy, using Francium's SOL-USD pool characteristics with 3'rd leverage:

Last updated