Rolling volatility
analytics_volatilityComputes rolling annualised volatility for each series in a stored price or returns result to quantify risk over a chosen window, using DuckDB locally.
Instructions
Rolling annualised volatility of each series in a stored result of prices (or of returns from analytics_returns), computed locally in DuckDB: vol_t = stddev_samp(returns over the last window rows) x sqrt(periods_per_year), reported at the window's last observation; rows before the window fills are omitted. return_kind log (default) or simple for prices. periods_per_year defaults from the bar timeframe (1d 252, 1w 52, 1mo 12, 1h 1638, Nmin 98280/N: US equity sessions) and is required otherwise (365 for daily crypto). Volatility is a fraction per year (0.2 = 20 %). Large outputs are stored and you get a result_id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| window | No | Returns per rolling window (2-2520). | |
| result_id | Yes | A stored result of prices, or of returns from analytics_returns. | |
| return_kind | No | Returns computed from prices (ignored for a returns result, which keeps its kind). | log |
| price_column | No | Numeric column of prices (or returns). Default: the model's first value column. | |
| series_column | No | Column naming each series. Default: the result's group column. | |
| periods_per_year | No | Annualisation factor. Default from the bar timeframe: 1d 252, 1w 52, 1mo 12, 1h 1638, Nmin 98280/N (US equity sessions); required otherwise (e.g. 365 for daily crypto). |