Deri Protocol Docs
HomeMiningFuturesOptions
  • Genesis
    • Getting Started
  • 📈Trading [Guide]
    • Deri Lite
      • Perpetual Futures
      • Everlasting Options
      • Power Perpetuals
    • Deri Pro
      • Perpetual Futures
      • Everlasting Options
      • Power Perpetuals
      • Gamma Swap
    • Arbitrage
  • 📶Mining [Guide]
    • AMM Liquidity Mining
    • DERI Liquidity Mining
  • How it works
    • Architecture
    • DPMM (Proactive Market Making)
    • Oracle
    • External Custody
    • Funding Fee
    • Leverage
    • Margin Requirement
    • Open Interest
    • Liquidation
    • Mining (AMM Liquidity Mining)
    • Limit Orders and Stop Orders
  • Governance
    • Deri Improvement Proposal (DIP)
  • Library
    • Derivative Products
    • Whitepaper
    • Code Audits
    • Tokenomics
    • List of Smart Contracts
    • Referral Program
    • Social Links & Media
    • Bridge
    • Trade on Demo Testnet
    • Academy
      • General
        • What are derivatives in DeFi?
        • What are the 3 biggest mistakes of trading derivatives?
        • Four tips for your trading
      • Perpetual Futures
        • General Intro about Perpetual Futures
        • How to Arbitrage
      • Everlasting Options
        • Introducing EverLasting Options
        • Numerical Examples of Everlasting Option Pricing
      • Power Perpetuals
        • Introducing Power Perpetuals
        • Hedging Impermanent Loss with Power Perpetuals (1)
        • Hedging Impermanent Loss with Power Perpetuals (2)
      • Gamma Swap
        • Introducing Gamma Swap
        • Gamma Swap by Deri Protocol
        • Hedging Impermanent Loss with Gamma Swap
        • A New Transaction Fee Algorithm for Gamma Swap
    • Glossary
    • ℹ️FAQs
      • Trading FAQ
        • Perpetual Futures
        • Everlasting Options
      • Mining FAQ
      • Mini-App FAQ
  • DEVELOPERS
    • How to find the Token ID associated with your account
    • Ideas to build
  • Support
    • Submit a question
    • Bug Report & Suggestions
    • Brand Asset
Powered by GitBook
On this page
  • Introduction
  • Composite DPMM of Gamma Swap
  • Funding Calculation
  • Summary

Was this helpful?

  1. Library
  2. Academy
  3. Gamma Swap

Gamma Swap by Deri Protocol

PreviousIntroducing Gamma SwapNextHedging Impermanent Loss with Gamma Swap

Last updated 2 years ago

Was this helpful?

Introduction

In , we introduced a new type of derivative, Gamma Swap. As discussed, the trading of Gamma swap depends on a composite trading venue consisting of two (virtual) primitive trading venues for power perps and perpetual futures. This paper explains the implementation of such a composite trading venue by the .

Composite DPMM of Gamma Swap

Following the terminology in the previous paper, in this paper, iii refers to the index price while MMM refers to the different kinds of mark prices. The core role of DPMM is to determine the mark prices based on the index price input and the trading activities. Everything else (e.g., PnL, funding fees) is then based on the mark prices.

Internally, 1 unit of Gamma swap is treated as a portfolio of powers and perps. DPMM simultaneously keeps track of the power and perp positions and calculates their respective mark prices. When 1 unit of long Gamma swap is entered, the DPMM adds 1 unit of power and −2i01−h0T-\frac{2i_0}{1-h_0T}−1−h0​T2i0​​ units of perp to the two positions, respectively. One could also enter a Gamma swap position with a specified entry price isi_sis​ . In that case, DPMM would add 1 unit of power and −2is1−h0T-\frac{2i_s}{1-h_0T}−1−h0​T2is​​ units of perp to the two positions, respectively. Denote the total net position of power as nnn and total net position of perp as mmm , then DPMM calculates the mark price of perp as follows:

Mperp−ii=kperp(n⋅2i1−hT+m)=kperpm′\frac{M_{perp}-i}{i}=k_{perp}\left(n\cdot\frac{2i}{1-hT}+m\right)=k_{perp}m'iMperp​−i​=kperp​(n⋅1−hT2i​+m)=kperp​m′

