Volatility
Author: Aloe Labs, Inc.
Provides functions that use Uniswap v3 to compute price volatility
State Variables
_Q224Div1e18
uint256 private constant _Q224Div1e18 = (uint256(1 << 224) * 1e6) / 1e24;
_Q128Div1e18
uint256 private constant _Q128Div1e18 = (uint256(1 << 128) * 1e6) / 1e24;
Functions
estimate
Estimates implied volatility using this math.
The return value can fit in uint128 if necessary
function estimate(
PoolMetadata memory metadata,
uint160 sqrtMeanPriceX96,
FeeGrowthGlobals memory a,
FeeGrowthGlobals memory b,
uint32 scale
) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
metadata | PoolMetadata | The pool's metadata (may be cached) |
sqrtMeanPriceX96 | uint160 | sqrt(TWAP) over some period. Likely from Oracle.consult |
a | FeeGrowthGlobals | The pool's cumulative feeGrowthGlobals some time in the past |
b | FeeGrowthGlobals | The pool's cumulative feeGrowthGlobals as of the current block |
scale | uint32 | The timescale (in seconds) in which IV should be reported, e.g. hourly, daily, annualized |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | An estimate of the implied volatility scaled by 1e12 |
Structs
PoolMetadata
struct PoolMetadata {
uint24 gamma0;
uint24 gamma1;
int24 tickSpacing;
}
FeeGrowthGlobals
struct FeeGrowthGlobals {
uint256 feeGrowthGlobal0X128;
uint256 feeGrowthGlobal1X128;
uint32 timestamp;
}