From 20af8245457d68bb5fd0757c47a19e29ab218da1 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 21 Apr 2026 18:47:26 -0700 Subject: [PATCH] Respect commissions in jq buy sizing --- crates/fidc-core/src/broker.rs | 3 ++- crates/fidc-core/src/strategy.rs | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fidc-core/src/broker.rs b/crates/fidc-core/src/broker.rs index bc2e2f4..e217d6d 100644 --- a/crates/fidc-core/src/broker.rs +++ b/crates/fidc-core/src/broker.rs @@ -1004,7 +1004,8 @@ where quantity = quantity.saturating_sub(lot); continue; } - if gross <= cash + 1e-6 { + let cost = self.cost_model.calculate(OrderSide::Buy, gross); + if gross + cost.total() <= cash + 1e-6 { return quantity; } quantity = quantity.saturating_sub(lot); diff --git a/crates/fidc-core/src/strategy.rs b/crates/fidc-core/src/strategy.rs index c7945b8..56ec39d 100644 --- a/crates/fidc-core/src/strategy.rs +++ b/crates/fidc-core/src/strategy.rs @@ -580,7 +580,7 @@ impl JqMicroCapStrategy { let mut quantity = self.round_lot_quantity((cash / sizing_price).floor() as u32, 100); while quantity > 0 { let gross_amount = execution_price * quantity as f64; - if gross_amount <= cash + 1e-6 { + if gross_amount + self.buy_commission(gross_amount) <= cash + 1e-6 { return quantity; } quantity = quantity.saturating_sub(100); @@ -825,7 +825,8 @@ impl JqMicroCapStrategy { take_qty = take_qty.saturating_sub(round_lot.max(1)); continue; } - if candidate_gross <= cash + 1e-6 { + let candidate_cash = candidate_gross + self.buy_commission(candidate_gross); + if candidate_cash <= cash + 1e-6 { break; } take_qty = take_qty.saturating_sub(round_lot.max(1)); @@ -904,7 +905,7 @@ impl JqMicroCapStrategy { take_qty = take_qty.saturating_sub(lot); continue; } - if candidate_gross <= cash + 1e-6 { + if candidate_gross + self.buy_commission(candidate_gross) <= cash + 1e-6 { break; } take_qty = take_qty.saturating_sub(lot);