where iii is the index price of the underlying, and m′=n⋅2i1−hT+mm'=n\cdot\frac{2i}{1-hT}+mm′=n⋅1−hT2i​+m. Please note that:

  • This is just the classical DPMM for perp with m′=(n⋅2i1−hT+m)m'=\left(n\cdot\frac{2i}{1-hT}+m\right)m′=(n⋅1−hT2i​+m) as the total net position, instead of just mmm.

  • Notice that m′=0 m'=0m′=0 at a “balanced point”, at which the liquidity pool has no Delta exposure. For example, immediately after the first position was opened, we have n=1 n =1n=1 and m=−2i01−h0Tm=-\frac{2i_0}{1-h_0T}m=−1−h0​T2i0​​ , hence m′=0m'=0m′=0 . A “balanced point” is equivalent to the scenario of zero net position in a regular DPMM of perp.

  • A trading action reducing ∣m′∣|m'|∣m′∣ (and thus bringing the system to the “balanced point”) enjoys a negative slippage of MperpM_{perp}Mperp​ . However, since opening a new position at the current price (without specifying entry price) does not change m′m'm′ , it does not enjoy a negative slippage. This is a bit different from the case of perp DPMM, in which a new position reducing the total net position always enjoys negative slippage.

And the mark price of power is:

Mpower−ipoweripower=kpowern\frac{M_{power}-i_{power}}{i_{power}}=k_{power}nipower​Mpower​−ipower​​=kpower​n
ipower=i21−hT i_{power}=\frac{i^2}{1-hT}ipower​=1−hTi2​

Now we have a composite DPMM that, at any point, takes the state variables (n,m,i,σ)(n, m, i, \sigma)(n,m,i,σ) to determine (Mperp,Mpower)(M_{perp}, M_{power}) (Mperp​,Mpower​) and hence givesMgammaM_{gamma}Mgamma​ as

Mgamma=Mpower−2i01−h0TMperp+i021−h0TM_{gamma}=M_{power}-\frac{2i_0}{1-h_0T}M_{perp}+\frac{i_0^2}{1-h_0T}Mgamma​=Mpower​−1−h0​T2i0​​Mperp​+1−h0​Ti02​​

MgammaM_{gamma}Mgamma​determines the trading cost of every trade and consequently determines PnL.

Funding Calculation

1 unit of Gamma swap has composite funding based on the power funding and the perp funding:

Fgamma=Fpower+(2i1−hT−2i01−h0T)FperpF_{gamma}=F_{power}+\left(\frac{2i}{1-hT}-\frac{2i_0}{1-h_0T}\right)F_{perp}Fgamma​=Fpower​+(1−hT2i​−1−h0​T2i0​​)Fperp​

where (i0,h0)(i_0, h_0)(i0​,h0​) are the (i,h)(i,h)(i,h) as of the position entry point, and

Fpower=Mpower−i2TFperp=Mperp−iT=i⋅kperpT(n⋅2i1−hT+m)\begin{align*} F_{power}=&\frac{M_{power}-i^2}{T}\\ F_{perp}=&\frac{M_{perp}-i}{T}=i\cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2i}{1-hT}+m\right) \end{align*}Fpower​=Fperp​=​TMpower​−i2​TMperp​−i​=i⋅Tkperp​​(n⋅1−hT2i​+m)​

FpowerF_{power}Fpower​ is simply handled the same way as power perps.

Whereas the handling of FperpF_{perp}Fperp​ is somewhat tricky, as the coefficient of the FperpF_{perp}Fperp​ term is constantly changing with iii . Essentially, this can be understood as every unit of Gamma swap has −2i01−h0T -\frac{2i_0}{1-h_0T}−1−h0​T2i0​​ “real futures” as well as 2i1−hT\frac{2i}{1-hT}1−hT2i​ “virtual futures”, and hence totally (2i1−hT−2i01−h0T)\left(\frac{2i}{1-hT}-\frac{2i_0}{1-h_0T}\right)(1−hT2i​−1−h0​T2i0​​) effective futures. The tricky part is the constantly varying virtual part. Because of this constantly varying virtual part, the perp funding should be calculated per Gamma swap, instead of per futures.

By definition, the exact funding fee of 1 unit of Gamma swap accumulated over the time period (t1,t2)(t_1, t_2)(t1​,t2​) should be the integral of Fperp F_{perp}Fperp​ over this period.

