$npx -y skills add agiprolabs/claude-trading-skills --skill impermanent-lossImpermanent loss calculation, modeling, and breakeven analysis for AMM liquidity provision across pool types
| 1 | # Impermanent Loss — Calculation, Modeling & Breakeven Analysis |
| 2 | |
| 3 | 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. |
| 4 | |
| 5 | ## Why "Impermanent"? |
| 6 | |
| 7 | 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. |
| 8 | |
| 9 | ## Key Insight |
| 10 | |
| 11 | 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. |
| 12 | |
| 13 | ## Constant-Product IL Formula |
| 14 | |
| 15 | For a standard `x * y = k` AMM (Raydium standard, Orca legacy): |
| 16 | |
| 17 | ``` |
| 18 | IL = 2 * sqrt(r) / (1 + r) - 1 |
| 19 | ``` |
| 20 | |
| 21 | Where `r = P_new / P_initial` (the price ratio). |
| 22 | |
| 23 | ### IL at Key Price Ratios |
| 24 | |
| 25 | | Price Change | Ratio (r) | IL | |
| 26 | |-------------|-----------|----------| |
| 27 | | -75% | 0.25 | -5.72% | |
| 28 | | -50% | 0.50 | -5.72% | |
| 29 | | -25% | 0.75 | -0.60% | |
| 30 | | 0% | 1.00 | 0.00% | |
| 31 | | +25% | 1.25 | -0.60% | |
| 32 | | +50% | 1.50 | -2.02% | |
| 33 | | +100% (2x) | 2.00 | -5.72% | |
| 34 | | +200% (3x) | 3.00 | -13.40% | |
| 35 | | +400% (5x) | 5.00 | -25.46% | |
| 36 | | +900% (10x) | 10.00 | -42.54% | |
| 37 | |
| 38 | Note the symmetry: a 2x increase (r=2.0) and a 2x decrease (r=0.5) both produce -5.72% IL. |
| 39 | |
| 40 | ## Concentrated Liquidity (CLMM) Amplified IL |
| 41 | |
| 42 | 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. |
| 43 | |
| 44 | ### Concentration Factor |
| 45 | |
| 46 | ``` |
| 47 | concentration_factor = 1 / (1 - sqrt(P_lower / P_upper)) |
| 48 | ``` |
| 49 | |
| 50 | For a ±10% range around current price: concentration_factor ≈ 10x. |
| 51 | |
| 52 | ### CLMM IL Behavior |
| 53 | |
| 54 | - **Price within range**: IL is amplified by the concentration factor relative to constant-product IL. |
| 55 | - **Price exits range**: The position becomes 100% of the losing asset. This is the **maximum possible IL** for that direction — you hold only the depreciating token. |
| 56 | |
| 57 | ``` |
| 58 | IL_clmm ≈ IL_constant_product * concentration_factor |
| 59 | ``` |
| 60 | |
| 61 | This approximation holds for small moves. For large moves or prices near range boundaries, use the full CLMM formula (see `references/il_formulas.md`). |
| 62 | |
| 63 | ### Example: CLMM vs Constant-Product |
| 64 | |
| 65 | SOL at $150, LP with ±20% range ($120–$180): |
| 66 | |
| 67 | | Scenario | Constant-Product IL | CLMM IL (±20%) | |
| 68 | |---------------|--------------------:|----------------:| |
| 69 | | SOL → $180 | -0.62% | ~-3.1% | |
| 70 | | SOL → $200 | -1.03% | 100% SOL (exit) | |
| 71 | | SOL → $120 | -1.80% | ~-9.0% | |
| 72 | | SOL → $100 | -3.42% | 100% USDC (exit)| |
| 73 | |
| 74 | ## IL vs Fees: Breakeven Analysis |
| 75 | |
| 76 | The core question for any LP is: **Do fees earned exceed IL incurred?** |
| 77 | |
| 78 | ``` |
| 79 | Net Position = LP_value + accrued_fees - hold_value |
| 80 | ``` |
| 81 | |
| 82 | Profitable when `accrued_fees > IL`. |
| 83 | |
| 84 | ### Breakeven Fee Rate |
| 85 | |
| 86 | For constant-product pools, the expected IL per period is approximately: |
| 87 | |
| 88 | ``` |
| 89 | expected_IL ≈ σ² / 8 |
| 90 | ``` |
| 91 | |
| 92 | Where σ is the standard deviation of log returns for that period. This means: |
| 93 | |
| 94 | | Daily Volatility (σ) | Expected Daily IL | Min Daily Fee Rate to Break Even | |
| 95 | |----------------------|------------------:|--------------------------------:| |
| 96 | | 1% | 0.001% | 0.001% | |
| 97 | | 3% | 0.011% | 0.011% | |
| 98 | | 5% | 0.031% | 0.031% | |
| 99 | | 10% | 0.125% | 0.125% | |
| 100 | | 20% | 0.500% | 0.500% | |
| 101 | |
| 102 | Daily fee income for an LP: |
| 103 | |
| 104 | ``` |
| 105 | daily_fee_income = (deposit / TVL) * daily_volume * fee_rate |
| 106 | ``` |
| 107 | |
| 108 | For a full breakeven framework, see `references/breakeven_analysis.md`. |
| 109 | |
| 110 | ## Modeling IL Over Time |
| 111 | |
| 112 | ### Monte Carlo Simulation |
| 113 | |
| 114 | Simulate many random price paths using geometric Brownian motion (GBM): |
| 115 | |
| 116 | ```python |
| 117 | import numpy as np |
| 118 | |
| 119 | def simulate_price_path( |
| 120 | initial_price: float, |
| 121 | daily_vol: float, |
| 122 | days: int, |
| 123 | drift: float = 0.0, |
| 124 | ) -> np.ndarray: |
| 125 | """Simulate a price path using geometric Brownian motion.""" |
| 126 | dt = 1.0 # daily steps |
| 127 | log_returns = np.random.normal( |
| 128 | (drift - 0.5 * daily_vol**2) * dt, |
| 129 | daily_vol * np.sqrt(dt), |
| 130 | days, |
| 131 | ) |
| 132 | prices = initial_price * np.exp(np.cumsum(log_returns)) |