Skip to content

Commit 8c8c09f

Browse files
Pigbibicursoragent
andcommitted
Add per-platform cash-only execution and smooth deleverage switching.
Read {PLATFORM}_CASH_ONLY_EXECUTION via QuantPlatformKit, propagate through runtime/sync workflows, and bump QPK/UES pins. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 39447c8 commit 8c8c09f

5 files changed

Lines changed: 28 additions & 12 deletions

File tree

.github/workflows/sync-cloud-run-env.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ jobs:
182182
INCOME_LAYER_ENABLED: ${{ vars.INCOME_LAYER_ENABLED }}
183183
INCOME_LAYER_START_USD: ${{ vars.INCOME_LAYER_START_USD }}
184184
INCOME_LAYER_MAX_RATIO: ${{ vars.INCOME_LAYER_MAX_RATIO }}
185+
LONGBRIDGE_CASH_ONLY_EXECUTION: ${{ vars.LONGBRIDGE_CASH_ONLY_EXECUTION }}
185186
CASH_ONLY_EXECUTION: ${{ vars.CASH_ONLY_EXECUTION }}
186187
DCA_MODE: ${{ vars.DCA_MODE }}
187188
DCA_BASE_INVESTMENT_USD: ${{ vars.DCA_BASE_INVESTMENT_USD }}

decision_mapper.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from us_equity_strategies.cash_only_equity import (
88
build_portfolio_inputs_from_snapshot,
9+
resolve_weight_translation_equity,
910
)
1011
from quant_platform_kit.strategy_contracts import (
1112
PositionTarget,
@@ -464,6 +465,7 @@ def _normalize_to_value_target_decision(
464465
*,
465466
portfolio_inputs,
466467
runtime_metadata: Mapping[str, Any] | None = None,
468+
cash_only_execution: bool = True,
467469
) -> tuple[StrategyDecision, ValueTargetExecutionAnnotations | None]:
468470
target_mode = resolve_decision_target_mode(decision)
469471
no_execute = "no_execute" in set(decision.risk_flags)
@@ -472,18 +474,30 @@ def _normalize_to_value_target_decision(
472474
return decision, None
473475

474476
if target_mode == "weight" and not no_execute:
475-
total_equity = float(portfolio_inputs.total_equity)
476-
if total_equity <= 0.0:
477+
total_equity, block_execution, deleverage_mode = resolve_weight_translation_equity(
478+
portfolio_inputs,
479+
cash_only_execution=cash_only_execution,
480+
)
481+
if block_execution:
477482
return _build_zero_equity_value_decision(
478483
decision,
479484
), _build_weight_translation_annotations(
480485
decision,
481-
total_equity=total_equity,
486+
total_equity=float(portfolio_inputs.total_equity),
482487
liquid_cash=float(portfolio_inputs.liquid_cash),
483488
runtime_metadata=runtime_metadata,
484489
)
490+
decision_for_translation = decision
491+
if deleverage_mode:
492+
decision_for_translation = replace(
493+
decision,
494+
diagnostics={
495+
**dict(decision.diagnostics),
496+
"cash_only_deleverage_mode": True,
497+
},
498+
)
485499
translated = translate_decision_to_target_mode(
486-
decision,
500+
decision_for_translation,
487501
target_mode="value",
488502
total_equity=total_equity,
489503
)
@@ -652,6 +666,7 @@ def map_strategy_decision_to_plan(
652666
decision,
653667
portfolio_inputs=portfolio_inputs,
654668
runtime_metadata=runtime_metadata,
669+
cash_only_execution=cash_only_execution,
655670
)
656671
annotations = normalized_annotations
657672
if annotations is None:

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
flask
22
gunicorn
3-
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@bc5351d3567b2bb60416dc969062c37eedbbf65e
4-
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@5aa949df2962b70d6fdb11c33f7d150492795f16
3+
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@7b6e3ce33e6563db4794fa7b865db9ec428dc478
4+
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@78172596f64c6423a1ab304e53e5d0e18a865175
55
hk-equity-strategies @ git+https://github.com/QuantStrategyLab/HkEquityStrategies.git@f4a7d9252e4c82750045872ff852cb474b172e91
66
pandas
77
requests

runtime_config_support.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from quant_platform_kit.common.runtime_config import (
1010
resolve_bool_value,
11+
resolve_cash_only_execution_env,
1112
resolve_dry_run_env,
1213
resolve_optional_float_env,
1314
resolve_strategy_runtime_path_settings,
@@ -305,7 +306,10 @@ def load_platform_runtime_settings(
305306
if safe_haven_cash_substitute_threshold_usd is not None
306307
else DEFAULT_SAFE_HAVEN_CASH_SUBSTITUTE_THRESHOLD_USD
307308
),
308-
cash_only_execution=resolve_cash_only_execution_env(),
309+
cash_only_execution=resolve_cash_only_execution_env(
310+
os.environ,
311+
platform_env_prefix="LONGBRIDGE",
312+
),
309313
debug_position_snapshot=resolve_bool_value(os.getenv("LONGBRIDGE_DEBUG_POSITION_SNAPSHOT")),
310314
income_threshold_usd=resolve_optional_float_env(os.environ, "INCOME_THRESHOLD_USD"),
311315
qqqi_income_ratio=_qqqi_income_ratio_env(),
@@ -475,11 +479,6 @@ def _runtime_target_enabled_env() -> bool:
475479
return True if value is None else value
476480

477481

478-
def resolve_cash_only_execution_env(name: str = "CASH_ONLY_EXECUTION") -> bool:
479-
value = _optional_bool_env(name)
480-
return True if value is None else value
481-
482-
483482
def _optional_ratio_env(name: str) -> float | None:
484483
value = resolve_optional_float_env(os.environ, name)
485484
if value is None:

scripts/build_cloud_run_env_sync_plan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def _should_add_local_src(candidate: Path) -> bool:
8888
"LONGBRIDGE_STRATEGY_PLUGIN_MOUNTS_JSON",
8989
"LONGBRIDGE_MIN_RESERVED_CASH_USD",
9090
"LONGBRIDGE_RESERVED_CASH_RATIO",
91+
"LONGBRIDGE_CASH_ONLY_EXECUTION",
9192
"LONGBRIDGE_SAFE_HAVEN_CASH_SUBSTITUTE_THRESHOLD_USD",
9293
"INCOME_LAYER_ENABLED",
9394
"INCOME_LAYER_START_USD",

0 commit comments

Comments
 (0)