Fundingperp(t1,t2)=∫t1t2(2i1−hT−2i01−h0T)Fperpdt=∫t1t2(2i1−hT)Fperpdt−2i01−h0T∫t1t2Fperpdt=A∣t1t2−2i01−h0TB∣t1t2 \begin{align*} \text{Funding}_{perp}(t_1,t_2)=&\int_{t_1}^{t_2}\left(\frac{2i}{1-hT}-\frac{2i_0}{1-h_0T}\right) F_{perp}dt \\ =&\int_{t_1}^{t_2}\left(\frac{2i}{1-hT}\right) F_{perp}dt-\frac{2i_0}{1-h_0T}\int_{t_1}^{t_2} F_{perp}dt \\ =& A|_{t_1}^{t_2}- \frac{2i_0}{1-h_0T}B|_{t_1}^{t_2} \end{align*}Fundingperp​(t1​,t2​)===​∫t1​t2​​(1−hT2i​−1−h0​T2i0​​)Fperp​dt∫t1​t2​​(1−hT2i​)Fperp​dt−1−h0​T2i0​​∫t1​t2​​Fperp​dtA∣t1​t2​​−1−h0​T2i0​​B∣t1​t2​​​

where A∣t1t2A|_{t_1}^{t_2} A∣t1​t2​​ and B∣t1t2B|_{t_1}^{t_2} B∣t1​t2​​ are the accumulated increment of AAA and BBB over (ti,t2](t_i,t_2] (ti​,t2​] :

A∣t1t2=∫t1t22i1−hT⋅Fperpdt=∫t1t22i1−hT⋅i⋅kperpT(n⋅2i1−hT+m)dtB∣t1t2=∫t1t2Fperpdt=∫t1t2i⋅kperpT(n⋅2i1−hT+m)dt \begin{align*} A|_{t_1}^{t_2}=&\int_{t_1}^{t_2}\frac{2i}{1-hT}\cdot F_{perp}dt=\int_{t_1}^{t_2}\frac{2i}{1-hT}\cdot i\cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2i}{1-hT}+m\right)dt\\ B|_{t_1}^{t_2}=&\int_{t_1}^{t_2} F_{perp}dt=\int_{t_1}^{t_2} i\cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2i}{1-hT}+m\right)dt\\ \end{align*} A∣t1​t2​​=B∣t1​t2​​=​∫t1​t2​​1−hT2i​⋅Fperp​dt=∫t1​t2​​1−hT2i​⋅i⋅Tkperp​​(n⋅1−hT2i​+m)dt∫t1​t2​​Fperp​dt=∫t1​t2​​i⋅Tkperp​​(n⋅1−hT2i​+m)dt​

Please note that the two accumulating variables AAA and BBB are universal to all positions while io1−h0T\frac{i_o}{1-h_0T}1−h0​Tio​​ is position-specific. We need to track the accumulations of AAA and BBB separately and then for any position we can calculate its accumulated funding fee with its own value of i01−h0T\frac{i_0}{1-h_0T}1−h0​Ti0​​ . That is, for a position of xxx gamma swaps entered at tat_ata​ with entry values (i0,h0)(i_0, h_0)(i0​,h0​) , its accumulated funding fee from t1t_1t1​ to t2t_2t2​ is:

[(At2−At1)−(Bt2−Bt1)2i01−h0T]⋅x\left[(A_{t_2}-A_{t_1})-(B_{t_2}-B_{t_1})\frac{2i_0}{1-h_0T}\right]\cdot x[(At2​​−At1​​)−(Bt2​​−Bt1​​)1−h0​T2i0​​]⋅x

In practice, it is impossible to rigorously calculate AAA and BBB due to their path-dependencies. Hence, we need some numerical approximations.

Approximation Method 1

We assume the funding over the time period (ti−1,ti](t_{i-1},t_i](ti−1​,ti​] is accumulated at the speed as of tit_iti​ . Essentially this assumes i=i(t2),∀i∈(ti−1,ti]i=i(t_2), \forall i \in(t_{i-1}, t_i]i=i(t2​),∀i∈(ti−1​,ti​] . With this approximation, the two integrals over (ti,t2](t_i,t_2](ti​,t2​] degenerate into simple multiplications:

A∣t1t2=2i1−hT⋅i⋅kperpT(n⋅2i1−hT+m)ΔtB∣t1t2=i⋅kperpT(n⋅2i1−hT+m)Δt\begin{align*} A|_{t_1}^{t_2}=&\frac{2i}{1-hT}\cdot i \cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2i}{1-hT}+m\right)\Delta t\\ B|_{t_1}^{t_2}=& i \cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2i}{1-hT}+m\right)\Delta t \end{align*}A∣t1​t2​​=B∣t1​t2​​=​1−hT2i​⋅i⋅Tkperp​​(n⋅1−hT2i​+m)Δti⋅Tkperp​​(n⋅1−hT2i​+m)Δt​

