Calculate impermanent loss for liquidity pool positions
Impermanent loss occurs when the price ratio between two tokens in a liquidity pool changes from the ratio at deposit. The loss is "impermanent" because it reverses if prices return to the original ratio.
The formula: IL = 2√(price_ratio) / (1 + price_ratio) - 1. A 2x price change causes about 5.7% IL, while a 5x change causes about 25.5%.
Pool trading fees can offset impermanent loss. A pool needs to earn more in fees than the IL to be profitable compared to simply holding the tokens.