Once a position is open, a trader could choose to close it before expiry. If that's the case, the protocol needs to exit the lending position, which at expiry would have represented an amount L(principal + interest), and repay the owed debt, which at expiry would have represented an amount D(principal + interest).
Pricing
The table below presents the price at which a trader could close a long position at a price PC,L or a short position at a price PC,S(other notations have been introduced in theoretical pricing).
Side
Price to close a position
Example
Let's consider the close of the long and short positions presented in the numerical example in position opening:
A trader wants to immediately close the long position with an open price PO,L=100.59DAI. Given one could borrow ETH at a yearly fixed rate of rB,b=3.10% and lend DAI at a yearly fixed rate rQ,l=9.90%, and given the total debt to reimburse at expiry is D=50.59DAI, the price at which a trader could immediately close the position is:
PC,L=(1+0.0310)0.2599.90+50.59∗(1−(1+0.0990)0.251)=100.32DAI
A trader wants to immediately close the short position with an entry price PO,S=102.70DAI. Given one could lend ETH at a yearly fixed rate of rB,l=2.90% and borrow DAI at a yearly fixed rate rQ,b=10.10%, and given the total money to get back from lending (principal + interest) is L=152.70DAI, the price at which a trader could immediately close the position is:
PC,S=(1+0.0290)0.25100.10+152.70∗(1−(1+0.1010)0.251)=103.02DAI
Demonstration
Long
Let's consider a trader who wants to immediately close a long position of 1ETH (numerical applications rely on the above example):
Short
1. The protocol gets back the base currency which was lent, (1+rB,b)T1, i.e. 0.9924ETH.
2. This base currency is swapped back to the quote currency, (1+rB,b)TSS, i.e. 99.14DAI.
3. The protocol buys back the debt D, today worth (1+rQ,l)TD, i.e. 49.41DAI.
4. For closing the position earlier, the trader will get back money on the debt, D−(1+rQ,l)TD or D(1−(1+rQ,l)T1), i.e. 1.18DAI.
5. Hence the money the trader gets back for closing the long position is (1+rB,b)TSS+D(1−(1+rQ,l)T1), i.e 100.32DAI.
Let's consider a trader who wants to immediately close a short position of 1ETH (numerical applications rely on the above example):
1. The protocol needs (1+rB,l)T1ETHto close the debt, i.e. 0.9929ETH.
2. Hence the protocol needs (1+rB,l)TSLDAIto close the debt, i.e. 99.39DAI.
3. On the other hand, the protocol gets back (1+rQ,b)TLDAIfrom lending, i.e. 149.07DAI.
4. The money lost in lending for closing the position earlier is L−(1+rQ,b)TLDAIor L(1−(1+rQ,b)T1)DAI, i.e. 3.63DAI.
5. Hence the money the trader gets back for closing the short position is (1+rB,l)TSL+L(1−(1+rQ,b)T1), i.e. 103.02DAI.
🤓
PC,L=(1+rB,b)TSS+D(1−(1+rQ,l)T1) PC,S=(1+rB,l)TSL+L(1−(1+rQ,b)T1)