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

Function dfs_paths

crates/openquant/src/combinatorial_optimization.rs:420–461  ·  view source on GitHub ↗
(
    schema: &TradingTrajectorySchema,
    step: usize,
    trades: &mut Vec<i64>,
    inventory_path: &mut Vec<i64>,
    out: &mut Vec<TradingTrajectoryPath>,
)

Source from the content-addressed store, hash-verified

418}
419
420fn dfs_paths(
421 schema: &TradingTrajectorySchema,
422 step: usize,
423 trades: &mut Vec<i64>,
424 inventory_path: &mut Vec<i64>,
425 out: &mut Vec<TradingTrajectoryPath>,
426) -> Result<(), CombinatorialOptimizationError> {
427 if out.len() >= schema.max_paths {
428 return Err(CombinatorialOptimizationError::EnumerationLimitExceeded {
429 limit: schema.max_paths,
430 });
431 }
432 if step == schema.horizon() {
433 let inventory_final = *inventory_path.last().unwrap_or(&schema.initial_inventory);
434 if schema.terminal_inventory.is_some_and(|required| required != inventory_final) {
435 return Ok(());
436 }
437 out.push(TradingTrajectoryPath {
438 trades: trades.clone(),
439 inventory_path: inventory_path.clone(),
440 });
441 return Ok(());
442 }
443
444 let bounds = schema.step_trade_bounds[step];
445 for trade in bounds.min_trade..=bounds.max_trade {
446 let current = *inventory_path.last().unwrap_or(&schema.initial_inventory);
447 let next = match current.checked_add(trade) {
448 Some(v) => v,
449 None => continue,
450 };
451 if next < schema.inventory_min || next > schema.inventory_max {
452 continue;
453 }
454 trades.push(trade);
455 inventory_path.push(next);
456 dfs_paths(schema, step + 1, trades, inventory_path, out)?;
457 inventory_path.pop();
458 trades.pop();
459 }
460 Ok(())
461}
462
463fn enumerate_decisions(
464 values: &[Vec<i64>],

Callers 1

enumerate_trading_pathsFunction · 0.85

Calls 2

lenMethod · 0.80
horizonMethod · 0.80

Tested by

no test coverage detected