Backtesting is a core daily task for a quant. Beyond calculating the total cumulative PnL, the goal of backtesting is to analyse where the PnL comes from.
In this article, we focus on backtesting options strategies, where the PnL is typically decomposed into the PnL from each Greek component:
Delta PnL: The PnL from changes in the underlying asset's price.
Gamma PnL: The PnL from changes in the option’s delta.
Vega PnL: The PnL from changes in implied volatility.
Theta PnL: The PnL from the time decay of the option.
Unexplained PnL: The difference between the total PnL and the sum of the explained PnL components.
We exclude Rho (the change in option value due to changes in the risk-free rate) as its impact is typically minimal.
Delta PnL
If an option has a delta of 0.5, a $1 increase in the underlying's price would lead to a $0.50 increase in the option's price.
df['delta_pnl'] = df['delta'].shift(1) * df['stock_price'].diff()
Gamma PnL
From the Taylor expansion, the Gamma PnL is computed using the formula below.
As gamma PnL is proportional to the square of the price change, gamma PnL is always positive for long option holders.
df['gamma_pnl'] = 0.5 * df['gamma'].shift(1) * df['stock_price'].diff().pow(2)
Vega PnL
If an option has a vega of 0.2, a 1% increase in implied volatility would increase the option's price by $0.20.
df['vega_pnl'] = df['vega'].shift(1) * df['implied_vol'].diff()
Theta PnL
If an option has a theta of -0.05, the option's price decreases by $0.05 per day. Long options positions always have negative theta (which balances out the always positive gamma PnL).
df['theta_pnl'] = df['theta'].shift(1) * df['date'].diff()
Interview Guide (OUT NOW)
What’s inside the Quant Prep Interview Guide:
Time-Saving Strategies: Proven tips to land interviews efficiently, skipping the grind of endless applications.
Interview Mastery: A step-by-step breakdown of the process, packed with best practices and winning strategies.
Salary Insights: A detailed list of front-office compensation figures.
Industry Directory: A comprehensive roundup of top financial services firms.
Real-World Prep: 6 authentic interview experiences, covering 18 rounds of questions.
Extensive Question Bank: 138 carefully curated questions spanning Finance, Probability & Statistics, Math & Linear Algebra, Python, Algorithms, and HR.
HR Excellence: Tested techniques to shine in HR interviews.
Now on Sale: Just $21.60 (VAT included) - a steep discount from the regular $39.60.
Ready to land a $200k+ quant role? Grab your copy HERE.
Other Media
Twitter: @quant_prep
Medium: @quant_prep
LinkedIn: Quant Prep
Free Stoikov Market Making Code: Here
Free BTC Options Notebook: Here
Free CV template: Here