Skip to content

Keep safe haven cash for unbuyable small accounts#45

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#45
Pigbibi merged 1 commit into
mainfrom
fix-small-account-safe-haven-cash

Conversation

@Pigbibi

@Pigbibi Pigbibi commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • avoid sweeping into BOXX when the only non-safe target is below one whole share
  • record safe-haven cash substitution metadata on value-target plans
  • cover the small-account SOXL/SOXX case in execution tests

Verification

  • python -m pytest tests/test_execution_service.py -k 'projects_unbuyable_value_target_to_zero or keeps_safe_haven_cash_when_only_risk_target_is_unbuyable or leaves_small_safe_haven_target_as_cash'

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

ℹ️ 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
Comment on lines +160 to +162
safe_haven_symbols = tuple(
dict.fromkeys(str(symbol or "").strip().upper() for symbol in allocation.get("safe_haven_symbols", ()))
)

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 Include cash sweep symbols in safe-haven substitution

When a plan identifies the sweep vehicle only via portfolio.cash_sweep_symbol and omits allocation.safe_haven_symbols, this new block never considers that symbol for the cash substitution. For example, with risk_symbols=("SOXX",), targets={"SOXX": 194, "BOXX": 1099}, and cash_sweep_symbol="BOXX", the unbuyable SOXX target is projected to zero but BOXX remains a positive target and the executor still sweeps the small account into BOXX. The earlier safe-haven helper already treats cash_sweep_symbol as a safe-haven symbol, so this path should use the same source.

Useful? React with 👍 / 👎.

Comment on lines +163 to +167
remaining_non_safe_targets = [
symbol
for symbol in candidate_symbols
if float(adjusted_targets.get(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 Normalize candidate symbols before checking remaining targets

If risk_symbols/income_symbols arrive in a different case than the target keys, this lookup misses still-buyable non-safe targets after project_unbuyable_value_targets_to_cash normalizes target keys. In a mixed case plan such as risk_symbols=("soxl", "soxx") with uppercase targets where only SOXX is below one share, both lookups return zero here, so the code incorrectly treats all non-safe targets as gone and zeros the safe-haven target even though SOXL remains buyable. Normalize symbol for the adjusted_targets.get(...) check.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi force-pushed the fix-small-account-safe-haven-cash branch from bb3f629 to 70030d8 Compare May 27, 2026 03:30
@Pigbibi Pigbibi merged commit d8071e1 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: 70030d8d36

ℹ️ 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 +183 to +187
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 Honor disabled safe-haven cash substitution

When FIRSTRADE_SAFE_HAVEN_CASH_SUBSTITUTE_THRESHOLD_USD is set to 0 (or otherwise below the BOXX/BIL target), the earlier helper intentionally leaves safe-haven targets unchanged, but this new branch still zeros them whenever a risk/income target was projected away and the adjusted total is <= $2,000. For example, with threshold 0, an unbuyable SOXX target and a $1,099.90 BOXX cash-sweep target, execution skips the BOXX buy anyway, so operators can no longer opt out of keeping safe-haven targets as cash via the documented setting.

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