Skip to content

feat(risk): add apply_risk_gate to all crypto entrypoints#63

Merged
Pigbibi merged 4 commits into
mainfrom
feat/crypto-risk-gate
Jul 8, 2026
Merged

feat(risk): add apply_risk_gate to all crypto entrypoints#63
Pigbibi merged 4 commits into
mainfrom
feat/crypto-risk-gate

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add shared apply_risk_gate() in entrypoints/_common.py
  • Wire all 4 crypto evaluate_* entrypoints with appropriate max_single_weight limits

Test plan

  • pytest tests/ -q

Made with Cursor

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@Pigbibi Pigbibi enabled auto-merge (squash) July 8, 2026 14:28
Pigbibi and others added 2 commits July 8, 2026 22:35
Risk gate REJECT/APPROVE paths now carry budgets forward so entrypoint
execution-contract tests keep working when concentration limits fire.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Preserve budgets on reject; pool rotation uses default gate; trend/BTC use 50% cap.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@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: 757caa828e

ℹ️ 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 +96 to +99
return StrategyDecision(
positions=decision.positions,
risk_flags=tuple(risk_flags),
diagnostics={**(decision.diagnostics or {}), "risk_gate": "APPROVE"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve budgets when approving decisions

When any entrypoint passes the gate with positions, this reconstructs StrategyDecision without carrying over decision.budgets, even though the entrypoints just populated DCA/trend BudgetIntents before calling apply_risk_gate. Approved decisions therefore expose empty or missing budgets, so downstream execution loses the pool amounts while positions still look approved. Carry forward the original budgets when returning the approved decision.

Useful? React with 👍 / 👎.

if max_single_weight < 1.0:
for p in positions:
weight = abs(float(p.target_weight))
if weight > max_single_weight:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid applying altcoin caps to core BTC allocations

This concentration check is applied to every position, including the core BTCUSDT leg. With the new callers, crypto_live_pool_rotation uses max_single_weight=0.30 while its own get_dynamic_btc_target_ratio() exceeds 30% above about $17.2k equity, and crypto_btc_dca uses 0.50 while the strategy targets up to 65%, so ordinary accounts are converted to empty rejected decisions before execution. Exempt the core BTC role or align these caps with the BTC target range.

Useful? React with 👍 / 👎.

risk_flags=risk_flags,
diagnostics=diagnostics,
)
return apply_risk_gate(decision, max_single_weight=0.30)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Relax the cap for normal two-asset trend rotations

With the default rotation_top_n=2, crypto_trend_rotation.compute_signals() returns selected rotation weights normalized across the two winners, so at least one selected position is usually 50% or more before any volatility reduction. Passing those normal successful rotations through a 30% single-position cap rejects the entire decision and emits an empty portfolio whenever candidates exist; use a cap compatible with the configured top-N or scale the weights instead of rejecting them.

Useful? React with 👍 / 👎.

risk_flags=risk_flags,
diagnostics=diagnostics,
)
return apply_risk_gate(decision)

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 Enforce a concentration limit for the combo entrypoint

This call relies on the default max_single_weight=1.0, so crypto_equity_combo effectively skips the new single-position concentration gate while the other crypto entrypoints set explicit caps. In normal combo runs with only one rotation winner, the trend leg can allocate most of the configured trend sleeve to a single altcoin and still pass, which leaves this entrypoint outside the hard risk control this change is adding.

Useful? React with 👍 / 👎.

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector

This comment has been minimized.

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector

This comment has been minimized.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector

This comment has been minimized.

@Pigbibi Pigbibi merged commit d1e25ba into main Jul 8, 2026
3 checks passed
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