From ce46c13f37f028393e689babbe5c348d482d3a32 Mon Sep 17 00:00:00 2001 From: boris Date: Mon, 5 Oct 2026 05:57:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=AE=9E=E9=99=85=E7=99=BB?= =?UTF-8?q?=E8=AE=B0=E9=93=BE=E8=B7=AF=E6=9E=84=E9=80=A0=E5=BE=85=E4=BA=A4?= =?UTF-8?q?=E4=BB=98=E8=82=A1=E4=BB=BD=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/fidc-core/src/broker.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/fidc-core/src/broker.rs b/crates/fidc-core/src/broker.rs index a58f622..c6870f7 100644 --- a/crates/fidc-core/src/broker.rs +++ b/crates/fidc-core/src/broker.rs @@ -10758,14 +10758,16 @@ mod tests { Vec::new(), Vec::new(), ).unwrap(); let mut portfolio = PortfolioState::new(20_000.0); - portfolio.position_mut("000001.SZ").buy(date.pred_opt().unwrap(), 1_000, 10.0); - portfolio.apply_cash_delta(-10_000.0).unwrap(); - // Isolated broker fixture: these shares are an asset, but not delivered stock. - portfolio.position_mut("000001.SZ").share_receivables.push(crate::portfolio::ShareReceivable { - ex_date: date, record_date: date.pred_opt().unwrap(), - effective_date: date.succ_opt().unwrap(), quantity: 500, - holding_origin_date: date.pred_opt().unwrap(), - }); + portfolio.position_mut("000001.SZ").buy(date.pred_opt().unwrap(), 1_000, 15.0); + portfolio.apply_cash_delta(-15_000.0).unwrap(); + portfolio.record_closing_holdings(date.pred_opt().unwrap()).unwrap(); + portfolio.register_share_entitlement(&crate::CorporateAction { + date, symbol: "000001.SZ".into(), record_date: date.pred_opt(), + share_effective_date: date.succ_opt(), share_rounding_rule: None, + payable_date: None, share_cash: 0.0, share_bonus: 0.5, share_gift: 0.0, + issue_quantity: 0.0, issue_price: 0.0, reform: false, adjust_factor: None, + successor_symbol: None, successor_ratio: None, successor_cash: None, + }, Some(10.0)).unwrap(); let mut report = BrokerExecutionReport::default(); broker.process_target_value(date, &mut portfolio, &data, "000001.SZ", 15_000.0, "registered shares already meet target value", &mut BTreeMap::new(), @@ -10779,7 +10781,7 @@ mod tests { &mut IntradayExecutionLedger::default(), &mut None, &mut BTreeMap::new(), &mut report).unwrap(); assert!(report.order_events.is_empty()); assert!(report.fill_events.is_empty()); - assert_eq!(portfolio.cash(), 10_000.0); + assert_eq!(portfolio.cash(), 5_000.0); let position = portfolio.position("000001.SZ").unwrap(); assert_eq!(position.quantity, 1_000); assert_eq!(position.share_receivable_quantity(), 500);