Respect commissions in jq buy sizing

This commit is contained in:
boris
2026-04-21 18:47:26 -07:00
parent 5be836423a
commit 20af824545
2 changed files with 6 additions and 4 deletions

View File

@@ -1004,7 +1004,8 @@ where
quantity = quantity.saturating_sub(lot); quantity = quantity.saturating_sub(lot);
continue; continue;
} }
if gross <= cash + 1e-6 { let cost = self.cost_model.calculate(OrderSide::Buy, gross);
if gross + cost.total() <= cash + 1e-6 {
return quantity; return quantity;
} }
quantity = quantity.saturating_sub(lot); quantity = quantity.saturating_sub(lot);

View File

@@ -580,7 +580,7 @@ impl JqMicroCapStrategy {
let mut quantity = self.round_lot_quantity((cash / sizing_price).floor() as u32, 100); let mut quantity = self.round_lot_quantity((cash / sizing_price).floor() as u32, 100);
while quantity > 0 { while quantity > 0 {
let gross_amount = execution_price * quantity as f64; 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; return quantity;
} }
quantity = quantity.saturating_sub(100); quantity = quantity.saturating_sub(100);
@@ -825,7 +825,8 @@ impl JqMicroCapStrategy {
take_qty = take_qty.saturating_sub(round_lot.max(1)); take_qty = take_qty.saturating_sub(round_lot.max(1));
continue; continue;
} }
if candidate_gross <= cash + 1e-6 { let candidate_cash = candidate_gross + self.buy_commission(candidate_gross);
if candidate_cash <= cash + 1e-6 {
break; break;
} }
take_qty = take_qty.saturating_sub(round_lot.max(1)); take_qty = take_qty.saturating_sub(round_lot.max(1));
@@ -904,7 +905,7 @@ impl JqMicroCapStrategy {
take_qty = take_qty.saturating_sub(lot); take_qty = take_qty.saturating_sub(lot);
continue; continue;
} }
if candidate_gross <= cash + 1e-6 { if candidate_gross + self.buy_commission(candidate_gross) <= cash + 1e-6 {
break; break;
} }
take_qty = take_qty.saturating_sub(lot); take_qty = take_qty.saturating_sub(lot);