Skip to content

Keep safe haven cash for unbuyable small accounts#95

Merged
Pigbibi merged 1 commit into
mainfrom
fix-small-account-safe-haven-cash
May 27, 2026
Merged

Keep safe haven cash for unbuyable small accounts#95
Pigbibi merged 1 commit into
mainfrom
fix-small-account-safe-haven-cash

Conversation

@Pigbibi

@Pigbibi Pigbibi commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • avoid sweeping cash into BOXX when the only risk/income target was too small to buy one whole share
  • keep normal cash-sweep BOXX rebuys available when no small-account substitution occurred
  • keep smart DCA out of the LongBridge rollout allowlist for now
  • update the SG SOXL/SOXX rebalance tests for the cash behavior

Verification

  • python -m pytest tests/test_rebalance_service.py -k 'safe_haven_target_below_cash_substitute_threshold_stays_cash or small_account_whole_share_layer_sells_unbuyable_soxx_sleeve or strategy_target_keeps_cash_when_only_risk_target_is_unbuyable or target_gap_below_one_share_does_not_report_cash_shortage'
  • python -m pytest tests/test_rebalance_service.py -k 'strategy_target_keeps_cash_when_only_risk_target_is_unbuyable or dry_run_rebuys_cash_sweep_symbol_with_remaining_investable_cash'
  • Not run locally: python -m unittest discover -s tests -v (local Python environment is missing installed package dependencies)

@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: 3692604741

ℹ️ 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".

Comment thread application/execution_service.py Outdated
not cash_sweep_sold_this_cycle
and cash_sweep_symbol
and cash_sweep_symbol in strategy_assets
and float(target_values.get(cash_sweep_symbol, 0.0) or 0.0) > 0.0

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 Preserve cash-sweep rebuy when no explicit BOXX target

When a strategy relies on cash_sweep_symbol as the fallback sweep instrument but has a zero BOXX target, this new guard skips the final rebuy even if investable_cash is above the threshold and can buy multiple shares. That regresses the existing “remaining investable cash” sweep path (for example the test_dry_run_rebuys_cash_sweep_symbol_with_remaining_investable_cash scenario with BOXX target 0.0 and $1200 cash), leaving cash idle instead of buying BOXX; the condition needs to distinguish the small-account unbuyable-risk substitution from the normal cash-sweep rebuy case.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi force-pushed the fix-small-account-safe-haven-cash branch 2 times, most recently from 3d91da0 to e574543 Compare May 27, 2026 03:23

@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: e574543ba9

ℹ️ 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".

Comment on lines +303 to +304
if float(adjusted_targets.get(symbol, 0.0) or 0.0) > 0.0:
adjusted_targets[symbol] = 0.0

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 Track cash substitution after threshold already zeroed BOXX

When _apply_safe_haven_cash_substitution has already zeroed a BOXX target below the safe-haven threshold (for example BOXX target $900 with a $1000 threshold), this check does not record small_account_safe_haven_cash_substituted_symbols even if all risk/income targets were just projected to cash. The final cash-sweep guard then treats this as a normal zero-target sweep case and can rebuy BOXX whenever investable_cash >= threshold, undoing the intended “keep cash for unbuyable small accounts” behavior for accounts whose safe-haven sleeve was under the threshold but cash is still above it.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi force-pushed the fix-small-account-safe-haven-cash branch from e574543 to d778e96 Compare May 27, 2026 03:30
@Pigbibi Pigbibi merged commit f521131 into main May 27, 2026
1 check passed
@Pigbibi Pigbibi deleted the fix-small-account-safe-haven-cash branch May 27, 2026 03:32

@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: d778e960cb

ℹ️ 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".

Comment on lines +319 to +323
if (
substituted
and not remaining_non_safe_targets
and _positive_target_total(adjusted_targets) <= SMALL_ACCOUNT_SAFE_HAVEN_CASH_SUBSTITUTE_LIMIT_USD
):

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 Count substituted targets in the small-account cap

When a risk/income target is projected to zero, this cap is checked against adjusted_targets, so the substituted sleeve no longer contributes to the $2,000 limit. For example, with a $1,900 risk target whose share price is $2,000 plus a $1,900 BOXX target, substituted is true and the adjusted total is only $1,900, causing BOXX to be zeroed and sold/blocked even though the strategy account was targeting $3,800; use the original target total or portfolio equity for the small-account limit.

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