Risk Management Guide
This guide covers position sizing strategies and risk control in Matchstick.
Overview
Risk management determines how much capital to allocate to each trade. Good risk management protects your portfolio from large losses while allowing profitable trades to compound.
Position Sizing Strategies
Fixed Position Size
Trade a fixed dollar amount or number of shares.
[risk]
position_size = "fixed"
fixed_amount = 1000.0 # $1,000 per tradeUse case: Simple, predictable position sizes. Good for testing strategies.
Percent of Capital
Risk a fixed percentage of your total capital per trade.
[risk]
position_size = "percent"
percent_of_capital = 2.0 # 2% of portfolio per positionUse case: Positions scale with account size. Standard approach for most traders.
Kelly Criterion
Optimal position size based on win rate and payoff ratio.
[risk]
position_size = "kelly"
kelly_fraction = 0.25 # Use 25% of Kelly for safetyKelly formula: f* = (bp - q) / b
b= odds received (win/loss ratio)p= probability of winningq= probability of losing (1 - p)
Use case: Mathematically optimal growth. Often fractional Kelly (25-50%) is used for safety.
ATR-Based Position Size
Size positions based on current volatility.
[risk]
position_size = "atr"
atr_period = 14
atr_multiplier = 2.0
max_risk_per_trade = 1.0 # 1% of capital at riskFormula: position_size = (capital * risk_percent) / (atr * multiplier)
Use case: Adapts to volatility. Smaller positions in volatile markets, larger in calm markets.
Risk Metrics
Portfolio-Level Metrics
Matchstick tracks several portfolio metrics:
Portfolio Metrics
=================
Total Value: $105,234.50
Cash: $45,234.50
Equity: $60,000.00
Margin Used: $0.00
Buying Power: $90,469.00
Risk Metrics:
Max Drawdown: -5.2%
Current DD: -1.8%
Sharpe Ratio: 1.35
Win Rate: 58.3%Per-Position Metrics
Each position tracks:
| Metric | Description |
|---|---|
| Entry Price | Average price of position |
| Current Price | Last market price |
| Unrealized P&L | Open profit/loss |
| Realized P&L | Closed profit/loss |
| Position % | Percent of portfolio |
| Risk Amount | Dollar amount at risk to stop loss |
Stop Loss Strategies
Fixed Percentage Stop
Exit if price drops by a fixed percentage:
[exit]
stop_loss = 2.0 # Exit if down 2%ATR-Based Stop
Dynamic stop based on volatility:
[exit]
stop_type = "atr"
atr_period = 14
atr_multiplier = 2.0 # Stop at 2x ATR below entryTrailing Stop
Follows price upward, locks in gains:
[exit]
trailing_stop = 1.5 # Trail by 1.5%Time-Based Exit
Exit after a certain number of bars:
[exit]
max_hold_bars = 20 # Exit after 20 bars regardlessTake Profit Strategies
Fixed Target
Exit at a predetermined profit:
[exit]
take_profit = 4.0 # Exit when up 4%Risk-Reward Ratio
Set target as multiple of stop loss:
[exit]
stop_loss = 1.0
risk_reward_target = 3.0 # Target = 3x the risk (3%)Partial Exits
Scale out of positions at multiple levels:
[exit.scaled]
levels = [
{ target = 2.0, quantity = 0.33 }, # Sell 33% at 2%
{ target = 4.0, quantity = 0.33 }, # Sell 33% at 4%
{ target = 6.0, quantity = 0.34 } # Sell remaining at 6%
]Portfolio Constraints
Maximum Positions
Limit total number of open positions:
[risk]
max_positions = 10Maximum Exposure
Limit total invested capital:
[risk]
max_exposure = 80.0 # Maximum 80% investedSector/Asset Limits
Prevent concentration in one area:
[risk.limits]
max_per_sector = 20.0 # Max 20% in any sector
max_per_symbol = 5.0 # Max 5% in any single stockCorrelation Limits
Avoid correlated positions:
[risk.correlation]
max_correlation = 0.7 # Reject positions with >0.7 correlation to existingRisk Management Best Practices
The 1% Rule
Never risk more than 1% of your portfolio on a single trade:
Risk per trade = Position size × (Entry - Stop) / Entry
Target: Risk per trade ≤ 1% of portfolioThe 2% Rule
Never have more than 2% of your portfolio at risk at any time:
Total risk = Sum of all position risks
Target: Total risk ≤ 2% of portfolioDrawdown Limits
Reduce position sizes after losses:
[risk.drawdown_rules]
reduce_at = 5.0 # Reduce to 50% size at 5% drawdown
halt_at = 10.0 # Stop trading at 10% drawdownPosition Sizing Checklist
Before each trade, verify:
- [ ] Position size fits within max per-symbol limit
- [ ] Total exposure after trade within max exposure
- [ ] Risk amount within per-trade risk limit
- [ ] Total portfolio risk within maximum
- [ ] Not adding correlated positions
Example: Conservative Risk Configuration
Complete example for a conservative approach:
# strategies/conservative.toml
[risk]
# Position sizing
position_size = "atr"
atr_period = 14
atr_multiplier = 2.0
max_risk_per_trade = 0.5 # 0.5% per trade
# Portfolio limits
max_positions = 8
max_exposure = 60.0
max_per_symbol = 8.0
[exit]
stop_loss = 2.0
trailing_stop = 1.0
take_profit = 6.0 # 3:1 reward-to-risk
[risk.drawdown_rules]
reduce_at = 3.0
halt_at = 6.0CLI Commands
Check portfolio risk:
matchstick risk checkCalculate position size:
matchstick risk size --symbol AAPL --capital 100000 --risk 1.0Show current exposure:
matchstick risk exposureNext Steps
- Backtesting Guide - Test risk parameters
- Indicators Guide - ATR for volatility-based sizing
- CLI Commands Reference - All risk commands