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 |
---|
| PC,Lā=(1+rB,bā)TSSāā+D(1ā(1+rQ,lā)T1ā) |
| PC,Sā=(1+rB,lā)TSLāā+L(1ā(1+rQ,bā)T1ā) |
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):
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.
Short
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ā)T1āETHto close the debt, i.e. 0.9929ETH.
2. Hence the protocol needs (1+rB,lā)TSLāāDAIto close the debt, i.e. 99.39DAI.
3. On the other hand, the protocol gets back (1+rQ,bā)TLāDAIfrom lending, i.e. 149.07DAI.
4. The money lost in lending for closing the position earlier is Lā(1+rQ,bā)TLāDAIor 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.