Documentation

Backtest & Optimize

How partiqon tests strategies on historical data, finds optimal parameters, and validates robustness. Includes backtesting, optimization, walk-forward validation, and WFO.

Backtesting

A backtest simulates a strategy on historical data. For each bar, we check if entry or exit signals fire, and record all trades with their P&L. No real money is used — it's pure simulation to measure past performance.

How It Works

  1. Load data: Historical bars (OHLCV) from BAR6 files
  2. Reset state: Strategy parameters, indicators, and positions reset to start
  3. Iterate bars: For each bar in the period, feed it to the strategy
  4. Check signals: Does the strategy generate entry or exit signals?
  5. Execute trades: Entry opens a position; exit closes it. Record entry/exit price, P&L
  6. Calculate metrics: Win rate, drawdown, profit factor, etc.
  7. Output results: Trade list, equity curve, performance statistics

Key Metrics

⚠ Important: Backtest results are historical. They show what happened in the past, not what will happen in the future. Markets change; strategies that worked yesterday may not work today. Always validate on out-of-sample (future) data before trading live.

PSO Optimization

PSO (Particle Swarm Optimization) is a search algorithm that finds good parameter values automatically. Instead of trying random combinations, particles "swarm" toward the best regions of the parameter space.

How PSO Works

  1. Define searchable parameters: Which block parameters can be tuned? (e.g., EMA period 10–100, RSI level 20–50)
  2. Initialize swarm: Create N particles, each with random parameter values (e.g., 30 particles)
  3. Evaluate each particle: Run a backtest with those parameters. Record profit factor (or your chosen metric)
  4. Track best: Each particle remembers its best result ever. The swarm remembers the global best.
  5. Update velocities: Each particle adjusts its parameters toward its personal best and the global best (with randomness)
  6. Repeat: Run multiple generations (e.g., 60 iterations). The swarm converges toward good parameters.
  7. Return champion: The best parameters found across all generations

Why PSO?

Iteration 1: particles → backtest → evaluate Iteration 2: particles move toward best → backtest → evaluate Iteration 3: particles move again → backtest → evaluate ... Iteration 60: final positions → return best

Walk-Forward Validation

Walk-forward validation prevents overfitting by splitting data into blocks: optimize on the first block (in-sample), then test on the second block (out-of-sample), but never mix them.

The Problem: Overfitting

If you optimize on all your data, you can fit the noise in that specific history. The parameters look great on the past but fail on the future. Walk-forward breaks the data to catch this.

Walk-Forward Process

  1. Define blocks: Split your 5-year history into 3 blocks (e.g., each ~1.5 years)
  2. Block 1 (in-sample): Run PSO optimization on this period. Find best parameters.
  3. Block 2 (out-of-sample): Test those best parameters on the next block. How do they perform on unseen data?
  4. Block 3 (out-of-sample): Slide the window. Use Block 2 to optimize; test on Block 3.
Period: [====== Block 1 ======] [====== Block 2 ======] [====== Block 3 ======] In-Sample optimization ──────────→ then test unseen data on Block 2 Optimize ──────────→ then test unseen data on Block 3

Interpreting Results

Walk-Forward Optimization (WFO)

WFO combines walk-forward validation with optimization: optimize on each in-sample block, then test the result on the next out-of-sample block. This simulates real trading where you re-optimize periodically.

WFO Process

  1. Split data: 3 blocks (or more). Blocks 1, 2, 3 for example.
  2. Cycle 1: Optimize on Block 1 (in-sample) → test optimized params on Block 2 (out-of-sample)
  3. Cycle 2: Optimize on Block 2 (in-sample) → test optimized params on Block 3 (out-of-sample)
  4. Aggregate results: Combine all out-of-sample trades from cycles 1, 2, etc.
  5. Calculate metrics: Profit factor, drawdown, etc. on the full aggregated out-of-sample result
💡 Key insight: WFO tells you: "If I re-optimize every quarter, what's my realistic future performance?" It's closest to how traders actually use optimization: not a one-time fit, but continuous re-fitting to live market conditions.

WFO Interpretation

Strategy Development Workflow

The recommended approach:

  1. Build: Design your strategy using blocks in the graph editor
  2. Test: Run a simple backtest with default parameters (2020–2026)
  3. Optimize: Run PSO on a clean in-sample block (e.g., 2020–2023)
  4. Validate: Backtest the optimized params on out-of-sample (2023–2026). Profit factor >1.0?
  5. Walk-Forward: Run WFO with 3 blocks. Profit factor >1.5 and consistent? Ready to trade.
  6. Paper trade: Demo the strategy on live data for 1–2 weeks before real money
  7. Redeploy: Every quarter, run WFO again on the latest data to re-optimize parameters

Common Pitfalls

Next Steps

Ready to build a strategy? Start in the graph editor on the /graph page. Or read the block reference to understand what's available.