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+(closePriceentryPrice1)positionSizehoursPassedborrowRatepositionSizepositionValueshort=collateral+(1closePriceentryPrice)positionSizehoursPassedborrowRatepositionSizepositionValue_{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=105=50entryPrice=100closePrice=110hoursPassed=20borrowRate=0.00005collateral = 10\\ leverage = 5\\ positionSize = 10 * 5 = 50\\ entryPrice = 100\\ closePrice = 110\\ hoursPassed = 20\\ borrowRate = 0.00005\\

positionValuelong=10+(1101001)50200.0000550positionValuelong=10+(1.11)50200.0025positionValuelong=10+0.1500.05positionValuelong=10+50.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+(1110100)50200.0000550positionValueshort=10+(11.1)50200.0025positionValueshort=10+(0.1)500.05positionValueshort=100.5500.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(1openFee)closePricelong=marketPrice(1closeFee)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=1001.005entryPricelong=100.5closePricelong=100(10.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=collateralleveragepositionSize = collateral * leverage\\

Example:

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

positionSize=105positionSize=50positionSize = 10 * 5\\ positionSize = 50\\

Calculating Liquidation Price

Formula:

liquidationPricelong=entryPriceentryPriceleveragevaluecollateralliquidationPriceshort=entryPrice+entryPriceleveragevaluecollateralliquidationPrice_{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=1001005510liquidationPricelong=100200.5liquidationPricelong=90liquidationPriceshort=100+1005510liquidationPriceshort=100+200.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=valuecollateralpnl = value - collateral\\

Example:

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

pnl=1510pnl=5pnl = 15 - 10\\ pnl = 5\\

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

pnl=510pnl=5pnl = 5 - 10\\ pnl = -5\\

Calculating Available Liquidity

Formula:

availableLiquidityshort=openInteresttotal2openInterestshortavailableLiquiditylong=openInteresttotal2openInterestlongavailableLiquidity_{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=10002300availableLiquiditylong=500300availableLiquiditylong=200availableLiquidity_{long} = \frac{1000}{2} - 300\\ availableLiquidity_{long} = 500 - 300\\ availableLiquidity_{long} = 200\\

Calculating Hourly Borrow Cost

Formula:

hourlyBorrowCost=borrowRatepositionSizehourlyBorrowCost = borrowRate * positionSize\\

Example:

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

hourlyBorrowCost=0.0000550=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\\