MCPcopy Create free account
hub / github.com/Open-Quant/openquant / bar_diagnostics

Function bar_diagnostics

python/openquant/bars.py:138–167  ·  view source on GitHub ↗
(df: pl.DataFrame)

Source from the content-addressed store, hash-verified

136 `n_obs` (rows in the bar) and `dollar_value` (sum of `close * volume`), sorted by
137 `symbol` then `ts`.
138
139 Raises
140 ------
141 ValueError
142 If `interval` does not have a supported form or is not positive, or `df` lacks a
143 required column.
144 """
145 return _build_by_symbol(df, _core.bars.build_time_bars, _interval_to_seconds(interval))
146
147
148def build_tick_bars(df: pl.DataFrame, *, ticks_per_bar: int = 50) -> pl.DataFrame:
149 """Group an OHLCV frame into tick bars of a fixed row count per symbol (AFML 2.3.1.2).
150
151 The input goes through `openquant.data.clean_ohlcv` first (column aliases resolved, rows
152 with nulls dropped, duplicate `(symbol, ts)` keys removed) and is then processed one
153 symbol at a time. Each input row is treated as one trade at its `close` price with its
154 `volume`; the input `open`, `high`, `low` and `adj_close` are ignored, so the output
155 `high`/`low` are the extremes of the input closes.
156
157 A bar closes once `ticks_per_bar` rows have accumulated; a trailing partial bar is
158 dropped.
159
160 Parameters
161 ----------
162 df : polars.DataFrame
163 Long OHLCV frame with columns `ts`, `symbol`, `open`, `high`, `low`, `close` and
164 `volume` (or aliases accepted by `clean_ohlcv`).
165 ticks_per_bar : int, default 50
166 Number of rows per bar.
167
168 Returns
169 -------
170 polars.DataFrame

Callers

nothing calls this directly

Calls 1

_lag1_autocorrFunction · 0.85

Tested by

no test coverage detected