RMMs & Derivatives

Author: Alyssa Chen

Introduction

Automated Market Makers (AMMs) such as Uniswap and PancakeSwap are decentralized exchanges (DEX) that utilize an algorithmic trading rule that determines how two assets are to be exchanged through two users. These AMM-based DEXs operate primarily through liquidity pools, where liquidity providers (LP) deposit assets into the pool and are rewarded with a fraction of the fees generated on the AMM, usually distributed as LP tokens. This practice of depositing assets to earn rewards is known as yield farming.

Automated Market Makers & Liquidity

As traders buy and sell assets on AMMs, insufficient liquidity can lead to high-borrow lending spreads, which can lead to capital efficiency and impermanent loss.

AMM exchanges are usually based on a constant function– Bancor was one of the first AMM-based DEXs to implement the constant product market maker (CPMM), which is based off the constant product function: xy=kx*y=k. This formula accounts the range of prices for two tokens according to the available quantities (liquidity) of each token. When the supply of token XX increases, the token supply of YY must decrease, and vice-versa, to maintain the constant product KK.

Constant Product Function
Constant Product Function

On the other hand, constant sum market makers (CSMM) follow the formula x+y=kx+y=k. However, this formula allows arbitrageurs to drain one of the reserves if the off-chain reference price between the tokens is not 1:1, which is why AMMs rarely follow the CSMM model.

Constant Sum Function
Constant Sum Function

The final market maker we will cover in this article is the constant mean market maker (CMMM), which enables the creation of AMMs that can have more than two tokens and be weighted outside of the standard 50/50 distribution. For a liquidity pool with three assets, the equation would be the following: xyz13=kxyz^{\frac{1}{3}}=k, where the weighted geometric mean of each reserve remains constant (i.e. Balancer).

Limitations of AMMs

Impermanent Loss & Capital Inefficiency

Impermanent loss (also known as 'negative gamma' in finance) and low capital inefficiency are two limits of AMMs that affect both liquidity providers and traders.

After an LP deposits assets into a pool, the price of one of the deposited assets changes significantly compared to the value when initially deposited. As a result, the ratio of assets in the pool will also fluctuate due to arbitrage trading and rebalancing prices that occur with external markets– therefore, in some cases depositing assets could lessen the LP’s positional value, which is the essence of impermanent loss. In other words, this loss is “impermanent” because the loss is recoverable if prices return to its original state when liquidity was initially deposited. On the other hand, the impermanent loss becomes permanent if the LP decides to withdraw their liquidity from the pool at this new price ratio.

Capital inefficiency refers to how effectively liquidity (capital) within a pool is used to facilitate trades without leading to large price impacts. Low capital efficiency indicates that large amounts of liquidity are required to facilitate trades without moving the market price significantly. An ideal DeFi protocol is able to optimally utilize deposited assets to ensure a balanced and efficient market– high spreads would be an indicator of capital inefficiency. As a result, platforms with high spreads may result in loss of market share over time in comparison to other platforms offering more favorable rates, and this can be unfavorable for LPs because their capital isn't utilized as effectively, leading to lower returns.

Replicating Maker Markets allow users to directly control their impermanent loss by defining a target price around which liquidity will be most concentrated. In the context of traditional markets, this is similar to setting a price in a limit order where a trader specifies the price at which they're willing to buy or sell an asset. RMMs seek to address these limitations via algorithmic strategies to better replicate the ideal liquidity curves and trading functionalities of traditional order book markets, allowing for more efficiency, flexibility, and risk management control.

Explaining RMMs

Portfolios & Continuous Rebalancing

RMMs are essentially AMMs whose portfolio value matches a target payoff. We can investigate the case of a Uniswap liquidity provider (LP), whose value is determined by its underlying assets and their performance over time to better understand the concept of rebalancing. When the value of one asset with respect to the other asset changes, the portfolio must be rebalanced such that the value composition is equally 50-50 in each asset. This rebalancing occurs by arbitrageurs who put one asset in and take another asset out, in order to maintain the pool composition to the 50-50 value. When the rebalancing occurs, whoever made the trade will have paid a trading fee. This trading fee is earned by all the LPs of the pool. Therefore, as more trades (rebalancing) occur, their portfolio value will grow over time (the specific fees are determined by the protocol of the specific AMM protocol).

In a RMM, the portfolio is always being rebalanced in a way such that it matches a desired payoff. In RMMs, the goal is to replicate or mimic the payoff of certain financial instruments or a desired outcome. Unlike traditional AMMs which rely on a predefined mathematical formula to set prices and manage liquidity, RMMs actively manage their portfolios to ensure that the outcome of trading within these markets closely follows a predetermined financial model or payoff structure.

