Risk management
Deterministic. Independent. Fail-closed.
The risk engine is a pure function of the order, the portfolio (with every outstanding order counted as filled) and market statistics. No language model can change its answer. Controls manage risk; they cannot eliminate losses.
Thirteen checks
Every order, every time
kill_switch
Trading halted while the kill switch is engaged (fail-closed if its state cannot be read).
shorting
Sells may never exceed settled holdings minus pending sells; no short positions.
buying_power
Cash must cover the order plus every outstanding buy.
position_size
Single-name weight cap.
sector_exposure
Sector weight cap.
gross_exposure
Gross exposure cap (no leverage).
net_exposure
Net exposure cap.
portfolio_beta
Portfolio beta cap.
daily_loss
New risk halted after the daily loss limit.
max_drawdown
New risk halted beyond the drawdown limit.
liquidity_adv
Order size versus 20-day average volume.
liquidity_dollar_volume
Minimum average daily traded value.
correlation_concentration
Cap on weight in highly correlated names.
services/risk-engine/src/hf_risk/engine.py
Current policy
Limits in force
Read live from risk engine v1.0.0
- Max position
- 5%
- Max sector
- 25%
- Max gross exposure
- 1×
- Max net exposure
- 1×
- Max portfolio beta
- 1.3
- Daily loss limit
- 3%
- Drawdown kill level
- 15%
- Max order / 20-day volume
- 1%
- Min 20-day $ volume
- $5M
- Correlation threshold
- 0.85
- Max correlated cluster
- 15%
- Short selling
- Disabled
Workflow
Approval workflow
- A proposal is risk-checked; a rejection is final and recorded with reason codes.
- An approved risk check must be followed by a named human approval within 30 minutes, or the order expires.
- The approval is bound to a hash of the exact order payload; any change after approval rejects the order.
- Risk is re-evaluated at the live price immediately before submission.
- An optional autonomy envelope — granted, capped and revocable by a human — can approve strategy orders within per-order, per-day and permitted-security limits. Webhook-originated orders always need a person.
Kill switch
Stored in Redis with a durable database record. If its state cannot be read, trading is treated as halted. The assistant may engage it; only a human may release it. Loss limits and reconciliation mismatches also revoke autonomy automatically.
Audit trail
Every proposal, risk decision, approval, submission, fill and kill-switch change is written to a hash-chained, append-only audit log under a correlation ID.