Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers, and custom indicators
中文简介正在准备中。当前显示原文说明。
Impermanent loss calculation, modeling, and breakeven analysis for AMM liquidity provision across pool types
中文简介正在准备中。当前显示原文说明。
实测评分 未实测
查看安装方法安装前可以查看交给 AI 代理的指令内容。
Impermanent loss (IL) is the cost of providing liquidity to an automated market maker (AMM) relative to simply holding the tokens. When you deposit tokens into a liquidity pool, the AMM continuously rebalances your position as prices move. This rebalancing always works against you — selling winners and buying losers — resulting in less value than if you had just held the original tokens.
IL is called "impermanent" because it only crystallizes when you withdraw. If prices return to their original ratio, IL reverts to zero. However, in practice, prices rarely return exactly, so IL is usually quite real.
IL is a function of the price ratio change, not the absolute price. A token moving from $1 to $2 produces the same IL as a token moving from $100 to $200 — both are a 2x ratio change. Direction does not matter either: a 2x increase and a 0.5x decrease produce the same IL magnitude.
For a standard x * y = k AMM (Raydium standard, Orca legacy):
IL = 2 * sqrt(r) / (1 + r) - 1
Where r = P_new / P_initial (the price ratio).
| Price Change | Ratio (r) | IL |
|---|---|---|
| -75% | 0.25 | -5.72% |
| -50% | 0.50 | -5.72% |
| -25% | 0.75 | -0.60% |
| 0% | 1.00 | 0.00% |
| +25% | 1.25 | -0.60% |
| +50% | 1.50 | -2.02% |
| +100% (2x) | 2.00 | -5.72% |
| +200% (3x) | 3.00 | -13.40% |
| +400% (5x) | 5.00 | -25.46% |
| +900% (10x) | 10.00 | -42.54% |
Note the symmetry: a 2x increase (r=2.0) and a 2x decrease (r=0.5) both produce -5.72% IL.
Concentrated liquidity market makers (Orca Whirlpools, Raydium CLMM, Meteora DLMM) allow LPs to concentrate liquidity within a price range [P_lower, P_upper]. This amplifies both fee income and IL.
concentration_factor = 1 / (1 - sqrt(P_lower / P_upper))
For a ±10% range around current price: concentration_factor ≈ 10x.
IL_clmm ≈ IL_constant_product * concentration_factor
This approximation holds for small moves. For large moves or prices near range boundaries, use the full CLMM formula (see references/il_formulas.md).
SOL at $150, LP with ±20% range ($120–$180):
| Scenario | Constant-Product IL | CLMM IL (±20%) |
|---|---|---|
| SOL → $180 | -0.62% | ~-3.1% |
| SOL → $200 | -1.03% | 100% SOL (exit) |
| SOL → $120 | -1.80% | ~-9.0% |
| SOL → $100 | -3.42% | 100% USDC (exit) |
The core question for any LP is: Do fees earned exceed IL incurred?
Net Position = LP_value + accrued_fees - hold_value
Profitable when accrued_fees > IL.
For constant-product pools, the expected IL per period is approximately:
expected_IL ≈ σ² / 8
Where σ is the standard deviation of log returns for that period. This means:
| Daily Volatility (σ) | Expected Daily IL | Min Daily Fee Rate to Break Even |
|---|---|---|
| 1% | 0.001% | 0.001% |
| 3% | 0.011% | 0.011% |
| 5% | 0.031% | 0.031% |
| 10% | 0.125% | 0.125% |
| 20% | 0.500% | 0.500% |
Daily fee income for an LP:
daily_fee_income = (deposit / TVL) * daily_volume * fee_rate
For a full breakeven framework, see references/breakeven_analysis.md.
Simulate many random price paths using geometric Brownian motion (GBM):
import numpy as np
def simulate_price_path(
initial_price: float,
daily_vol: float,
days: int,
drift: float = 0.0,
) -> np.ndarray:
"""Simulate a price path using geometric Brownian motion."""
dt = 1.0 # daily steps
log_returns = np.random.normal(
(drift - 0.5 * daily_vol**2) * dt,
daily_vol * np.sqrt(dt),
days,
)
prices = initial_price * np.exp(np.cumsum(log_returns))
return np.insert(prices, 0, initial_price)
For each path, compute the IL at each timestep and the cumulative fees earned. After N simulations, analyze the distribution of outcomes.
See scripts/il_scenario_modeler.py for a complete Monte Carlo simulation.
Use actual OHLCV price data to compute what IL would have been for a historical period. This gives a more realistic (but backward-looking) estimate.
Pairs like USDC/USDT have near-zero IL because the price ratio barely moves. Fee income is almost pure profit.
Pairs like SOL/mSOL or ETH/stETH move together, so the price ratio stays close to 1.0. IL is minimal.
A wider range reduces concentration factor, reducing IL at the cost of less fee income per unit of capital.
Monitor price and rebalance your CLMM range when price approaches boundaries. This reduces the risk of price exiting your range entirely.
Higher fee tiers (e.g., 1% vs 0.3%) compensate for higher IL in volatile pairs. Match fee tier to expected volatility.
references/il_formulas.md — Full IL derivations for constant-product, CLMM, and multi-asset poolsreferences/breakeven_analysis.md — Fee vs IL breakeven framework with practical toolsscripts/il_calculator.py — Calculate IL for any price change across pool types, with tables and comparisonsscripts/il_scenario_modeler.py — Monte Carlo simulation of LP positions over time with fee and IL modeling还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers, and custom indicators
中文简介正在准备中。当前显示原文说明。
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security checks, and trader activity
中文简介正在准备中。当前显示原文说明。
Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats, historical price data going back years, exchange volumes, trending tokens, and category filters. Best for macro analysis and long-term historical data.
中文简介正在准备中。当前显示原文说明。
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability analysis
中文简介正在准备中。当前显示原文说明。
Wallet evaluation, monitoring, and copy-trade strategy design for Solana DEX trading
中文简介正在准备中。当前显示原文说明。
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail dependence, and regime-dependent correlation
中文简介正在准备中。当前显示原文说明。