RMMs use algorithms as a mechanism to continuously adjust the composition of their liquidity pools in order to ensure that the value of the pool aligns with the desired payoff structure over time. This process involves algorithmically trading assets within the pool or with external markets to maintain the target allocation and payoff outcome.

Replicating Portfolios

A replicating portfolio (also known as a hedge) is defined as a portfolio of assets that exhibit the same properties as the asset being referenced. In this context, there can be state and dynamic replications. State replication alludes to a portfolio sharing the same cash flows as the reference asset (with a stagnant change state), while dynamic replication indicates that the portfolio has a differing cash flow than the reference asset, but shares the same Greeks (meaning for infinitesimally small changes to underlying market parameters, the asset and portfolio price are altered in the same way). Due to the behaviors of the asset and portfolio’s partial derivatives at a singular point, dynamic replication must occur frequently.

Replicating portfolios provide a framework for assessing and managing risk— they do so by allowing traders to replicate the payoff structures of complex financial instruments. In DeFi, where derivatives are commonly used to hedge risk, manage exposure, and facilitate liquidity provision, the concept of RMMs can be important.

RMM & CFMM curves

Since the goal of RMMs is to generate a trading function that models a specific trading fee payoff, we can represent the equation for an RMM given the CFMM function. A constant function market maker (CFMM) is governed by its trading function (ψ):R+nR(\psi ) : \mathbb{R}^n_+ \to \mathbb{R}.

