Beta
analytics_betaCompute beta, alpha, and R-squared for stored asset price series against one benchmark, using shared timestamps and optional rolling windows in DuckDB.
Instructions
Beta of each asset series against a benchmark, from two stored price results (the benchmark must hold exactly one series), computed locally in DuckDB. Returns (simple or log) are computed over the timestamps both results share: beta = covar_samp(r_a, r_b) / var_samp(r_b), alpha = mean(r_a) - beta x mean(r_b) per period, r_squared = corr^2; fewer than min_obs (20) shared returns gives None (insufficient_data). Bars of different timeframes are refused unless period samples both to the same UTC buckets. With window, a rolling beta per window end. Large outputs are stored and you get a result_id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | No | Sample both to the last price per UTC bucket first (needed when their bars differ). | |
| window | No | Rolling beta over this many shared returns (one row per window end). | |
| min_obs | No | Fewest shared returns for a static beta; below it None. | |
| return_kind | No | Returns used for both series. | simple |
| price_column | No | Numeric price column in both results. Default: each model's first value column (close). | |
| series_column | No | Asset column naming each series. Default: its group column. | |
| asset_result_id | Yes | A stored result of prices of one or more assets (one beta per series). | |
| benchmark_result_id | Yes | A stored result of prices of exactly one benchmark series (e.g. SPY). |