You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While the arithmetic mean TWAPs are much more widely used, they should theoretically be less accurate in measuring a geometric Brownian motion process (which is how price movements are usually modeled)
Arithmetic TWAP tends to overweight higher prices relative to lower ones.
Therefore, we should implement Geometric TWAP.
Suggested Design
The geometric mean can be expressed as the exponential of the arithmetic mean of logarithms.
Ultimately, we would like to calculate:
Therefore, we should be able to utilize our existing arithmetic accumulator system in the log scale.
As the first step, I propose finalizing the logarithm implementation: #2788
Next, integrate the geometric TWAP into the twap module by utilizing the log-average relationship described above.
The naive approach to computing a geometric weighted average is not desirable. First, it is computationally expensive. Second, it causes overflows when attempting to exponentiate spot price with the time weight denominated in milliseconds. Using seconds instead would make us lose precision.
The proposed approach requires using Power() function that takes a decimal exponent.
We already have a Taylor series approximation for bases <= 2 here.
Earlier I suggested using Euler's number (that is > 2) as the base and natural log as the exponent. However, there is no particular reason for that.
Therefore, we can follow the Uniswap v3 choice of base 1.0001 that is within the bounds for the existing Power function to compute: $$GeometricTwap(P) = 1.0001^{ArithmeticTwap(log_{1.0001}{P})}$$
Background
Arithmetic TWAP tends to overweight higher prices relative to lower ones.
Therefore, we should implement Geometric TWAP.
Suggested Design
The geometric mean can be expressed as the exponential of the arithmetic mean of logarithms.
Ultimately, we would like to calculate:
Therefore, we should be able to utilize our existing arithmetic accumulator system in the log scale.
As the first step, I propose finalizing the logarithm implementation: #2788
Next, integrate the geometric TWAP into the
twap
module by utilizing the log-average relationship described above.Core Progress
twapLog
andtwapPow
#3543Acceptance Criteria
Sources
The text was updated successfully, but these errors were encountered: