Author: Amber Krause
Date: 2025-12-06

# Introduction to Weighted AMM Impermanent Loss

#### Amber Krause

#### 2025-12-06

## Introduction to Weighted AMM Impermanent Loss

### The Practical Justification

Impermanent loss is a form of opportunity cost in which individuals who lend assets through Automated Market Maker lending pools can see a decrease in the currency value of their assets compared to the value they would have received by holding (HODL) their assets outside of the lending pool. When considering whether to lend or HODL, individuals balance the projected impermanent loss against the projected fees they will earn from lending.

The impermanentlosscalc package allows users to calculate hypothetical Impermanent Loss (IL) and Net Profit and Loss (PnL) projections under a variety of projected price scenarios.

A single function handles the more commonly used two asset Constant Function Market Maker (CFMM) pools, such as Uniswap and extends to \(\mathbf{N}\)-asset pools, such as Balancer.

### The Mathematical Principle

Tiruviluamala et al. (2023) showed that impermanent loss for an \(\mathbf{N}\)-asset pool can be calculated as \[ \text{IL} = \frac{\text{Geometric Mean of the } t_j\text{'s}}{\text{Arithmetic Mean of the } t_j\text{'s}} - 1 \] where the \(t_{j}\) represent the relative price changes for each asset in the pool.

### Function: Impermanent Loss Calculation

As demonstrated in the referenced literature, impermanent loss is determined solely by the ratio of price change for each asset, making the calculation straightforward regardless of the number of assets. This function takes the following arguments:

- prices_old (\(P_0\)): The vector or array of initial asset prices for each token in the pool.
- prices_new (\(P_t\)): The vector or array of final asset prices for each token in the pool.
- weights (\(w\)): The relative weight of each asset in the pool (must sum to 1).
- investment (\(V_0\)): The total currency value of the initial investment.
- fees: The expected currency value of trading fees earned by the liquidity provider.

The function then produces the following outputs:

- Value if held (\(V_H\)): The final value of the portfolio if the given mix of assets were held outside the lending pool (the Hold Portfolio).
- Value in pool (\(V_P\)): The final value of the assets in the pool (the Pool Portfolio).
- Impermanent loss percent (\(\text{IL\%}\)): The percent of impermanent loss (\(\frac{V_H - V_P}{V_H}\)).
- Nominal impermanent loss (\(\text{IL}\)): The currency value of impermanent loss (\(V_H - V_P\)).
- Fee offset: The currency value of the trading fees earned for providing liquidity.
- Net gain: The final performance difference: \((\text{Value in pool} + \text{Fees}) - \text{Value if held}\).

#### Function Demonstration: Broad Applicability

###### Example 1: Standard Two-Asset Pool (50/50 Uniswap)

The most common AMMs use a 50/50 weight between two assets. If one asset doubles in price, we expect IL to be approximately \(5.7\%\). This shows the package can be used as a standard IL calculator.

    # 50/50 Pool, Token 1 price doubles (100 -> 200)
    library(impermanentlosscalc)
    impermanent_loss(
      prices_old = c(100, 10),
      prices_new = c(200, 10),
      weights = c(0.5, 0.5), # Standard 50/50 weights
      investment = 1000,
      fees = 0,
      plot = FALSE
    )

    ## $`Value if held`
    ## [1] 1500
    ##
    ## $`Value in pool`
    ## [1] 1414.214
    ##
    ## $impermanent_loss_percent
    ## [1] 0.05719096
    ##
    ## $`Nominal impermanent loss`
    ## [1] 85.78644
    ##
    ## $`Fee offset ($)`
    ## [1] 0
    ##
    ## $`Net gain`
    ## [1] -85.78644

###### Example 2: Multi-Asset Pool (Balancer Type)

Though less common, multi asset AMM lending pools with unequal asset weights also exist. This function allows users to calculate impermanent loss for \(\mathbf{N}\)-asset pools with unequal weights.

    # 20/40/40 Pool, Token 1 price triples (10 -> 30).
    library(impermanentlosscalc)
    impermanent_loss(
      prices_old = c(10, 10, 10),
      prices_new = c(30, 10, 10),
      weights = c(0.2, 0.4, 0.4), # Unequal weights for three assets
      investment = 1000,
      fees = 0,
      plot = FALSE
    )

    ## $`Value if held`
    ## [1] 1400
    ##
    ## $`Value in pool`
    ## [1] 1245.731
    ##
    ## $impermanent_loss_percent
    ## [1] 0.1101922
    ##
    ## $`Nominal impermanent loss`
    ## [1] 154.2691
    ##
    ## $`Fee offset ($)`
    ## [1] 0
    ##
    ## $`Net gain`
    ## [1] -154.2691

### Reference

Tiruviluamala, N., Port, A., & Lewis, E. (2022). A general framework for impermanent loss in automated market makers. arXiv preprint arXiv:2203.11352.

    ## R version 4.3.3 (2024-02-29)
    ## Platform: x86_64-pc-linux-gnu (64-bit)
    ## Running under: Linux Mint 22.2
    ##
    ## Matrix products: default
    ## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    ##
    ## locale:
    ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C
    ##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    ##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    ##  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
    ##
    ## time zone: America/Denver
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] impermanentlosscalc_0.1.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] vctrs_0.6.5        cli_3.6.5          knitr_1.50         rlang_1.1.6
    ##  [5] xfun_0.51          generics_0.1.3     S7_0.2.1           jsonlite_2.0.0
    ##  [9] glue_1.8.0         htmltools_0.5.8.1  sass_0.4.9         scales_1.4.0
    ## [13] rmarkdown_2.29     grid_4.3.3         tibble_3.2.1       evaluate_1.0.3
    ## [17] jquerylib_0.1.4    fastmap_1.2.0      yaml_2.3.10        lifecycle_1.0.4
    ## [21] compiler_4.3.3     dplyr_1.1.4        RColorBrewer_1.1-3 pkgconfig_2.0.3
    ## [25] rstudioapi_0.17.1  farver_2.1.2       digest_0.6.37      R6_2.6.1
    ## [29] tidyselect_1.2.1   dichromat_2.0-0.1  pillar_1.10.1      magrittr_2.0.3
    ## [33] bslib_0.9.0        tools_4.3.3        gtable_0.3.6       ggplot2_4.0.1
    ## [37] cachem_1.1.0