Align jq microcap sizing and snapshot pricing
This commit is contained in:
@@ -580,8 +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;
|
||||
let cash_out = gross_amount + self.buy_commission(gross_amount);
|
||||
if cash_out <= cash + 1e-6 {
|
||||
if gross_amount <= cash + 1e-6 {
|
||||
return quantity;
|
||||
}
|
||||
quantity = quantity.saturating_sub(100);
|
||||
@@ -594,23 +593,10 @@ impl JqMicroCapStrategy {
|
||||
market: &crate::data::DailyMarketSnapshot,
|
||||
side: OrderSide,
|
||||
) -> f64 {
|
||||
let tick = market.effective_price_tick();
|
||||
let base_price = market.price(PriceField::Last);
|
||||
let adjusted = match side {
|
||||
OrderSide::Buy => base_price + tick * 2.0,
|
||||
OrderSide::Sell => base_price - tick,
|
||||
};
|
||||
let lower = if market.lower_limit.is_finite() && market.lower_limit > 0.0 {
|
||||
market.lower_limit
|
||||
} else {
|
||||
tick
|
||||
};
|
||||
let upper = if market.upper_limit.is_finite() && market.upper_limit > 0.0 {
|
||||
market.upper_limit
|
||||
} else {
|
||||
f64::INFINITY
|
||||
};
|
||||
adjusted.clamp(lower, upper)
|
||||
match side {
|
||||
OrderSide::Buy => market.buy_price(PriceField::Last),
|
||||
OrderSide::Sell => market.sell_price(PriceField::Last),
|
||||
}
|
||||
}
|
||||
|
||||
fn project_order_value(
|
||||
@@ -654,9 +640,8 @@ impl JqMicroCapStrategy {
|
||||
let mut quantity = snapshot_requested_qty;
|
||||
while quantity > 0 {
|
||||
let gross_amount = projected_execution_price * quantity as f64;
|
||||
let cash_out = gross_amount + self.buy_commission(gross_amount);
|
||||
if gross_amount <= order_value + 400.0
|
||||
&& cash_out <= projected.cash() + 1e-6
|
||||
&& gross_amount <= projected.cash() + 1e-6
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -671,8 +656,7 @@ impl JqMicroCapStrategy {
|
||||
.unwrap_or(projected_execution_price);
|
||||
while quantity > 0 {
|
||||
let gross_amount = execution_price * quantity as f64;
|
||||
let cash_out = gross_amount + self.buy_commission(gross_amount);
|
||||
if cash_out <= projected.cash() + 1e-6 {
|
||||
if gross_amount <= projected.cash() + 1e-6 {
|
||||
break;
|
||||
}
|
||||
quantity = quantity.saturating_sub(round_lot);
|
||||
@@ -687,7 +671,7 @@ impl JqMicroCapStrategy {
|
||||
};
|
||||
let gross_amount = fill.price * fill.quantity as f64;
|
||||
let cash_out = gross_amount + self.buy_commission(gross_amount);
|
||||
if cash_out > projected.cash() + 1e-6 {
|
||||
if gross_amount > projected.cash() + 1e-6 {
|
||||
return 0;
|
||||
}
|
||||
projected.apply_cash_delta(-cash_out);
|
||||
@@ -890,8 +874,7 @@ impl JqMicroCapStrategy {
|
||||
take_qty = take_qty.saturating_sub(lot);
|
||||
continue;
|
||||
}
|
||||
let candidate_cash_out = candidate_gross + self.buy_commission(candidate_gross);
|
||||
if candidate_cash_out <= cash + 1e-6 {
|
||||
if candidate_gross <= cash + 1e-6 {
|
||||
break;
|
||||
}
|
||||
take_qty = take_qty.saturating_sub(lot);
|
||||
@@ -923,9 +906,7 @@ impl JqMicroCapStrategy {
|
||||
residual_qty = residual_qty.saturating_sub(lot);
|
||||
continue;
|
||||
}
|
||||
let candidate_cash_out =
|
||||
candidate_gross + self.buy_commission(candidate_gross);
|
||||
if candidate_cash_out <= cash + 1e-6 {
|
||||
if candidate_gross <= cash + 1e-6 {
|
||||
break;
|
||||
}
|
||||
residual_qty = residual_qty.saturating_sub(lot);
|
||||
|
||||
Reference in New Issue
Block a user