How to Calculate Profit and Loss (P&Ls) for Your Trading Strategies (Hint: it’s not as easy as you think)

Quantitative Trading Toolbox | Python for Financial Analysis

AAA Quants
4 min readNov 19, 2020
Quantitative Trading Like a Pro: Essential Python Course

Calculating Profit and Loss (P&L) for your trading strategy can be surprisingly tricky at times. Traders are often surprised when their calculations of realised and unrealised P&Ls don’t match up. Today let’s see how it can be done by going through a Moving Average (MA) Crossover strategy.

To start with we create an arbitrary price series from normally distributed random numbers. Of course, you could also use market data from your favourite instrument, it doesn’t matter so much here as we are focussed on calculating strategy P&L curves.

Backtesting for the MA Crossover Strategy

In the next step we create a backtest. In this backtest, we loop through our price data, calculate two moving averages and whenever the two moving averages cross we change from short to long and vice versa.

--

--

AAA Quants

AI, Quantitative Analysis and Data Science Solutions for Finance