Links

Gamma Swap by Deri Protocol

Introduction

In the previous paper, 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 DPMM of Deri Protocol.
​

Composite DPMM of Gamma Swap

Following the terminology in the previous paper, in this paper,
ii
refers to the index price while
MM
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}
units of perp to the two positions, respectively. One could also enter a Gamma swap position with a specified entry price
isi_s
. In that case, DPMM would add 1 unit of power and
−2is1−h0T-\frac{2i_s}{1-h_0T}
units of perp to the two positions, respectively. Denote the total net position of power as
nn
and total net position of perp as
mm
, 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'
where
ii
is the index price of the underlying, and
m′=n⋅2i1−hT+mm'=n\cdot\frac{2i}{1-hT}+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)
    as the total net position, instead of just
    mm
    .
  • Notice that
    m′=0 m'=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 =1
    and
    m=−2i01−h0Tm=-\frac{2i_0}{1-h_0T}
    , hence
    m′=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'|
    (and thus bringing the system to the “balanced point”) enjoys a negative slippage of
    MperpM_{perp}
    . However, since opening a new position at the current price (without specifying entry price) does not change
    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}n
where
ipoweri_{power}
is the theoretical price of the power, calculated just like that in the power perp DPMM:
ipower=i21−hT i_{power}=\frac{i^2}{1-hT}
Now we have a composite DPMM that, at any point, takes the state variables
(n,m,i,σ)(n, m, i, \sigma)
to determine
(Mperp,Mpower)(M_{perp}, M_{power})
and hence gives
MgammaM_{gamma}
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}
​
MgammaM_{gamma}
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}
where
(i0,h0)(i_0, h_0)
are the
(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*}
​
FpowerF_{power}
is simply handled the same way as power perps.
Whereas the handling of
FperpF_{perp}
is somewhat tricky, as the coefficient of the
FperpF_{perp}
term is constantly changing with
ii
. Essentially, this can be understood as every unit of Gamma swap has
−2i01−h0T -\frac{2i_0}{1-h_0T}
“real futures” as well as
2i1−hT\frac{2i}{1-hT}
“virtual futures”, and hence totally
(2i1−hT−2i01−h0T)\left(\frac{2i}{1-hT}-\frac{2i_0}{1-h_0T}\right)
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)
should be the integral of
Fperp F_{perp}
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*}
where
A∣t1t2A|_{t_1}^{t_2}
and
B∣t1t2B|_{t_1}^{t_2}
are the accumulated increment of
AA
and
BB
over
(ti,t2](t_i,t_2]
:
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*}
Please note that the two accumulating variables
AA
and
BB
are universal to all positions while
io1−h0T\frac{i_o}{1-h_0T}
is position-specific. We need to track the accumulations of
AA
and
BB
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}
. That is, for a position of
xx
gamma swaps entered at
tat_a
with entry values
(i0,h0)(i_0, h_0)
, its accumulated funding fee from
t1t_1
to
t2t_2
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
​
In practice, it is impossible to rigorously calculate
AA
and
BB
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]
is accumulated at the speed as of
tit_i
. Essentially this assumes
i=i(t2),∀i∈(ti−1,ti]i=i(t_2), \forall i \in(t_{i-1}, t_i]
. With this approximation, the two integrals over
(ti,t2](t_i,t_2]
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*}
​

Approximation Method 2

A more reasonable approximation is to assume the index price
ii
changes linearly over
(t1,t2](t_1, t_2]
:
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]
Then we can calculate the accumulating variables
AA
and
BB
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*}
​
where
i3‾\overline {i^3}
,
i2‾\overline {i^2}
and
i‾ \overline i
are the time-weighted average value of
i3i^3
,
i2i^2
and
ii
over
(t1,t2](t_1, t_2]
, 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*}
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}
​
where
Apower∣t1t2A_{power}|_{t_1}^{t_2}
is the accumulating variable tracking the accumulation of power funding. In practice, the two
AA
variables of power and futures can be combined into a single variable.

Summary

The previous paper 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.
​