Skip to main content

Math

This section will help you better understand the math behind the protocol. By exploring the calculations and concepts involved, you'll gain valuable insights into how the system operates and how to make informed trading/liquidity providing decisions.

Calculating Position Value​

Formula:

positionValuelong=collateral+(closePriceentryPrice−1)∗positionSize−hoursPassed∗borrowRate∗positionSizepositionValueshort=collateral+(1−closePriceentryPrice)∗positionSize−hoursPassed∗borrowRate∗positionSizepositionValue_{long} = collateral + \left(\frac{closePrice}{entryPrice} - 1\right) * positionSize - hoursPassed * borrowRate * positionSize\\ positionValue_{short} = collateral + \left(1 - \frac{closePrice}{entryPrice}\right) * positionSize - hoursPassed * borrowRate * positionSize\\

Example:

collateral=10leverage=5positionSize=10∗5=50entryPrice=100closePrice=110hoursPassed=20borrowRate=0.00005collateral = 10\\ leverage = 5\\ positionSize = 10 * 5 = 50\\ entryPrice = 100\\ closePrice = 110\\ hoursPassed = 20\\ borrowRate = 0.00005\\

positionValuelong=10+(110100−1)∗50−20∗0.00005∗50positionValuelong=10+(1.1−1)∗50−20∗0.0025positionValuelong=10+0.1∗50−0.05positionValuelong=10+5−0.05positionValuelong=14.95positionValue_{long} = 10 + \left(\frac{110}{100} - 1\right) * 50 - 20 * 0.00005 * 50\\ positionValue_{long} = 10 + (1.1 - 1) * 50 - 20 * 0.0025\\ positionValue_{long} = 10 + 0.1 * 50 - 0.05\\ positionValue_{long} = 10 + 5 - 0.05\\ positionValue_{long} = 14.95\\

positionValueshort=10+(1−110100)∗50−20∗0.00005∗50positionValueshort=10+(1−1.1)∗50−20∗0.0025positionValueshort=10+(−0.1)∗50−0.05positionValueshort=10−0.5∗50−0.05positionValueshort=4.95positionValue_{short} = 10 + \left(1 - \frac{110}{100}\right) * 50 - 20 * 0.00005 * 50\\ positionValue_{short} = 10 + (1 - 1.1) * 50 - 20 * 0.0025\\ positionValue_{short} = 10 + (-0.1) * 50 - 0.05\\ positionValue_{short} = 10 - 0.5 * 50 - 0.05\\ positionValue_{short} = 4.95\\

Calculating Entry/Close Price​

Formula:

entryPricelong=marketPrice∗(1+openFee)entryPriceshort=marketPrice∗(1−openFee)closePricelong=marketPrice∗(1−closeFee)closePriceshort=marketPrice∗(1+closeFee)entryPrice_{long} = marketPrice * (1 + openFee)\\ entryPrice_{short} = marketPrice * (1 - openFee)\\ closePrice_{long} = marketPrice * (1 - closeFee)\\ closePrice_{short} = marketPrice * (1 + closeFee)\\

Example:

marketPrice=100openFee=0.005marketPrice = 100\\ openFee = 0.005\\

entryPricelong=100∗(1+0.005)entryPricelong=100∗1.005entryPricelong=100.5closePricelong=100∗(1−0.005)closePricelong=100∗(0.995)closePricelong=99.5entryPrice_{long} = 100 * (1 + 0.005)\\ entryPrice_{long} = 100 * 1.005\\ entryPrice_{long} = 100.5\\ closePrice_{long} = 100 * (1 - 0.005)\\ closePrice_{long} = 100 * (0.995)\\ closePrice_{long} = 99.5\\

Calculating Position Size​

Formula:

positionSize=collateral∗leveragepositionSize = collateral * leverage\\

Example:

collateral=10leverage=5collateral = 10\\ leverage = 5\\

positionSize=10∗5positionSize=50positionSize = 10 * 5\\ positionSize = 50\\

Calculating Liquidation Price​

Formula:

liquidationPricelong=entryPrice−entryPriceleverage∗valuecollateralliquidationPriceshort=entryPrice+entryPriceleverage∗valuecollateralliquidationPrice_{long} = entryPrice - \frac{entryPrice}{leverage} * \frac{value}{collateral}\\ liquidationPrice_{short} = entryPrice + \frac{entryPrice}{leverage} * \frac{value}{collateral}\\

Example:

entryPrice=100leverage=5value=5collateral=10entryPrice = 100\\ leverage = 5\\ value = 5\\ collateral = 10\\

liquidationPricelong=100−1005∗510liquidationPricelong=100−20∗0.5liquidationPricelong=90liquidationPriceshort=100+1005∗510liquidationPriceshort=100+20∗0.5liquidationPriceshort=110liquidationPrice_{long} = 100 - \frac{100}{5} * \frac{5}{10}\\ liquidationPrice_{long} = 100 - 20 * 0.5\\ liquidationPrice_{long} = 90\\ liquidationPrice_{short} = 100 + \frac{100}{5} * \frac{5}{10}\\ liquidationPrice_{short} = 100 + 20 * 0.5\\ liquidationPrice_{short} = 110\\

Calculating Profit and Loss​

Formula:

pnl=value−collateralpnl = value - collateral\\

Example:

value=15collateral=10value = 15\\ collateral = 10\\

pnl=15−10pnl=5pnl = 15 - 10\\ pnl = 5\\

value=5collateral=10value = 5\\ collateral = 10\\

pnl=5−10pnl=−5pnl = 5 - 10\\ pnl = -5\\

Calculating Available Liquidity​

Formula:

availableLiquidityshort=openInteresttotal2−openInterestshortavailableLiquiditylong=openInteresttotal2−openInterestlongavailableLiquidity_{short} = \frac{openInterest_{total}}{2} - openInterest_{short}\\ availableLiquidity_{long} = \frac{openInterest_{total}}{2} - openInterest_{long}\\

Example:

openInteresttotal=1000openInterestlong=300openInterest_{total} = 1000\\ openInterest_{long} = 300\\

availableLiquiditylong=10002−300availableLiquiditylong=500−300availableLiquiditylong=200availableLiquidity_{long} = \frac{1000}{2} - 300\\ availableLiquidity_{long} = 500 - 300\\ availableLiquidity_{long} = 200\\

Calculating Hourly Borrow Cost​

Formula:

hourlyBorrowCost=borrowRate∗positionSizehourlyBorrowCost = borrowRate * positionSize\\

Example:

collateral=10leverage=5positionSize=10∗5=50borrowRate=0.00005collateral = 10\\ leverage = 5\\ positionSize = 10 * 5 = 50\\ borrowRate = 0.00005\\

hourlyBorrowCost=0.00005∗50=0.0025hourlyBorrowCost = 0.00005 * 50 = 0.0025\\

Calculating LP Token Price​

Formula:

LPTokenPrice=liquidityLPTokenAmountLPTokenPrice = \frac{liquidity}{LPTokenAmount}\\

Example:

liquidity=1000LPTokenAmount=100liquidity = 1000\\ LPTokenAmount = 100\\

LPTokenPrice=1000100LPTokenPrice=10LPTokenPrice = \frac{1000}{100}\\ LPTokenPrice = 10\\