Returns
analytics_returnsCompute simple or log returns for each series in a stored market data result, optionally sampled by UTC period, using DuckDB and saving large outputs for further analysis.
Instructions
Simple or log returns of each series in a stored result (pass its result_id), computed locally in DuckDB. Per series ordered by time: simple r_t = p_t / p_t-1 - 1, log r_t = ln(p_t / p_t-1); the first row of each series has no return; NULL, NaN, infinite and non-positive prices are skipped and counted in the notes. With period (e.g. 1d, 1w), each series is first sampled to its last price per UTC bucket and t is the bucket start. Returns are fractions (0.01 = 1 %). Use split-adjusted bars (adjustment=all). Large outputs are stored and you get a result_id for results_query or other analytics_* tools.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kind | No | simple: p_t / p_t-1 - 1; log: ln(p_t / p_t-1). | simple |
| period | No | Sample each series to the last price per UTC bucket first (1d, 1w, 1mo, 1h, 5min, ...); default: returns between consecutive rows. | |
| result_id | Yes | A stored result of prices (bars, trades, snapshots, portfolio history, ...). | |
| price_column | No | Numeric column of prices. Default: the model's first value column (close for bars). | |
| series_column | No | Column naming each series. Default: the result's group column. |