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

Function data_clean_ohlcv

crates/pyopenquant/src/data.rs:10–57  ·  view source on GitHub ↗
(
    py: Python<'_>,
    timestamps_us: Vec<i64>,
    symbols: Vec<String>,
    open: Vec<f64>,
    high: Vec<f64>,
    low: Vec<f64>,
    close: Vec<f64>,
    volume: Vec<f64>,
    adj_close: Vec<f6

Source from the content-addressed store, hash-verified

8
9use crate::helpers::{build_ohlcv_columns, report_to_pydict, to_py_err};
10
11#[pyfunction(name = "clean_ohlcv")]
12fn data_clean_ohlcv(
13 py: Python<'_>,
14 timestamps_us: Vec<i64>,
15 symbols: Vec<String>,
16 open: Vec<f64>,
17 high: Vec<f64>,
18 low: Vec<f64>,
19 close: Vec<f64>,
20 volume: Vec<f64>,
21 adj_close: Vec<f64>,
22 dedupe_keep_last: bool,
23) -> PyResult<(
24 Vec<i64>,
25 Vec<String>,
26 Vec<f64>,
27 Vec<f64>,
28 Vec<f64>,
29 Vec<f64>,
30 Vec<f64>,
31 Vec<f64>,
32 PyObject,
33)> {
34 let cols =
35 build_ohlcv_columns(timestamps_us, symbols, open, high, low, close, volume, adj_close)?;
36 let (clean, report) = clean_ohlcv_columns(&cols, dedupe_keep_last).map_err(to_py_err)?;
37
38 let out_report = PyDict::new(py);
39 out_report.set_item("row_count", report.row_count)?;
40 out_report.set_item("symbol_count", report.symbol_count)?;
41 out_report.set_item("duplicate_key_count", report.duplicate_key_count)?;
42 out_report.set_item("gap_interval_count", report.gap_interval_count)?;
43 out_report
44 .set_item("ts_min", report.ts_min.map(|v| v.format("%Y-%m-%d %H:%M:%S").to_string()))?;
45 out_report
46 .set_item("ts_max", report.ts_max.map(|v| v.format("%Y-%m-%d %H:%M:%S").to_string()))?;
47 out_report.set_item("rows_removed_by_deduplication", report.rows_removed_by_deduplication)?;
48 Ok((
49 clean.timestamps_us,
50 clean.symbols,
51 clean.open,
52 clean.high,
53 clean.low,
54 clean.close,
55 clean.volume,
56 clean.adj_close,
57 out_report.into_pyobject(py).unwrap().into_any().unbind(),
58 ))
59}
60

Callers

nothing calls this directly

Calls 2

build_ohlcv_columnsFunction · 0.85
clean_ohlcv_columnsFunction · 0.85

Tested by

no test coverage detected