Skip to content

fix(execution): universal whole-share retention rule for small accounts#307

Merged
Pigbibi merged 1 commit into
mainfrom
fix/qqqm-small-account-retention
Jul 8, 2026
Merged

fix(execution): universal whole-share retention rule for small accounts#307
Pigbibi merged 1 commit into
mainfrom
fix/qqqm-small-account-retention

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

问题

小账户整数股兼容层的 _should_retain_existing_whole_share 使用硬编码白名单决定是否保留已有持仓。每次新策略加了新标的(如 QQQM),都要手动加白名单,否则会出现 sell-then-fail-to-rebuy 的问题。

修复

通用规则替代逐个标的硬编码:

如果账户已持有该标的(>0 股)且策略 target >= 1 股价格的 85%,就保留不卖

85% 门槛的效果:

  • QQQM $262.74 / $292.42 = 90% → 保留 ✅
  • SOXX $155 / $537 = 29% → 允许卖出(真正的减持)✅

变更

  • 新增 _SMALL_ACCOUNT_RETENTION_MIN_TARGET_SHARE_RATIO_DEFAULT = 0.85
  • _should_retain_existing_whole_share 接受 quantity 参数,先走通用规则,再 fallback 到硬编码白名单
  • 调用方传入持仓数量

影响

所有美国股票策略的所有标的生效,不需要逐个维护白名单。

同步

  • InteractiveBrokersPlatform
  • CharlesSchwabPlatform
  • FirstradePlatform

🤖 Generated with Claude Code

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

1 similar comment
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

…-share compatibility

QQQM (TQQQ's unlevered sleeve in tqqq_growth_income) was not in the
whole-share retention whitelist. When the strategy's target for QQQM
was below 1 share price, the small account compatibility layer zeroed
the target, creating an artificial sell signal. After selling, the
system couldn't buy back because the target (below 1 share) couldn't
be fulfilled, leaving the account in cash.

Add QQQM to:
- SMALL_ACCOUNT_EXISTING_WHOLE_SHARE_RETENTION_SYMBOLS (unconditional)
- SMALL_ACCOUNT_EXISTING_WHOLE_SHARE_RETENTION_MIN_TARGET_SHARE_RATIO_BY_SYMBOL (0.85)
- SMALL_ACCOUNT_WHOLE_SHARE_BOOTSTRAP_MIN_TARGET_SHARE_RATIO_BY_SYMBOL (0.85)

Co-Authored-By: Claude <noreply@anthropic.com>
@Pigbibi Pigbibi force-pushed the fix/qqqm-small-account-retention branch from abc2d36 to 85b4009 Compare July 8, 2026 21:50
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@Pigbibi Pigbibi enabled auto-merge (squash) July 8, 2026 21:51
@Pigbibi Pigbibi merged commit 5eb00ce into main Jul 8, 2026
2 checks passed
@Pigbibi Pigbibi deleted the fix/qqqm-small-account-retention branch July 8, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant