Skip to content

Retain existing leveraged ETF shares for small accounts#163

Merged
Pigbibi merged 1 commit into
mainfrom
codex/small-account-retention-floor
Jun 18, 2026
Merged

Retain existing leveraged ETF shares for small accounts#163
Pigbibi merged 1 commit into
mainfrom
codex/small-account-retention-floor

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • keep an existing whole share for TQQQ/SOXL when the positive target is below one share price
  • preserve existing cash-substitution behavior for other unbuyable sleeves
  • add regression coverage for the SG-style sell-all-then-cannot-buy-back case

Tests

  • python -m py_compile application/execution_service.py tests/test_rebalance_service.py
  • git diff --check
  • timeout 120 python -m pytest tests/test_rebalance_service.py -k 'existing_tqqq_retention_below_one_share or small_account_whole_share_layer_sells_unbuyable_soxx_sleeve or tqqq_delevered_qqqm_target_is_executable or tqqq_delevered_qqq_target_below_one_share' -q

@Pigbibi Pigbibi merged commit 343937c into main Jun 18, 2026
1 check passed
@Pigbibi Pigbibi deleted the codex/small-account-retention-floor branch June 18, 2026 06:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b0fb78508

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

target_value = max(0.0, float(compatibility_targets.get(symbol, 0.0) or 0.0))
price = max(0.0, float(quote_prices.get(symbol, 0.0) or 0.0))
if price > 0.0 and 0.0 < target_value < price and quantities.get(symbol, 0.0) >= 1.0:
compatibility_targets[symbol] = price

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid retaining an extra share when quotes tick up

When the order quote is even slightly above the portfolio snapshot's per-share valuation, setting the retained target to exactly price makes _sell_order_quantity compute (current_value - price) / price and then floor it below held - 1; for example, 7 TQQQ shares valued at $541.31 with a fresh quote of $77.34 sells only 5 shares, leaving 2 instead of the intended minimum whole share. Derive the retained target/order quantity from the held quantity, or otherwise account for quote/snapshot drift before flooring.

Useful? React with 👍 / 👎.

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