Skip to content
All library documents

Trade-Level Backtest P&L and Performance Analysis

Code Quant course library

Summary

This document demonstrates how to turn a backtest’s sequence of fills into completed trade records. It accumulates signed position, traded value, and price-based profit and loss until exposure returns to zero, then derives each trade’s duration, volume, turnover, and closing direction. Commission and slippage assumptions are applied to estimate net results.

The resulting series is used to calculate balance, log returns, drawdown, win rate, average outcomes, holding time, and long-only versus short-only statistics, with plots for balance and trade P&L. The example runs a turtle signal strategy on hourly Bitcoin pricing over a stated historical interval and supplies fee, slippage, size, and capital assumptions. These are illustrative backtest calculations; the code does not report the resulting performance figures, establish robustness, or address limitations such as partial position handling and execution realism.

Key ideas

  • Completed trades are identified when cumulative signed position returns to zero.
  • Trade P&L is adjusted for turnover-based commission and volume-based slippage assumptions.
  • Performance summaries include returns, drawdown, win rate, trade duration, and long or short breakdowns.
  • The example evaluates a turtle signal strategy on historical hourly Bitcoin data.
  • Backtest calculations depend on the supplied costs and do not establish live performance.

Tags

From a private course collection; the original is not published.