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

Function _rows_to_frame

python/openquant/bars.py:25–73  ·  view source on GitHub ↗
(symbol: str, rows: list[tuple[str, str, float, float, float, float, float, float, int]])

Source from the content-addressed store, hash-verified

23
24
25def _rows_to_frame(symbol: str, rows: list[tuple[str, str, float, float, float, float, float, float, int]]) -> pl.DataFrame:
26 if not rows:
27 return pl.DataFrame(
28 {
29 "ts": [],
30 "symbol": [],
31 "open": [],
32 "high": [],
33 "low": [],
34 "close": [],
35 "volume": [],
36 "adj_close": [],
37 "start_ts": [],
38 "n_obs": [],
39 "dollar_value": [],
40 }
41 )
42 return pl.DataFrame(
43 {
44 "start_ts": [r[0] for r in rows],
45 "ts": [r[1] for r in rows],
46 "open": [r[2] for r in rows],
47 "high": [r[3] for r in rows],
48 "low": [r[4] for r in rows],
49 "close": [r[5] for r in rows],
50 "volume": [r[6] for r in rows],
51 "dollar_value": [r[7] for r in rows],
52 "n_obs": [r[8] for r in rows],
53 }
54 ).with_columns(
55 pl.lit(symbol).alias("symbol"),
56 pl.col("start_ts").str.strptime(pl.Datetime, strict=False),
57 pl.col("ts").str.strptime(pl.Datetime, strict=False),
58 pl.col("close").alias("adj_close"),
59 ).select(
60 [
61 "ts",
62 "symbol",
63 "open",
64 "high",
65 "low",
66 "close",
67 "volume",
68 "adj_close",
69 "start_ts",
70 "n_obs",
71 "dollar_value",
72 ]
73 )
74
75
76def _build_by_symbol(

Callers 1

_build_by_symbolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected