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

Function build_labeling_events

crates/pyopenquant/src/helpers.rs:191–233  ·  view source on GitHub ↗
(
    close_timestamps: Vec<String>,
    close_prices: Vec<f64>,
    t_events: Vec<String>,
    target_timestamps: Vec<String>,
    target_values: Vec<f64>,
    pt: f64,
    sl: f64,
    min_ret: f64,

Source from the content-addressed store, hash-verified

189 out_report.set_item("symbol_count", report.symbol_count)?;
190 out_report.set_item("duplicate_key_count", report.duplicate_key_count)?;
191 out_report.set_item("gap_interval_count", report.gap_interval_count)?;
192 out_report
193 .set_item("ts_min", report.ts_min.map(|v| v.format("%Y-%m-%d %H:%M:%S").to_string()))?;
194 out_report
195 .set_item("ts_max", report.ts_max.map(|v| v.format("%Y-%m-%d %H:%M:%S").to_string()))?;
196 out_report.set_item("rows_removed_by_deduplication", report.rows_removed_by_deduplication)?;
197 Ok(out_report.into_pyobject(py).unwrap().into_any().unbind())
198}
199
200pub fn build_labeling_events(
201 close_timestamps: Vec<String>,
202 close_prices: Vec<f64>,
203 t_events: Vec<String>,
204 target_timestamps: Vec<String>,
205 target_values: Vec<f64>,
206 pt: f64,
207 sl: f64,
208 min_ret: f64,
209 vertical_barrier_times: Option<Vec<(String, String)>>,
210 side_prediction: Option<Vec<(String, f64)>>,
211) -> PyResult<(
212 Vec<(chrono::NaiveDateTime, f64)>,
213 Vec<(chrono::NaiveDateTime, openquant::labeling::Event)>,
214)> {
215 let close =
216 pair_timestamps_values(close_timestamps, close_prices, "close_timestamps", "close_prices")?;
217 let t_events = parse_naive_datetimes(t_events)?;
218 let target = pair_timestamps_values(
219 target_timestamps,
220 target_values,
221 "target_timestamps",
222 "target_values",
223 )?;
224 let vbars = parse_vertical_barriers(vertical_barrier_times)?;
225
226 let side_storage: Option<Vec<(chrono::NaiveDateTime, f64)>> =
227 if let Some(side) = side_prediction {
228 let (timestamps, values): (Vec<String>, Vec<f64>) = side.into_iter().unzip();
229 Some(pair_timestamps_values(timestamps, values, "side timestamps", "side values")?)
230 } else {
231 None
232 };
233
234 let events = openquant::labeling::triple_barrier_events(
235 &close,
236 &t_events,

Callers 3

labeling_meta_labelsFunction · 0.85

Calls 4

pair_timestamps_valuesFunction · 0.85
parse_naive_datetimesFunction · 0.85
parse_vertical_barriersFunction · 0.85
triple_barrier_eventsFunction · 0.85

Tested by

no test coverage detected