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

Function labeling_get_bins

crates/pyopenquant/src/labeling.rs:264–296  ·  view source on GitHub ↗
(
    events: Vec<(String, Option<String>, f64, Option<f64>, f64, f64)>,
    close_timestamps: Vec<String>,
    close_prices: Vec<f64>,
)

Source from the content-addressed store, hash-verified

262) -> PyResult<Vec<(String, f64, f64, i8, Option<f64>)>> {
263 let close =
264 pair_timestamps_values(close_timestamps, close_prices, "close_timestamps", "close_prices")?;
265
266 let parsed_events: Vec<(chrono::NaiveDateTime, openquant::labeling::Event)> = events
267 .into_iter()
268 .map(|(ts_str, t1_str, trgt, side, pt, sl)| {
269 let ts = chrono::NaiveDateTime::parse_from_str(&ts_str, "%Y-%m-%d %H:%M:%S").map_err(
270 |e| pyo3::exceptions::PyValueError::new_err(format!("invalid datetime: {e}")),
271 )?;
272 let t1 = t1_str
273 .map(|s| {
274 chrono::NaiveDateTime::parse_from_str(&s, "%Y-%m-%d %H:%M:%S").map_err(|e| {
275 pyo3::exceptions::PyValueError::new_err(format!("invalid datetime: {e}"))
276 })
277 })
278 .transpose()?;
279 Ok((ts, openquant::labeling::Event { t1, trgt, side, pt, sl }))
280 })
281 .collect::<PyResult<Vec<_>>>()?;
282
283 let bins = openquant::labeling::get_bins(&parsed_events, &close);
284 Ok(bins
285 .into_iter()
286 .map(|(ts, ret, trgt, label, side)| {
287 (ts.format("%Y-%m-%d %H:%M:%S").to_string(), ret, trgt, label, side)
288 })
289 .collect())
290}
291
292#[pyfunction(name = "drop_labels")]
293fn labeling_drop_labels(
294 events: Vec<(String, f64, f64, i8, Option<f64>)>,
295 min_pct: f64,
296) -> Vec<(String, f64, f64, i8, Option<f64>)> {
297 let parsed: Vec<(chrono::NaiveDateTime, f64, f64, i8, Option<f64>)> = events
298 .into_iter()
299 .filter_map(|(ts_str, ret, trgt, label, side)| {

Callers

nothing calls this directly

Calls 2

pair_timestamps_valuesFunction · 0.85
get_binsFunction · 0.85

Tested by

no test coverage detected