← Back to Learn
II IntermediateWeek 4 • Lesson 11Duration: 55 min

PIP The Multi-Layer ML Pipeline

Why one model isn't enough — separation of concerns for trading

Learning Objectives

  • Understand why production trading systems use multiple model layers
  • Learn the signal → filter → exit architecture pattern
  • See how separation of concerns improves each component independently
  • Compare single-model vs multi-layer system performance characteristics

Explain Like I'm 5

Imagine hiring one person to find investment ideas, decide when to act, and manage every trade until it closes. They'd be mediocre at everything. Now hire three specialists — one for each job. Each one can be world-class at their specific task. That's the multi-layer pipeline.

Think of It This Way

A hospital doesn't have one doctor who diagnoses, operates, and does rehab. They have specialists at each stage because the skills are completely different. Same logic applies to trading: finding a signal, timing the entry, and managing the exit are fundamentally different problems that deserve different models.

1Why One Model Isn't Enough

The most common approach in retail quant trading is to build a single model that outputs "buy" or "sell." Train it on features, optimize it, and deploy. Simple. It also doesn't work very well. Here's why. A single model tries to solve three different problems simultaneously: 1. Is there a tradeable pattern right now? (signal detection) 2. Should I actually enter, or is the timing terrible? (entry filtering) 3. When do I get out? (exit management) These are fundamentally different tasks. Signal detection needs pattern recognition across many features. Entry filtering needs to assess market conditions and timing. Exit management needs to track trade evolution in real time. Forcing one model to do all three creates a mediocre compromise. Splitting them into separate layers — each optimized for its specific job — produces a system that's better at every stage. This isn't a novel idea. Software engineering has used separation of concerns for decades. The insight is applying it to ML trading systems. Caruana, R. (1997). "Multitask Learning." Machine Learning, 28(1), 41-75.

2The Three Layers

A production ML trading system typically has three distinct layers: Layer 1 — Signal Detection. Scans the market for candidate trading opportunities. Processes price action, momentum, volatility, and regime features through a classification model. Outputs a probability: how likely is this a genuine opportunity? Layer 2 — Entry Filter. Takes L1's candidates and asks: "Should we actually enter right now?" Considers timing, spread conditions, recent performance, and regime context. Many L1 signals get filtered out here — and that's the point. Quality over quantity. Layer 3 — Exit Management. Once you're in a trade, a separate model manages it. Tracks how the trade is evolving, monitors regime changes, and decides when to close — either at a profit target or to cut losses. Different problem, different model. Each layer can be independently improved, tested, and validated without breaking the others. Change L1's feature set? L2 and L3 don't care. Improve L3's exit timing? L1 and L2 keep working exactly the same.

Signal Funnel: How Candidates Get Filtered

3Single-Model vs Multi-Layer — The Numbers

Does this actually improve results? Yes, and the difference is meaningful. A well-tuned single model might achieve 52-54% win rate on clean data. A multi-layer system with the same underlying features typically gets into the high 50s. That might sound small, but in trading, a few percentage points of win rate compound into dramatically different equity curves over thousands of trades. Why the improvement? Two reasons: 1. Better filtering. L2 rejects poor-quality L1 signals. The trades you actually take have higher average quality. 2. Better exits. L3 manages each trade based on its specific evolution rather than using fixed stop-loss/take-profit levels. Adaptive exits capture more profit in trending moves and cut losses faster in mean-reverting conditions. The downside is complexity. Three models means three things to validate, three things that can break, three things to monitor in production. But the performance improvement justifies it.

Equity Curve: Single Model vs Multi-Layer Pipeline (Normalized)

4Practical Considerations

Building a multi-layer system is harder than building a single model. Here's what to watch for: Data leakage between layers. L2 should not see L3 outcome data. L3 should not be trained on L1 features that were already used for filtering. Keep the information flow clean. Coordination problems. The layers need to communicate but not create circular dependencies. L1 outputs a probability. L2 takes that probability plus its own features and makes a binary decision. L3 takes the entered trade and manages it independently. Validation complexity. You can't just validate L1 in isolation — you need to test the full pipeline together. A great L1 with a bad L2 produces worse results than a decent L1 with a good L2. Model retraining. Each layer may need different retraining frequencies. L1 might retrain monthly. L2 might need weekly updates. L3 might be stable for longer periods. You need infrastructure for independent retraining. Don't let the complexity scare you. Start with L1. Get it working. Then add L2 filtering. Then L3 exits. Build incrementally. Wolpert, D.H. (1992). "Stacked Generalization." Neural Networks, 5(2), 241-259.

5Why This Architecture Scales

The multi-layer approach has another advantage people overlook: it scales cleanly across different markets. Each market cluster (forex, metals, indices, crypto) can have its own L1 model trained on cluster-specific patterns. L2 can have cluster-specific entry rules. L3 can adapt exit strategies to the typical behavior of each cluster. You end up with a family of models rather than one monolithic system. New market? Train a new L1 for that cluster, reuse the L2 and L3 architecture, and you're live. This modularity is borrowed directly from software engineering. Replace components without rebuilding the whole thing. Test components in isolation. Deploy updates incrementally. The same principles that make large codebases maintainable also make large trading systems maintainable.

Key Formulas

L1 Signal Probability

L1 takes a feature vector x_t and outputs a probability. Above a threshold → candidate signal. The threshold is tuned per market cluster based on validation data.

Pipeline Expected Value

Expected return per candidate signal. Each layer filters, so fewer trades are taken but each one has higher expected value. The product of pass rates times conditional expected return determines overall system profitability.

Hands-On Code

Multi-Layer Pipeline Skeleton

python
class TradingPipeline:
    """Three-layer ML trading pipeline."""
    
    def __init__(self, l1_model, l2_model, l3_model):
        self.l1 = l1_model  # Signal detection
        self.l2 = l2_model  # Entry filter
        self.l3 = l3_model  # Exit management
    
    def evaluate_signal(self, features):
        """Run a candidate through all three layers."""
        # Layer 1: Is there a signal?
        l1_prob = self.l1.predict_proba(features)
        if l1_prob < self.l1.threshold:
            return None  # No signal
        
        # Layer 2: Should we enter?
        l2_context = {
            'l1_probability': l1_prob,
            'spread': features['spread'],
            'regime': features['regime'],
            'recent_performance': self.get_recent_stats(),
        }
        l2_decision = self.l2.predict(l2_context)
        if l2_decision == 'SKIP':
            return None  # Signal exists but timing is wrong
        
        # Layer 3 activates after entry
        return {
            'action': 'ENTER',
            'confidence': l1_prob,
            'l3_params': self.l3.get_exit_params(features),
        }
    
    def manage_open_trade(self, trade, current_features):
        """L3 manages the trade after entry."""
        exit_signal = self.l3.evaluate(trade, current_features)
        if exit_signal['should_exit']:
            return {'action': 'EXIT', 'reason': exit_signal['reason']}
        return {'action': 'HOLD'}

Each layer has a single responsibility. L1 finds opportunities. L2 decides timing. L3 manages the trade. This separation makes the system easier to improve, test, and debug.

Knowledge Check

Q1.Why does a multi-layer pipeline outperform a single model?

Q2.What's the main risk of a multi-layer architecture?

Assignment

Design a three-layer pipeline on paper. For each layer, specify: (1) what inputs it takes, (2) what output it produces, (3) what model type you'd use, and (4) how you'd validate it independently. Don't build it yet — just think through the architecture.