Stephen Boyd is a renowned @Stanford researcher known for his oft cited textbook, multitude of INFORMS/IEEE awards, and advising BlackRock on convex analysis for manage trillions of dollars
. @akshaykagarwal just defended his PhD under Boyd and is known for his work on visualizations of embeddings via his open-source package PyMDE (minimal distortion embedding)
He’s also a core developer of cvxpy (quant traders ♥️ him) and previously worked on TensorFlow 2
Unlike our other papers, which assume knowledge of crypto, DeFi, + convex analysis, this book chapter is pedagogical + from first principles
Goal: Quant-y undergrads who know Multivariable Calc and Linear Algebra (with proofs, like Lang) *should* be able to pick up CFMM theory
We also show a few new nifty features of CFMMs
1/ Simplified proofs
a. Round-trip trades always lose (path deficiency)
b. Liquidity Provider (LP) share value ∝ ∇ϕ(R)’R [= ϕ(R) for 1-homogeneous functions; surprisingly simple!]
c. Input + output portfolios disjoint
2/ Explicit formulas for add/remove liquidity
Previous papers assumed reserves were constant
We provide a connection between the trading function gradient and the change to liquidity ▶️ helps improve concentrated liquidity formulas (e.g. @Uniswap V3)
e.g. result below:
3/ Exchange Functions
Our curvature paper only showed properties of liquidity (e.g. curvature at fixed reserve) are too state dependent
We elucidate some properties of changes to liquidity via _exchange functions_ which turn out to be concave/convex (*w/o* metric properties)
Their metric properties, which do depend on a particular parametrization and reserve, are shown to be easily computed numerically
This, again, is very useful for measuring impact to concentrated liquidity (e.g. you can extend by linearity exchange functions to piecewise convex)
Finally, exchange functions generalize the invariant calculation done by @CurveFinance to general CFMM curves
There's a simple Newton iteration (gradient descent) for computing trade size from exch. functions
[Remember when @samczsun found a bug in curve's Newton iteration?]
4/ Expected Utility Portfolio
We provide some LP strategies for different utility functions
If we view an LP’s contribution to a CFMM pool as a portfolio allocation, we explicitly find both linear and Markowitz convex programs for how to optimize LP allocation
These are *easily* solved on a laptop and we numerically show how LP allocations change as a function of risk-aversion (cvxpy code included!)
We hope that a clean presentation of these results can make the field more assessable to folks in theoretical CS, ML, statistics, and other quantitative fields
But what’s next? You’ll have to wait until next month ✌🏾
Wow, y'all really aped into this paper, thanks for all the memes (@0xtuba) & thoughtful comments
I figured I'd go a little deeper into the connection between lending protocols and options selling but first, don't forget to follow @htkao, @GuilleAngeris, and @alexhevans ☺️
As @cuckqueeen points out, numerical methods for simulating barrier options are hard to execute correctly (one of the reasons we run all such simulations @gauntletnetwork against the contract execution state in EVM, otherwise you will mess up liq barrier)
The paper explicitly connects the option that a liquidator holds to a down-and-in knock-in option
- a: liquidation incentive
- l: ratio of liq threshold to LTV
- p(t0): loan entry price
But you might be asking: how the hell did we get an exact, analytical formula for this?
We first show how to compare Loan-to-Value (LTV) / collateral factors between borrowing A with B as a collateral vs. borrowing A against an A/B LP pool share
Turns out, with dynamically adjusted LTVs you can make LP share lending *more* safe than lending of the underlying
👉🏾 Lending + CFMM protocols like @SushiSwap’s Kashi can provide way better efficiency if they dynamically adjust LTVs in response to price changes and fee accruals
I found this insanely counterintuitive until I wrote the equations — LP shares can be amazing collateral w/ care
One thing I will say is that most of the fair methodologies have a downsides themselves: 1. Added latency 2. Lack of guarantees about economic price ordering 3. Extremely unproven in production (similar to ZKPs in 2012)
Theoretical (@vegaprotocol’s Wendy) and practical protocols (@valardragon) add a >= 1 block commit-reveal from validators OR added rounds of BFT-style message passing. Griefing vectors (DDoS-esque) are abundant + provable models have weak synchrony guarantees
Recent papers from @algo_class and Joachim Neu show lower bounds on these latencies and it is very unclear if the practical implementations even come close to saturating these bounds (Kelkar, et. al get to weaker bounds in their paper)
Flip the problem upside down: LP returns are a function of how close the weights w (@BalancerLabs portfolio weights) are to the 'optimum' weight w*
Arbitrageurs can be viewed as a stochastic control mechanism that moves w around w*
Can you control |w-w*| as a function of fees?
Trad. Optimal Control: Robot/program has 100% deterministic control over the intervention (e.g. moving robot arm)
LP vs. Arbs: Stochastic control plus fees add a wrinkle — the fee interval. Arbs can never exactly get to w* because of fees, yet Martin/Dave show LPs are still 🤑🤑
Post 1 tl;dr: Curvature controls pool price stability
Post 2: Curvature *directly* controls:
- LP profits when asset pairs are mean reverting
- ∃ a magic formula relating LP profit to adverse selection (probability α of LP realizing IL), curvature, and fees for *any* CFMM!
These results generalize Glosten & Milgrom (1984), Kyle (1985) to arbitrary CFMMs
This seminal work shows the shape of the order book represents the amount of adverse selection a market maker feels, leading to strategies where they remove liquidity to avoid adverse selection