Drawdown
analytics_drawdownCalculate drawdown for stored price or equity results: get max drawdown, peak/trough/recovery timing, or drawdown at every observation.
Instructions
Drawdown of each series in a stored result of prices or equity, computed locally in DuckDB: running peak = the highest value so far, drawdown = value / peak - 1 (0 at a new peak, negative below it). mode max (default): one row per series with max_drawdown, peak_t, trough_t, recovery_t (the first time back at the peak; None if not recovered), peak_to_trough_days and n_obs. mode series: the drawdown at every observation. NULL, NaN, infinite and non-positive values are skipped. Drawdowns are fractions (-0.25 = 25 % below the peak). Use split-adjusted bars. Large outputs are stored and you get a result_id.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"result_id": "<result_id>"
},
"name": "analytics_drawdown"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | max: one summary row per series; series: the drawdown at every observation. | max |
| result_id | Yes | A stored result of prices or account equity (bars, portfolio history, ...). | |
| value_column | No | Numeric column of positive values. Default: the model's first value column (close, equity). | |
| series_column | No | Column naming each series. Default: the result's group column. |