Option FanaticOptions, stock, futures, and system trading, backtesting, money management, and much more!

Time Spread Backtesting in Python (Part 1)

Recently, I did a blog mini-series manually backtesting the COVID-19 crash with time spreads. I left off suggesting backtesting of a slightly rather than extremely bullish time spread as more representative of the long-term market.

One benefit to manual backtesting is a closer look at the day-by-day PnL of each and every trade. Seeing this is a closer approximation to live trading than only seeing the trade result.

Ultimately though, Python is where I want to be for automation, for efficiency, and for all of my backtesting needs. Manual backtesting takes much longer. It also requires me to go back and do many other calculations whenever I want a slightly different look at the data, whenever I want to calculate additional trade statistics, etc.

For me as a beginner, Python has a big temporal cost. That won’t change unless I work consistently to improve my skills.

I want to try and organize my thoughts about this backtesting and maybe come up with a flow chart before I actually try writing any code. I’ve been advised this can help prevent me from getting stranded in the weeds spending lots of time ironing out bugs that aren’t all that important.

This might be a decent time to start transitioning to Python since I’ve been backtesting in ONE and have a fresh sense of what the process entails.

Part of the process I won’t have with Python includes risk-graph management, which is prominently displayed in ONE. Without programming Black-Scholes (way too difficult for my current proficiency), I won’t have any ability to model the trade in Python. I therefore won’t see a profit tent, day steps, or PnL breakevens. I can’t reject the possibility this affects my [manually backtested] Practice Trades, but no risk graph information is called by trade guidelines so hopefully this isn’t an issue.

The .csv data file includes greeks, which will allow for some common techniques of trade management.

To start, I need to think about what I want the program to output and what it will take as input. Here is a snippet of the option data file that gets purchased as .csv archives:

Option data file snippet (12-30-21)

The actual data file has more columns. For time spreads, I will need all greeks but gamma along with IV.

The spreadsheet column headers I have been using in recent manual backtesting provide a starting point for the kind of data I’m looking to collect. Reading down:

Date
Trade #
ONE Trade #
DTE
SPX
MR
Theta
TD
IV
Horiz Skew %
NPD
NPV
MDD %
DTE
Max MR
# Adj
Exit DTE
PnL
ROI
SD Chg
IV Chg
DIT
Horiz Skew %
TD
Comments

I will continue next time.

No comments posted.

Leave a Reply

Your email address will not be published. Required fields are marked *