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

Function load_ohlcv

python/openquant/data.py:224–246  ·  view source on GitHub ↗
(
    path: str | Path,
    *,
    symbol: str | None = None,
    return_report: bool = False,
)

Source from the content-addressed store, hash-verified

222
223
224def load_ohlcv(
225 path: str | Path,
226 *,
227 symbol: str | None = None,
228 return_report: bool = False,
229) -> pl.DataFrame | tuple[pl.DataFrame, dict[str, Any]]:
230 file_path = Path(path)
231 if not file_path.exists():
232 raise FileNotFoundError(f"file not found: {file_path}")
233 suffix = file_path.suffix.lower()
234 if suffix == ".csv":
235 raw = pl.read_csv(file_path)
236 elif suffix in {".parquet", ".pq"}:
237 raw = pl.read_parquet(file_path)
238 else:
239 raise ValueError(f"unsupported file type: {suffix}")
240
241 raw = _canonicalize_columns(raw)
242 if "symbol" not in raw.columns:
243 if symbol is None:
244 raise ValueError("symbol column missing and no symbol argument provided")
245 raw = raw.with_columns(pl.lit(symbol).alias("symbol"))
246 return clean_ohlcv(raw, return_report=return_report)
247
248
249def align_calendar(

Callers

nothing calls this directly

Calls 2

_canonicalize_columnsFunction · 0.85
clean_ohlcvFunction · 0.85

Tested by

no test coverage detected