From 4b6301cb37efc230e7499bffa9b2a31dbab74184 Mon Sep 17 00:00:00 2001 From: boris Date: Fri, 19 Jun 2026 06:03:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=86=85=E8=A1=A5?= =?UTF-8?q?=E4=BB=93=E9=A2=84=E7=AE=97=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fidc-core/src/platform_expr_strategy.rs | 70 +++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/crates/fidc-core/src/platform_expr_strategy.rs b/crates/fidc-core/src/platform_expr_strategy.rs index ae754e9..29ac4bd 100644 --- a/crates/fidc-core/src/platform_expr_strategy.rs +++ b/crates/fidc-core/src/platform_expr_strategy.rs @@ -1767,7 +1767,28 @@ impl PlatformExprStrategy { return 0.0; } let slots_remaining = selection_limit.saturating_sub(working_symbols.len()).max(1); - let active_value = working_symbols + let active_value = self.remaining_buy_cash_active_value( + ctx, + projected, + date, + working_symbols, + value_symbols, + ); + let working_value = active_value + pending_buy_value.max(0.0); + let per_slot_budget = (target_budget - working_value).max(0.0) / slots_remaining as f64; + let single_slot_cap = target_budget / selection_limit as f64; + per_slot_budget.min(single_slot_cap) + } + + fn remaining_buy_cash_active_value( + &self, + ctx: &StrategyContext<'_>, + projected: &PortfolioState, + date: NaiveDate, + working_symbols: &BTreeSet, + value_symbols: &BTreeSet, + ) -> f64 { + working_symbols .iter() .filter(|symbol| value_symbols.contains(*symbol)) .map(|symbol| { @@ -1778,11 +1799,7 @@ impl PlatformExprStrategy { } }) .filter(|value| value.is_finite() && *value > 0.0) - .sum::(); - let working_value = active_value + pending_buy_value.max(0.0); - let per_slot_budget = (target_budget - working_value).max(0.0) / slots_remaining as f64; - let single_slot_cap = target_budget / selection_limit as f64; - per_slot_budget.min(single_slot_cap) + .sum::() } fn project_order_value( @@ -6493,6 +6510,10 @@ impl Strategy for PlatformExprStrategy { let mut projected = ctx.portfolio.clone(); let mut projected_execution_state = ProjectedExecutionState::default(); let mut order_intents = Vec::new(); + let debug_daily_top_up = std::env::var("FIDC_BT_DEBUG_DAILY_TOP_UP") + .map(|value| value == "1" || value.eq_ignore_ascii_case("true")) + .unwrap_or(false); + let mut daily_top_up_debug_notes = Vec::::new(); let mut exit_symbols = BTreeSet::new(); let mut same_day_sold_symbols = BTreeSet::::new(); let mut intraday_attempted_buys = BTreeSet::::new(); @@ -6899,6 +6920,17 @@ impl Strategy for PlatformExprStrategy { if working_symbols.len() >= selection_limit { break; } + let active_value = if debug_daily_top_up { + self.remaining_buy_cash_active_value( + ctx, + &projected, + execution_date, + &working_symbols, + &value_symbols, + ) + } else { + 0.0 + }; let slot_buy_cash = self.remaining_buy_cash_per_slot( ctx, &projected, @@ -6910,6 +6942,20 @@ impl Strategy for PlatformExprStrategy { pending_buy_value, ); let available_buy_cash = slot_buy_cash.min(aiquant_available_cash); + if debug_daily_top_up { + daily_top_up_debug_notes.push(format!( + "daily_top_up_budget date={} working={} value_symbols={} active_value={:.4} pending_buy_value={:.4} target_budget={:.4} slot_buy_cash={:.4} available_cash={:.4} portfolio_cash={:.4}", + execution_date, + working_symbols.len(), + value_symbols.len(), + active_value, + pending_buy_value, + target_budget, + slot_buy_cash, + available_buy_cash, + aiquant_available_cash + )); + } if slot_buy_cash <= 0.0 || available_buy_cash < slot_buy_cash * 0.5 { break; } @@ -6967,6 +7013,17 @@ impl Strategy for PlatformExprStrategy { working_symbols.insert(symbol.clone()); slot_working_symbols.insert(symbol.clone()); pending_buy_value += available_buy_cash; + if debug_daily_top_up { + daily_top_up_debug_notes.push(format!( + "daily_top_up_fill date={} symbol={} requested_cash={:.4} filled_qty={} spent={:.4} remaining_cash={:.4}", + execution_date, + symbol, + buy_cash, + filled_qty, + spent, + aiquant_available_cash + )); + } filled_any = true; break; } @@ -7208,6 +7265,7 @@ impl Strategy for PlatformExprStrategy { ]; diagnostics.extend(selection_notes); diagnostics.extend(explicit_action_diagnostics); + diagnostics.extend(daily_top_up_debug_notes); let notes = vec![ format!("stock_list={}", stock_list.len()),