[codex] Add platform-aware small account order floors#154
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06ca98c88c
ℹ️ 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".
| min_order_notional = max(0.0, float(min_order_notional_usd or 0.0)) | ||
| current_min_trade = max(float(execution["current_min_trade"]), min_order_notional) |
There was a problem hiding this comment.
Convert USD floor before comparing with HKD trade values
For HK runtimes, this compares LONGBRIDGE_MIN_ORDER_NOTIONAL_USD directly against execution["current_min_trade"] and the target/market deltas, but those execution values are in the configured trading currency: runtime_config_support.py defaults HK to trading_currency="HKD", and application/longbridge_portfolio.py builds cash and market values from HKD cash/quotes. As a result the default USD 100 floor becomes only HKD 100 for .HK orders, so HK buys/sells between HKD 100 and roughly USD 100 equivalent are still submitted despite the intended USD floor. Please convert the USD floor into the portfolio currency before taking the max, or keep the configured floor currency-specific.
Useful? React with 👍 / 👎.
06ca98c to
7d3468b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d3468b972
ℹ️ 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".
| investable_cash = float(execution["investable_cash"]) | ||
| current_min_trade = float(execution["current_min_trade"]) | ||
| min_order_notional = max(0.0, float(min_order_notional_usd or 0.0)) | ||
| current_min_trade = max(float(execution["current_min_trade"]), min_order_notional) |
There was a problem hiding this comment.
Check the buy budget against the notional floor
This raises the candidate threshold, but the actual buy size later comes from can_buy_value = min(diff, investable_cash). When a symbol is underweight by more than the floor but the remaining investable cash is below it (for example a $500 gap, $90 cash, and a $10 share price), the symbol passes this filter and the loop can still submit a ~$90 buy, defeating LONGBRIDGE_MIN_ORDER_NOTIONAL_USD. Please also reject buys whose available budget or final estimated order value is below the floor.
Useful? React with 👍 / 👎.
7d3468b to
e80cd51
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e80cd516d5
ℹ️ 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".
| if _sell_delta_exceeds_floor( | ||
| current_value=market_values[symbol], | ||
| target_value=target_values[symbol], | ||
| threshold_value=threshold_value, | ||
| min_trade_value=current_min_trade, | ||
| ): |
There was a problem hiding this comment.
Enforce the floor on floored sell quantities
For positive-target rebalances, this gate compares the pre-rounding dollar delta with current_min_trade, but the order sent later is the floored whole-share quantity from _sell_order_quantity. When the account is overweight by more than the new platform floor but one whole-share sale is below that floor (for example current $220, target $110, price $60), this branch still submits a ~$60 ordinary sell even though min_order_notional_usd is 100. Please recheck quantity * submitted_price (while still exempting target-zero exits) before submitting the sell.
Useful? React with 👍 / 👎.
Summary
LONGBRIDGE_MIN_ORDER_NOTIONAL_USDWhy
Small accounts need broker-aware execution filters, but risk-reduction sells must not be blocked by a platform minimum order floor.
Validation
python -m py_compile runtime_config_support.py application/runtime_composer.py application/runtime_dependencies.py application/rebalance_service.py application/execution_service.py main.py tests/test_rebalance_service.py tests/test_runtime_config_support.py tests/test_runtime_composer.pyPYTHONPATH=/home/ubuntu/Projects/LongBridgePlatform:/home/ubuntu/Projects/QuantPlatformKit/src python -m pytest tests/test_runtime_composer.py::test_runtime_composer_builds_runtime_and_config_from_local_builders tests/test_rebalance_service.py::RebalanceServiceNotificationTests::test_min_order_notional_skips_small_buy tests/test_rebalance_service.py::RebalanceServiceNotificationTests::test_min_order_notional_does_not_block_zero_target_risk_sellPYTHONPATH=/home/ubuntu/Projects/LongBridgePlatform:/home/ubuntu/Projects/QuantPlatformKit/src:/home/ubuntu/Projects/UsEquityStrategies/src:/home/ubuntu/Projects/HkEquityStrategies/src /tmp/qsl-platform-test-venv/bin/python -m pytest tests/test_runtime_config_support.py::RuntimeConfigSupportTests::test_min_order_notional_is_loaded_from_env tests/test_runtime_config_support.py::RuntimeConfigSupportTests::test_load_platform_runtime_settings_uses_defaults_with_explicit_strategy_profile