仅在持仓退役时归档批次序号并保留无持仓现金权益
This commit is contained in:
@@ -828,7 +828,7 @@ mod tests {
|
||||
sold.prune_flat_positions();
|
||||
apply(date(), &data, &mut sold, &mut Vec::new(), true, true).unwrap();
|
||||
assert_eq!(sold.cash_receivables()[0].amount, 50.);
|
||||
assert_eq!(sold.position("000001.SZ").unwrap().quantity, 0);
|
||||
assert!(sold.position("000001.SZ").is_none());
|
||||
let mut converted = conversion_book();
|
||||
converted.apply_successor_conversion("000001.SZ", "000002.SZ", 2., 0.).unwrap();
|
||||
apply(date(), &data, &mut converted, &mut Vec::new(), true, true).unwrap();
|
||||
|
||||
@@ -1214,9 +1214,11 @@ impl PortfolioState {
|
||||
pub fn prune_flat_positions(&mut self) {
|
||||
let mut sold_symbols = Vec::new();
|
||||
for (symbol, position) in &self.positions {
|
||||
if position.is_flat() {
|
||||
self.retired_lot_sequences.entry(symbol.clone()).and_modify(|next| *next=(*next).max(position.next_lot_sequence))
|
||||
.or_insert(position.next_lot_sequence);
|
||||
}
|
||||
}
|
||||
self.positions.retain(|symbol, position| {
|
||||
if position.is_flat() {
|
||||
if position.sold_quantity() > 0 {
|
||||
|
||||
Reference in New Issue
Block a user