Trading Strategies
30 essential concepts in trading strategy development and ML4T
What You'll Learn
Master trading strategy development with 30 comprehensive flashcards covering manual strategies, strategy learners, Q-learning, Sharpe ratio, portfolio metrics, and ML4T Projects 6 & 8. Learn TOS, position management, overfitting prevention, and backtesting best practices.
Key Topics
- Manual strategies vs Strategy Learners comparison
- Theoretically Optimal Strategy (TOS) benchmark
- Q-Learning for trading with query vs querySetState
- Portfolio metrics: Sharpe Ratio, cumulative returns, volatility
- Transaction costs and market impact modeling
- Overfitting detection and prevention in trading
Looking for more finance resources? Visit the Explore page to browse related decks or use the Create Your Own Deck flow to customize this set.
How to study this deck
Start with a quick skim of the questions, then launch study mode to flip cards until you can answer each prompt without hesitation. Revisit tricky cards using shuffle or reverse order, and schedule a follow-up review within 48 hours to reinforce retention.
Preview: Trading Strategies
Question
What is a Manual Strategy in Project 6?
Answer
Rule-based trading approach using technical indicators: 1. Combine 3+ indicators from Project 6 2. Define explicit entry/exit rules 3. Generate positions: -1000, 0, +1000 shares 4. No machine learning involved 5. Deterministic (same inputs → same outputs)
Question
What are the three valid position states in Projects 6 & 8?
Answer
-1000 shares: SHORT position (betting price goes down) 0 shares: NO position (out of market) +1000 shares: LONG position (betting price goes up) Cannot hold any other values. Must transition only between these three states.
Question
What is Theoretically Optimal Strategy (TOS)?
Answer
Benchmark strategy that assumes PERFECT FUTURE KNOWLEDGE: - Knows tomorrow's price today - Always buys before price increases - Always sells before price decreases - Represents upper bound on performance - Used to compare against Manual and Strategy Learner - Position limits: -1000, 0, +1000
Question
How does TOS generate positions?
Answer
For each day t: IF price[t+1] > price[t]: Hold LONG (+1000) ELSE IF price[t+1] < price[t]: Hold SHORT (-1000) ELSE: Hold previous position Perfect foresight → optimal possible returns (ignoring transaction costs)
Question
What is a Strategy Learner (Project 8)?
Answer
ML-based trading strategy that learns from historical data: Three implementation approaches: 1. Classification-based (Random Forest) 2. Reinforcement Learning (Q-Learning) 3. Optimization-based (with classifier or RL) Learns patterns in indicators to predict price movements and generate trades.
Question
What are the three Strategy Learner implementation approaches?
Answer
1. Classification-Based Learner: - Random Forest classifier - Min leaf_size = 5 - Predict UP/DOWN from indicators 2. Reinforcement Learning (Q-Learning): - Learn optimal trading policy - States: Market conditions - Actions: Buy/Sell/Hold 3. Optimization-Based: - Scan + optimize parameters - Combined with classifier or RL
Question
What is the critical rule for testPolicy() in Project 8?
Answer
testPolicy() must produce IDENTICAL output for consecutive calls with same inputs. Why: - testPolicy() = TESTING only (no learning/updating) - Must be deterministic and reproducible - Separates training (addEvidence) from testing - No learner updates allowed in testPolicy()
Question
For Q-Learner, which method should be used in testPolicy(): query() or querySetState()?
Answer
Use querySetState() in testPolicy() querySetState(): - Queries learned policy WITHOUT updating Q-values - Read-only operation - For testing only query(): - Updates Q-values (learning) - Only use in addEvidence() during training
Question
What is the difference between addEvidence() and testPolicy()?
Answer
addEvidence() - TRAINING: - Learn from historical data - Update model parameters - Can be called multiple times - No output required testPolicy() - TESTING: - Apply learned strategy - NO updates to model - Must be deterministic - Returns trades/positions
Question
Can you select hyper-parameters based on the symbol in Project 8?
Answer
NO. This is explicitly forbidden. Cannot do: if symbol == 'JPM': use leaf_size = 5 elif symbol == 'AAPL': use leaf_size = 10 Must use same hyper-parameters for all symbols. Why: Prevents overfitting to specific stocks.
Question
What are transaction costs and how do they affect strategies?
Answer
Two components: 1. Commission: Fixed cost per trade (e.g., $9.95) 2. Market Impact: Proportional to trade size - Cost = impact × |shares| - Larger trades = higher cost Effects: - Reduce net returns - Penalize high-frequency trading - Favor lower-frequency strategies - Must balance signal quality with trade frequency
Question
What is market impact and why is it important?
Answer
Market Impact: Your trade moves the price against you Larger trade → bigger price movement → worse execution price Cost = impact_coefficient × |shares| Experiment 2 (Project 8): - Test strategy with varying impact - How does performance degrade? - Does strategy adapt to higher costs? Realistic backtesting requires impact modeling
Question
What should Experiment 1 in Project 8 demonstrate?
Answer
Compare In-Sample vs Out-of-Sample performance: 1. Train on in-sample period 2. Test on both periods 3. Demonstrate: - Strategy works in-sample - How well it generalizes out-of-sample - Whether overfitting occurred Expected: In-sample > Out-of-sample performance
Question
What should Experiment 2 in Project 8 demonstrate?
Answer
Test strategy behavior under varying market impact: 1. Run strategy with different impact values (e.g., 0, 0.005, 0.01) 2. Show: - How returns degrade with higher impact - Number of trades changes - Strategy adaptation (if any) Expected: Higher impact → lower returns, possibly fewer trades
Question
What is Cumulative Return and how is it calculated?
Answer
Cumulative Return (CR) = (Portfolio Value[end] / Portfolio Value[start]) - 1.0 OR CR = (Final Value - Initial Value) / Initial Value Measures total return over period. Example: CR = 0.50 means 50% gain CR = -0.20 means 20% loss
Question
What is Average Daily Return?
Answer
Average Daily Return (ADR) = Sum(daily_returns) / Number of days Daily Return[t] = (Value[t] / Value[t-1]) - 1.0 Measures typical daily performance. Used in Sharpe ratio calculation.
Question
What is Standard Deviation of Daily Returns?
Answer
Std Dev = √(Variance of daily returns) Measures volatility/risk: - Higher std dev = more volatile, riskier - Lower std dev = more stable Used as denominator in Sharpe ratio. Key risk metric in portfolio evaluation.
Question
What is the Sharpe Ratio and how is it calculated?
Answer
Sharpe Ratio = (Mean Daily Return - Risk Free Rate) / Std Dev of Daily Returns SR = (R̄ - Rf) / σ Measures risk-adjusted return: - Higher is better - SR > 1: Good - SR > 2: Very good - SR > 3: Excellent Accounts for volatility, not just raw returns
Question
Why is Sharpe Ratio better than raw returns for comparing strategies?
Answer
Raw returns ignore RISK: - Strategy A: 50% return, high volatility - Strategy B: 30% return, low volatility Which is better? Depends on risk tolerance. Sharpe Ratio: - Adjusts for risk (volatility) - Allows fair comparison - Higher SR = better risk-adjusted performance - Industry standard metric
Question
What is the typical risk-free rate assumption in ML4T?
Answer
Often assumed to be 0.0 for simplicity in projects. Realistically: - Treasury bill rate (e.g., 3-month T-bill) - ~0-5% annually - ~0-0.02% daily Using Rf = 0 simplifies calculations: SR = Mean Daily Return / Std Dev
Question
What does it mean to normalize portfolio values to 1.0?
Answer
Divide all portfolio values by initial value: normalized[t] = portfolio_value[t] / portfolio_value[0] Why: - Easy comparison across strategies - All start at 1.0 - Final value shows cumulative return directly - Standard for visualization Example: Final value 1.5 = 50% cumulative return
Question
What are the typical benchmark comparisons in Projects 6 & 8?
Answer
1. Benchmark (SPY or symbol buy-and-hold): - Buy $100,000 of symbol at start - Hold until end 2. Theoretically Optimal Strategy: - Perfect foresight upper bound 3. Manual Strategy (Project 6): - Your rule-based approach 4. Strategy Learner (Project 8): - Your ML approach Compare all using same metrics (CR, SR, etc.)
Question
How do you calculate portfolio value from trades?
Answer
Start with cash (e.g., $100,000) and 0 shares. For each trade: 1. Update shares: shares += trade 2. Update cash: cash -= trade × price × (1 + impact) 3. Subtract commission if trade ≠ 0 Portfolio Value[t] = cash + shares × price[t] Track daily portfolio values for metrics.
Question
What is the difference between trades and holdings?
Answer
Trades (orders): - Changes in position - Example: [1000, 0, -2000, 0, 1000] - Can be any value Holdings (positions): - Current shares held - Example: [1000, 1000, -1000, -1000, 0] - For Projects 6 & 8: only -1000, 0, +1000 holdings[t] = holdings[t-1] + trades[t]
Question
What is a long position and when would you enter it?
Answer
Long Position: +1000 shares - Profit when price increases - Loss when price decreases Enter when: - Bullish indicators (expecting price rise) - RSI oversold + price at BB lower band - Golden Cross (SMA crossover) - Positive momentum building
Question
What is a short position and when would you enter it?
Answer
Short Position: -1000 shares - Profit when price decreases - Loss when price increases - Borrow shares, sell high, buy back low Enter when: - Bearish indicators (expecting price fall) - RSI overbought + price at BB upper band - Death Cross (SMA crossover) - Negative momentum building
Question
What are the typical in-sample and out-of-sample periods in Projects 6 & 8?
Answer
In-Sample (Training): - January 1, 2008 - December 31, 2009 - Used for training learner - Optimizing rules/parameters Out-of-Sample (Testing): - January 1, 2010 - December 31, 2011 - Testing generalization - No training/updates allowed Strict separation prevents look-ahead bias
Question
What is overfitting in trading strategies and how do you detect it?
Answer
Overfitting: Strategy works great in-sample but fails out-of-sample Causes: - Too many parameters - Too complex rules - Optimized for noise, not signal Detection: - Large gap between in-sample and out-of-sample performance - In-sample: 80% return - Out-of-sample: -10% return Solution: Simpler strategies, regularization, cross-validation
Question
What visualization standards should be followed in Projects 6 & 8?
Answer
Required elements: 1. Normalize to 1.0 at start 2. Proper title describing what's shown 3. Legend identifying each line 4. X-axis: Date, Y-axis: Normalized Portfolio Value 5. Color consistency: - Purple: Benchmark - Red: Theoretically Optimal - Green: Manual/Strategy Learner 6. Vertical lines for trade signals (optional)
Question
How do you combine a Manual Strategy with a Strategy Learner?
Answer
Hybrid approaches: 1. Ensemble: - Run both strategies - Average signals or take majority vote 2. Filter: - Use Manual Strategy rules as filter - Only trade when ML confirms 3. Regime-based: - Manual Strategy in trending markets - ML Strategy in ranging markets Not required in projects but can improve robustness
Question
What is look-ahead bias and how do you avoid it?
Answer
Look-Ahead Bias: Using future information in past decisions Examples: - Using today's close to calculate today's indicator - Training on entire dataset including test period - Selecting parameters based on out-of-sample results Avoid: - Only use information available at decision time - Strict in-sample/out-of-sample separation - No peeking at test data during development
Question
What metrics should you report when comparing strategies?
Answer
Required metrics: 1. Cumulative Return (CR) 2. Standard Deviation of Daily Returns (volatility) 3. Average Daily Return 4. Sharpe Ratio (risk-adjusted return) 5. Final Portfolio Value Optional: 6. Number of trades 7. Maximum drawdown 8. Win rate 9. Average win/loss