nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting tool in Python and Rust, which accounts for limit orders, queue positions, and latencies, utilizing full tick data for trades and order books, with real-world crypto market-making examples for Binance Futures
MIT License
1.78k stars 357 forks source link

Calculate the average holding time of position #133

Closed ffssea closed 2 weeks ago

ffssea commented 2 weeks ago

My code doesn't seem to be working as expected, how do I modify it or is this completely the wrong approach.

  let curr_orders = hbt.orders(0);

  let holding_ts = curr_orders
      .iter()
      .filter(|(_, x)| x.status == Status::Filled)
      .map(|(_, x)| hbt.current_timestamp() - x.local_timestamp)
      .sum::<i64>() as f64
      / curr_orders.len() as f64;
nkaz001 commented 2 weeks ago

Wouldn't it be better to compute holding time based on position changes?

ffssea commented 2 weeks ago

Thanks for clearing up the confusion, this is a good way to calculate the holding time.