fix(stock-pool): separate exit ownership and ordinary quote dependencies
This commit is contained in:
@@ -866,10 +866,17 @@ pub fn build_stock_pool_target_plan_with_fee_model(
|
||||
let mut quote_sell_exits = BTreeSet::new();
|
||||
let mut sell_condition_denials = BTreeSet::new();
|
||||
if rule.sell_trigger_mode == POOL_SELL_CONDITION {
|
||||
// Ordinary sell predicates only depend on positions participating in
|
||||
// that stage. Independent stops/expiry and protected holdings were
|
||||
// already decided above; unrelated quote fields must not block them.
|
||||
let held = current
|
||||
.iter()
|
||||
.filter(|(symbol, row)| {
|
||||
row.0 > Decimal::ZERO && !constraints.frozen_positions.contains_key(*symbol)
|
||||
row.0 > Decimal::ZERO
|
||||
&& !protected_positions.contains(*symbol)
|
||||
&& !global_stop_hits.contains(*symbol)
|
||||
&& !constraints.automatic_permissions.get(*symbol)
|
||||
.is_some_and(|permission| permission.max_holding_exit)
|
||||
})
|
||||
.map(|(symbol, _)| symbol.clone())
|
||||
.collect::<Vec<_>>();
|
||||
@@ -880,14 +887,6 @@ pub fn build_stock_pool_target_plan_with_fee_model(
|
||||
"e_map,
|
||||
)?;
|
||||
for symbol in held {
|
||||
if global_stop_hits.contains(&symbol)
|
||||
|| constraints
|
||||
.automatic_permissions
|
||||
.get(&symbol)
|
||||
.is_some_and(|permission| permission.max_holding_exit)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let permitted = qualified.get(&symbol) == Some(&true)
|
||||
&& (!rule.secondary_sell_condition
|
||||
|| constraints.position_target_bps.contains_key(&symbol));
|
||||
@@ -1031,7 +1030,12 @@ pub fn build_stock_pool_target_plan_with_fee_model(
|
||||
}
|
||||
let mut planning_symbols = active_symbols;
|
||||
for symbol in &original_final_symbols {
|
||||
if rebuy_exclusions.contains(symbol) && !planning_symbols.contains(symbol) {
|
||||
// An explicit quote/expiry position action owns its single target row.
|
||||
// Keep it excluded from entry sizing without adding a second stop row.
|
||||
if rebuy_exclusions.contains(symbol)
|
||||
&& !factor_position_target_bps.contains_key(symbol)
|
||||
&& !planning_symbols.contains(symbol)
|
||||
{
|
||||
planning_symbols.push(symbol.clone());
|
||||
}
|
||||
}
|
||||
@@ -1688,6 +1692,14 @@ pub fn build_stock_pool_target_plan_with_fee_model(
|
||||
}
|
||||
}
|
||||
}
|
||||
// Verify disjoint planning ownership before an index cap can address rows
|
||||
// by symbol. Never deduplicate emitted intentions or count proceeds twice.
|
||||
let mut owners = BTreeSet::new();
|
||||
for row in &rows {
|
||||
if !owners.insert(row.symbol.as_str()) {
|
||||
return Err(format!("stock_pool_target_owner_conflict:{}", row.symbol));
|
||||
}
|
||||
}
|
||||
if market_timing.is_some() {
|
||||
let caps = index_cap::remaining_index_targets(
|
||||
¤t,
|
||||
|
||||
Reference in New Issue
Block a user