Each reserve RiR+nR_i \in \mathbb{R}^n_+ represents the amount of asset ii available in the contract, which allows individuals to trade reserves as long as the following equation is satisfied: ψ(R)ψ(R),\psi(R') \geq \psi(R), with RR+nR \in \mathbb{R}^n_+.

For a non-decreasing, concave function V(αc)=αV(c)V(\alpha c) = \alpha V(c), αR\alpha\in\mathbb{R} , (V)(V) is a portfolio value function which maps (V):R+nR(V): \mathbb{R}^n_+ \to \mathbb{R}. We model asset cR+nc \in \mathbb{R}^n_+ as a price vector representing nn coins the CFMM trades, with cic_i being the price of coin ii in the external market.

The trading value is then defined with the following equation: ψV(R)=infc0(cRV(c)).\psi_V\left(R\right) = \inf_{c\geq0}(c^{\intercal}R - V\left(c\right)).

Given this definition, it is shown that ψV(R)\psi_V\left(R\right) is defined as the greatest lower bound (infimum) of the expression cRV(c)c^{\intercal}R - V\left(c\right) over all non-negative vectors cc.

Now, let's prove that ψV(R)0\psi_V\left(R\right) \geq 0 if and only if cRV(c)cRnc^{\intercal}R \geq V(c) \forall c \in \mathbb{R}^n, which is desirable since we want that the least surplus across all non-negative vectors cc to be non-negative to ensure reserves RR are always at least sufficient to meet required values V(c)V(c) under all possible weightings cc.

Given ψV(R)0\psi_V\left(R\right) \geq 0, this implies the infimum (least upper bound) of all cRV(c)c^{\intercal}R - V\left(c\right) across all c0c \geq 0 is non-negative, which implies that for every non-negative cc, the individual value cRV(c)c^{\intercal}R - V\left(c\right) is also non-negative. Therefore, cTRV(c)0    cTRV(c)c^TR-V(c) \geq 0 \implies c^TR \geq V(c). Since the infimum in this set is proven to be non-negative, this implies all values are at least as great.

To prove the other direction, since for all c0,cTRV(c)c \geq 0, c^TR \geq V(c), each evaluation of cTV(c)c^TV(c) would yield a non-negative value. By the same logic, the greatest lower bound of all these values would also be non-negative. Therefore, the condition ψV(R)0\psi_V\left(R\right) \geq 0 is true if and only if RR belongs to the set of reserves that yields a payoff greater or equal to VV.

This proof ensures that the reserves for a non-negative trading value function will always satisfy the required portfolio values under any external price weightings— in other words, the market maker is never undercollateralized. This way, we are able to check if a given reserve vector is able to satisfy the market making function we wish to model.

Derivatives

Derivatives are used as a tool to analyze or speculate on an assets price in the future without having to purchase the asset itself. For example, if a user believed Tesla's stock would rise in the near future, the user could then purchase the right to buy shares to Tesla's stock in the future for a set price. Purchasing derivatives is not only a way to take on long or short positions, but can also be a way to hedge risk.

A derivative is defined as a financial contract that derives its values from its underlying assets (i.e., shares, securities, commodities, etc.). Derivatives that are bought and sold privately (over the counter) are not regulated, and derivatives in exchanges are bought and sold via regulated systematic contracts. There are three main types of derivatives: futures & forwards, options, and swaps. In this paper, we will briefly introduce options, future and forwards.

Call Options

A call option in traditional financial markets is a contract between a buyer and seller that gives the right to purchase an asset for a predetermined (strike) price up until an expiration date. This allows the buyer to purchase the stock by exercising the call– however, the buyer does not have the obligation to do so. On the other hand, the seller shorting (selling) the call option has the obligation to sell the asset at the strike price.

In decentralized finance, these call options are collateralized to simulate the legally enforceable nature of asset delivery via one part to the other. A covered call occurs when collateral is deposited and the call option is sold.

In long calls, buyers have the option to openly purchase shares. Purchasing a long call at strike price gives buyers the option to plan ahead. For example, if a tech company frequently has new product launches at around the same time each year, the company’s stock price has the ability to appreciate after the launch.

Short Calls indicate an open obligation to sell shares. Until the expiration date, the seller is obligated to sell shares of the stock at strike price. Short calls are generally used to increase and boost income.

Investors in long call options hope for the underlying stock price to rise above the exercise price, and on the contrary, short call investors want the underlying stock price to stay below the exercise price.

Greeks & Black Scholes

The concept of greeks in decentralized finance (borrowed from traditional finance) plays a crucial role in analyzing the sensitivity of various derivative instruments and protocols to different market factors. While greeks are primarily used in options trading, their interpretation in DeFi can extend to protocols with automated market makers and liquidity provision mechanisms.

Delta (Δ\Delta): the sensitivity of an asset's price to changes in the price of the underlying token. In an AMM, delta can represent how the liquidity pool's token ratio shifts in response to price changes of one of the assets in the pool.

Gamma (Γ\Gamma): the rate of change of Delta in response to changes in the price of the underlying asset. Gamma can be important for yield farming or liquidity mining, or protocols where changes in the ratio of tokens due to price movements can impact returns.

Vega (VV ): represents sensitivity to volatility. In decentralized options or derivative markets, Vega can quantify how a liquidity provider’s position might gain or lose value based on volatility in the price of the underlying asset.

Theta (Θ\Theta): measures the sensitivity of the position's value to the passage of time. For example, in protocols that lock liquidity for a set duration, Theta reflects the decay in value as the lock-up period approaches expiration.

Rho (ρ\rho): measures sensitivity to interest rates. Rho is more commonly useful in traditional finance settings. However, rho can be commonly observed in DeFi protocols that involve borrowing and lending (e.g., Aave, Compound, etc.).

Black Scholes, Black-Scholes-Merton or BSM is a model developed in the 1970’s by economists Fischer Black and Myron Scholes. Black Scholes refers to the differential equation used by traders to price options contracts. It is commonly used by investors and traders to make decisions in trading and requires five main inputs:

  1. The underlying stock's price

  2. Option's strike price

  3. Time to option's expiry

  4. Stock's volatility

  5. Risk free interest rate

Formula: C=StN(d1)KertN(d2), where d1=lnStK+(r+12σ2)tσtC = S_tN(d_1) - Ke^{-rt}N(d_2), \text{ where } d_1 = \frac{\ln\frac{S_t}{K} + (r + \frac{1}{2}\sigma^2)t}{\sigma\sqrt{t}} and d2=d1σtd_2=d_1-\sigma \sqrt{t}.

  • SS-The current or underlying stock's price

  • CC- Call option's price

  • KK- Strike price

  • rr- Risk free interest rate

  • tt- Time to option's maturity

  • NN- Normal distribution

Futures & Forwards

Imagine you are a baker, famous for your apple pies, but apple prices fluctuate drastically between 10-40 cents/lb depending on the harvest season. In order to hedge against market volatility, you and the apple farmer set up a contract to apples at 15 cents/lb, regardless of the market price. This is an example of a forward contract.

On the other hand, futures are a legal contract to buy or sell a commodity asset or security at a set price at a specified date in the future. These contracts are standardized on futures exchanges. The seller of the contract has an obligation to deliver that asset at the expiration date, while the buyer takes on the obligation to buy and receive the asset at expiry date.

There are two main forwards and futures curves, which are attributed to prices over time, and is used to determine whether the contract price is rising of falling:

  • Contango markets are often involving goods that don't have an immediate consumption date, (i.e. precious metals). Contango can also be analogous to a normal curve; the idea is that consumers may be more willing to pay a higher price than the current spot price for a commodity in the future. In the previous example of apples, the current spot price for apples are 20 cents/barrel, and the futures contract is priced at 50 cents per barrel. If a consumer buys at the spot price and stores until later to sell at the futures price, the current demand and current price for apples will increase. This implies that, in the future people will be more likely to agree to sell, which will lower future prices.

  • On the contrary, normal backwardation is based upon the theory that due to volatility, sellers are more inclined to sell at a lower price than the expected price in the future.

Futures Market (Source: Investopedia)
Futures Market (Source: Investopedia)

Backwardation is a indicator of a bullish market for the commodity, since it suggests the current value of the asset is the most valuable, which can be a sign of a shortage. Some severe contangos, on the other hand, can be an indicator of a bearish market, which can be caused by surplus or anticipated future shortage.

Why RMM's?

Suppose you are an investor holding a large position in ETH, looking to hedge against specific short-term downside risks while minimizing exposure to ETH's price movements, yet also wanting to be bullish in the long run. A common strategy would be to actively rebalance your portfolio with options, futures, or other financial instruments to maintain the hedge. This is known as a delta neutral strategy– where the total delta of the portfolio is maintained at or near zero in order to hedge against price movements in the underlying asset.

Instead of doing this manually, users can incorporate RMMs to passively create a delta neutral position. This is one benefit of using RMMs; it serves as a form of risk management without the costs or efforts associated without monitoring the positions daily. Some other reasons to use RMMs could include the following:

  • Creating synthetic exposures to markets that might not be liquid or even accessible, for example, through cross-chain derivatives.

  • Custom yield strategies: By pairing options with yield-bearing assets, you can generate structured yield products such as covered call strategies.

  • Enhance liquidity provision: LPs can set up custom liquidity ranges based on expected volatility in an asset. (i.e. LPs can use concentrated liquidity (Uniswap v3) to replicate option-like payoff profiles by specifying ranges).

However, AMMs may also retain utility in the case where order books become too costly to maintain, such as in a low-liquidity environment. In low-liquidity environments, traditional order book systems can become inefficient due to wide bid-ask spreads and a lack of sufficient market participants to match trades. In contrast, AMMs provide continuous liquidity by relying on algorithmic price setting via a mathematical equation, which ensures trades are able to execute smoothly even in markets with fewer participants or lower liquidity.

Some examples of companies actively working on DeFi RMMs include but are not limited to Primitive’s RMM-01, which replicates the Black Scholes model on the Ethereum mainnet and Numeon Core, which allows for permissionless options exchanges via Ethereum.

Appendix

Glossary:

Infimum: The infimum, inf of a set is defined to be the greatest lower bound of that set. More rigorously, we define α\alpha to be the inf of a set AA if xA,αx.\forall x \in A, \alpha \leq x. Furthermore, since α\alpha is the greatest lower bound, if βx,xA\beta \leq x, \forall x \in A and βα\beta \leq \alpha, since α\alpha serves as the greatest lower bound.

CFMMs vs AMMs: To differentiate CFMMs and AMMs, remember that all CFMMs are AMMs, but not all AMMs are CFMMs. CFMMs are a specific type of AMM, which is governed by a constant mathematical relationship between asset reserves, while AMMs use any algorithm (i.e. oracles, market conditions) to adjust prices.

Impermanent Loss: Daily Defi provides an impermanent loss calculator that can be used to visualize the calculations of impermanent loss using Uniswap's constant product formula. In the following diagram, Token A is initially set to $150 and Token B is set to $1. In Future Prices, Token A has increased to $300 while Token B has remained the same. (The calculator automatically sets a total starting value of $1000 between the two tokens).

Daily Defi's Impermanent Loss Calculator
Daily Defi's Impermanent Loss Calculator
Calculations of Impermanent Loss
Calculations of Impermanent Loss

References:

An Introduction to Replicating Market Makers (Numeon, 2021)

Replicating Market Makers (The Tie, 2021)

Mirror.xyz: Replicating Market Makers by Evan De Kim} (2021)

What is an Automated Market Maker (AMM)? (Chainlink Education Hub, 2021)

Automated Market Makers and the Universal Law of Demand (Harvard ADS, 2021)

Market Makers (Opyn Notion, 2021)

Primitive.xyz RMM FAQ (2021)

Mirror.xyz: Primitive Finance RMM Explanation (2021)

Call Options Basics (Fidelity Learning Center, 2021)

Replicating Market Makers: Theoretical Model (Angeris et al., 2021)

Constant Function Market Makers (Stanford University, Boyd et al., 2021)

Replicating Portfolio Definition (Capital.com, 2021)

Subscribe to Blockchain at Berkeley
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.