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

Function _build_by_symbol

python/openquant/bars.py:76–94  ·  view source on GitHub ↗
(
    df: pl.DataFrame,
    rust_builder: Callable[[list[str], list[float], list[float], float | int], list[tuple[str, str, float, float, float, float, float, float, int]]],
    param: float | int,
)

Source from the content-addressed store, hash-verified

74
75
76def _build_by_symbol(
77 df: pl.DataFrame,
78 rust_builder: Callable[[list[str], list[float], list[float], float | int], list[tuple[str, str, float, float, float, float, float, float, int]]],
79 param: float | int,
80) -> pl.DataFrame:
81 clean = data.clean_ohlcv(df).sort(["symbol", "ts"])
82 out_frames: list[pl.DataFrame] = []
83 for symbol in clean["symbol"].unique().to_list():
84 sdf = clean.filter(pl.col("symbol") == symbol).sort("ts")
85 rows = rust_builder(
86 [str(x) for x in sdf["ts"].to_list()],
87 [float(x) for x in sdf["close"].to_list()],
88 [float(x) for x in sdf["volume"].to_list()],
89 param,
90 )
91 out_frames.append(_rows_to_frame(symbol, rows))
92 if not out_frames:
93 return _rows_to_frame("", [])
94 return pl.concat(out_frames, how="vertical").sort(["symbol", "ts"])
95
96
97def build_time_bars(df: pl.DataFrame, *, interval: str = "1d") -> pl.DataFrame:

Callers 4

build_time_barsFunction · 0.85
build_tick_barsFunction · 0.85
build_volume_barsFunction · 0.85
build_dollar_barsFunction · 0.85

Calls 2

_rows_to_frameFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected