Math deep dive

Position constructing

EVequity value;DVdebt value;PVsum value of assets in liquidity pool ,associated with position;Ccollateral value;lleverage;Scurrent asset price;S0asset price at position opening;rBborrowing rate;rYyield farming rate;Ttime from opening  Bottom indexes correspond to 1st and 2nd subpositionsEV - 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×(l1)×exp{rB1×T365};PV1=C1×l×SS0;FarmingYieldValue1=C1×l×exp{rY×T365};Delta1=EV1S=PV1S=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×(l1)×exp{rB2×T365}×SS0;PV2=C2×l×SS0;FarmingYieldValue2=C2×l×exp{rY×T365};Delta2=EV2S=PV2S=C2×l2S×S0C2×(l1)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)2SS0C2×(l1)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=l2l\frac{C_{1}}{C_{2}} = \frac{l-2}{l}

Generalized equation for delta of position​

Delta=C×l2S0×(S0Sexp{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 1position with borrowed stablecoin;Position 2position with borrowed asset;PV1position 1 value (in stablecoins); DV1position 1 debt value (in stablecoins);PV2position 2 value (in asset quantity); DV2position 2 debt value (in asset quantity);Sspot 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:

DV1PV1=23; (subPOS1 leverage == 3 after rabalance)DV2PV2=23; (subPOS2 leverage == 3 after rabalance)PV22+PV12SDV2=0 (Deltaneutrality condition)ΔPV1+ΔPV2SΔDV1ΔDV2S=0 (We dont 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(13PV1DV1+PV2×SDV2×S)ΔDV1=12(PV13DV1+PV2×SDV2×S)ΔPV2=94S(PV1DV1+59PV2×SDV2×S)ΔDV2=32S(PV1DV1+PV2×S53DV2×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