Skip to content

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.

toml
[risk]
position_size = "fixed"
fixed_amount = 1000.0  # $1,000 per trade

Use case: Simple, predictable position sizes. Good for testing strategies.

Percent of Capital

Risk a fixed percentage of your total capital per trade.

toml
[risk]
position_size = "percent"
percent_of_capital = 2.0  # 2% of portfolio per position

Use case: Positions scale with account size. Standard approach for most traders.

Kelly Criterion

Optimal position size based on win rate and payoff ratio.

toml
[risk]
position_size = "kelly"
kelly_fraction = 0.25  # Use 25% of Kelly for safety

Kelly formula: f* = (bp - q) / b

  • b = odds received (win/loss ratio)
  • p = probability of winning
  • q = 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.

toml
[risk]
position_size = "atr"
atr_period = 14
atr_multiplier = 2.0
max_risk_per_trade = 1.0  # 1% of capital at risk

Formula: 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:

MetricDescription
Entry PriceAverage price of position
Current PriceLast market price
Unrealized P&LOpen profit/loss
Realized P&LClosed profit/loss
Position %Percent of portfolio
Risk AmountDollar amount at risk to stop loss

Stop Loss Strategies

Fixed Percentage Stop

Exit if price drops by a fixed percentage:

toml
[exit]
stop_loss = 2.0  # Exit if down 2%

ATR-Based Stop

Dynamic stop based on volatility:

toml
[exit]
stop_type = "atr"
atr_period = 14
atr_multiplier = 2.0  # Stop at 2x ATR below entry

Trailing Stop

Follows price upward, locks in gains:

toml
[exit]
trailing_stop = 1.5  # Trail by 1.5%

Time-Based Exit

Exit after a certain number of bars:

toml
[exit]
max_hold_bars = 20  # Exit after 20 bars regardless

Take Profit Strategies

Fixed Target

Exit at a predetermined profit:

toml
[exit]
take_profit = 4.0  # Exit when up 4%

Risk-Reward Ratio

Set target as multiple of stop loss:

toml
[exit]
stop_loss = 1.0
risk_reward_target = 3.0  # Target = 3x the risk (3%)

Partial Exits

Scale out of positions at multiple levels:

toml
[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:

toml
[risk]
max_positions = 10

Maximum Exposure

Limit total invested capital:

toml
[risk]
max_exposure = 80.0  # Maximum 80% invested

Sector/Asset Limits

Prevent concentration in one area:

toml
[risk.limits]
max_per_sector = 20.0  # Max 20% in any sector
max_per_symbol = 5.0   # Max 5% in any single stock

Correlation Limits

Avoid correlated positions:

toml
[risk.correlation]
max_correlation = 0.7  # Reject positions with >0.7 correlation to existing

Risk 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 portfolio

The 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 portfolio

Drawdown Limits

Reduce position sizes after losses:

toml
[risk.drawdown_rules]
reduce_at = 5.0    # Reduce to 50% size at 5% drawdown
halt_at = 10.0     # Stop trading at 10% drawdown

Position 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:

toml
# 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.0

CLI Commands

Check portfolio risk:

bash
matchstick risk check

Calculate position size:

bash
matchstick risk size --symbol AAPL --capital 100000 --risk 1.0

Show current exposure:

bash
matchstick risk exposure

Next Steps

Built for traders who value data provenance.