Because TWAP inherently lags behind the spot price, it is helpful to understand the potential financial loss, and look into mitigations and tradeoffs.

In particular, it may be useful to quantify the over-valuation of MKR due to TWAP lagging behind the spot price using past swap data. [1][2]

It is shown that on average a 1 hour TWAP over-values MKR compared to spot price by 0.5% but 10% in the worst case. Noticing the worst case and that there is no limiting of loss in the current `kiln`

implementation, I will give more specifics and approaches to mitigate loss.

Hopefully, this article and the iPython notebook linked below, as well as other linked resources, are helpful to quantify the impact of the TWAP oracle lagging the spot price.

- Gathered and derived price data from swaps
- Executed in the UNIv3 MKR-ETH 0.3% pool
- Dates: 2022-08-15 to 2022-11-15

- Computed the average and worst TWAP deviation, specifically TWAP overvaluing the
`sell`

token, by comparing the differences between:- 1 hour TWAP
- 1 minute TWAP
- Pool spot price

- The worst over-valuation of MKR comparing TWAP to spot is about
**10%** - The average over-valuation of MKR comparing TWAP to spot is about
**0.5%**. - Distribution of over-valuation

Histogram of 1 hour TWAP deviation from the poolâ€™s spot price (negative values excluded)

- Summary of positive deviations ie. over-valuation of MKR (as fraction of the spot price)

```
3934676 observations over 2022-08-15 to 2022-11-15
mean 0.0048
std 0.0058
min 0.0000
25% 0.0013
50% 0.0030
75% 0.0062
max 0.1054
```

- Concrete example of moving average lagging significantly: on 2022-11-08 19:30 UTC, $750 lags compared to $646 spot price [4][6]

- Simulating the loss due to over-valuation using an estimated probability function (KDE) shows that on average, trading using TWAP loses $9,000 (0.3%) assuming $3,000,000 open market operation split into 100 $30k
`lot`

s.

```
50 trials
mean 8941.3001
std 2156.6957
min 3892.8330
25% 7433.8469
50% 8841.7192
75% 10514.1229
max 15499.7326
```