Approximation Method 2

A more reasonable approximation is to assume the index price iii changes linearly over (t1,t2](t_1, t_2](t1​,t2​] :

i(t)=i1+(i2−i1)t−t1t2−t1,∀i∈(ti−1,ti]i(t)=i_1+(i_2-i_1)\frac{t-t_1}{t_2-t_1}, \forall i \in(t_{i-1}, t_i]i(t)=i1​+(i2​−i1​)t2​−t1​t−t1​​,∀i∈(ti−1​,ti​]

Then we can calculate the accumulating variables AAA and BBB as follows:

A∣t1t2=21−hT⋅kperpT(n⋅21−hT⋅i3‾+m⋅i2‾)ΔtB∣t1t2=kperpT(n⋅21−hT⋅i2‾+m⋅i‾)Δt\begin{align*} A|_{t_1}^{t_2}=&\frac{2}{1-hT}\cdot\frac{k_{perp}}{T}\left(n\cdot\frac{2}{1-hT}\cdot\overline {i^3}+m\cdot\overline {i^2}\right)\Delta t\\ B|_{t_1}^{t_2}=& \frac{k_{perp}}{T}\left(n\cdot\frac{2}{1-hT}\cdot\overline {i^2}+m\cdot\overline {i}\right)\Delta t \end{align*}A∣t1​t2​​=B∣t1​t2​​=​1−hT2​⋅Tkperp​​(n⋅1−hT2​⋅i3+m⋅i2)ΔtTkperp​​(n⋅1−hT2​⋅i2+m⋅i)Δt​

where i3‾\overline {i^3}i3, i2‾\overline {i^2}i2 and i‾ \overline ii are the time-weighted average value of i3i^3i3 , i2i^2i2 and iii over (t1,t2](t_1, t_2](t1​,t2​] , respectively:

i3‾=1Δt∫t1t2i3dt=(i1+i2)(i12+i22)4i2‾=1Δt∫t1t2i2dt=i12+i1i2+i223i‾=1Δt∫t1t2idt=i1+i22\begin{align*} \overline{i^3}&=\frac{1}{\Delta t}\int_{t_1}^{t_2}i^3dt=\frac{(i_1+i_2)(i_1^2+i_2^2)}{4}\\ \overline{i^2}&=\frac{1}{\Delta t}\int_{t_1}^{t_2}i^2dt=\frac{i_1^2+i_1i_2+i_2^2}{3}\\ \overline{i}&=\frac{1}{\Delta t}\int_{t_1}^{t_2}idt=\frac{i_1+i_2}{2}\\ \end{align*}i3i2i​=Δt1​∫t1​t2​​i3dt=4(i1​+i2​)(i12​+i22​)​=Δt1​∫t1​t2​​i2dt=3i12​+i1​i2​+i22​​=Δt1​∫t1​t2​​idt=2i1​+i2​​​

With this approximation, the power funding component can be calculated similarly:

Fundingpower(t1,t2)=(kpowern+hT)(1−hT)T⋅i2‾Δt=Apower∣t1t2 \text{Funding}_{power}(t_1,t_2) = \frac{(k_{power}n+hT)}{(1-hT)T}\cdot \overline{i^2} \Delta t= A_{power}|_{t_1}^{t_2}Fundingpower​(t1​,t2​)=(1−hT)T(kpower​n+hT)​⋅i2Δt=Apower​∣t1​t2​​

where Apower∣t1t2A_{power}|_{t_1}^{t_2}Apower​∣t1​t2​​ is the accumulating variable tracking the accumulation of power funding. In practice, the two AAA variables of power and futures can be combined into a single variable.

Summary

where ipoweri_{power}ipower​ is the theoretical price of the power, calculated just like that in the :

The introduces the concept of Gamma Swap, a new type of derivative depending on a composite trading venue consisting of two primitive trading venues for power perps and perpetual futures. This paper explains the implementation of such a composite trading venue by the DPMM of Deri Protocol. With the DPMM for Gamma Swap constructed, now we are ready to roll out a comprehensive solution for Gamm Swap.

the previous paper
DPMM of Deri Protocol
power perp DPMM
previous paper