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

Function labeling_get_events

crates/pyopenquant/src/labeling.rs:203–261  ·  view source on GitHub ↗
(
    close_timestamps: Vec<String>,
    close_prices: Vec<f64>,
    t_events: Vec<String>,
    pt_sl: (f64, f64),
    target_timestamps: Vec<String>,
    target_values: Vec<f64>,
    min_ret: f64,
  

Source from the content-addressed store, hash-verified

201fn labeling_get_events(
202 close_timestamps: Vec<String>,
203 close_prices: Vec<f64>,
204 t_events: Vec<String>,
205 pt_sl: (f64, f64),
206 target_timestamps: Vec<String>,
207 target_values: Vec<f64>,
208 min_ret: f64,
209 num_threads: usize,
210 vertical_barrier_times: Option<Vec<(String, String)>>,
211 side_prediction: Option<Vec<(String, f64)>>,
212) -> PyResult<Vec<(String, Option<String>, f64, Option<f64>, f64, f64)>> {
213 let close =
214 pair_timestamps_values(close_timestamps, close_prices, "close_timestamps", "close_prices")?;
215 let t_ev = parse_naive_datetimes(t_events)?;
216 let target = pair_timestamps_values(
217 target_timestamps,
218 target_values,
219 "target_timestamps",
220 "target_values",
221 )?;
222 let vbars = parse_vertical_barriers(vertical_barrier_times)?;
223
224 let side_storage: Option<Vec<(chrono::NaiveDateTime, f64)>> =
225 if let Some(side) = side_prediction {
226 let (timestamps, values): (Vec<String>, Vec<f64>) = side.into_iter().unzip();
227 Some(pair_timestamps_values(timestamps, values, "side timestamps", "side values")?)
228 } else {
229 None
230 };
231
232 let events = openquant::labeling::get_events(
233 &close,
234 &t_ev,
235 pt_sl,
236 &target,
237 min_ret,
238 num_threads,
239 vbars.as_deref(),
240 side_storage.as_deref(),
241 );
242 Ok(events
243 .into_iter()
244 .map(|(ts, ev)| {
245 (
246 ts.format("%Y-%m-%d %H:%M:%S").to_string(),
247 ev.t1.map(|v| v.format("%Y-%m-%d %H:%M:%S").to_string()),
248 ev.trgt,
249 ev.side,
250 ev.pt,
251 ev.sl,
252 )
253 })
254 .collect())
255}
256
257#[pyfunction(name = "get_bins")]
258fn labeling_get_bins(
259 events: Vec<(String, Option<String>, f64, Option<f64>, f64, f64)>,
260 close_timestamps: Vec<String>,

Callers

nothing calls this directly

Calls 4

pair_timestamps_valuesFunction · 0.85
parse_naive_datetimesFunction · 0.85
parse_vertical_barriersFunction · 0.85
get_eventsFunction · 0.85

Tested by

no test coverage detected