Wednesday, October 23, 2019

000 - Start of the Python-Backetst Blog

00_project_goals

Purpose

The purpose of this blog is to chronicle my attempt to learn the fundamentals of Python.

In the past, I've picked-up languages haphazardly. I'd learn enough to get started, and then I'd focus only on specific areas of interest. By doing so, I would ignore large (and possibly important) swaths of the language.

This time, I want to learn the core elements of Python in a systematic manner. I will start by working through Learning Python (5th Edition) by Mark Lutz. I'm also reading the Python for Everybody text. At some point I'll dig into the book Pandas for Everyone, too.

I do not intend to rehash the examples described in those books. Instead, my plan is to use what I learn to build a set of tools that will automate option strategy backtests. Basically, the goal is to reproduce and expand upon the excellent research published by tastytrade.

My toolkit will be used to sift through historical option pricing data and test the performance of various option buying and/or selling strategies. I've purchased (from the Chicago Board Options Exchange) a data set that contains roughly 14 years of daily historical prices for options on the SPX. I will start with those data and see how things go.

Goals

The goals of this project are fairly basic. I want to develop an option strategy backtesting tool using Python. The end product should have these features.

  1. It should allow a user to select from a menu of choices, including:

    • The ability to select different backtest windows (e.g., 1/1/2004 -- 12/31/2018)
    • The ability to select from a standard set of option strategies (strangles, iron condors, naked puts, etc.)
    • The ability to select entry criteria (i.e., the strike | delta of option legs, etc.)
    • The ability to select exit criteria (i.e., hold-to-expiration, manage at X% profit, manage at Y days-to-expiration, etc.)
  1. The interface should be web-based.

  2. Use Python exclusively to automate all possible tasks. Use both Spyder and Jupyter notebooks to explore, test, and execute the code.

  3. (At some point, I may expand upon these goas.)

Rough Development Plan

The following is a rough sketch of the tasks I think I will need to complete. The ordering may change over time, and I will likely add sub-tasks to the list. At this point, however, I just want to get some basic ideas down.

  1. Perform an initial review of the historical data

    • Identify and scrub obvious data anomalies
  1. Select data to use in a prototype model

    • I will expand this over time, but the initial data set should be relatively simple
  1. Augment the initial data set:

    • Compute ays-to-expiration
    • Define option keys (e.g., (Ticker)+(YYMMDD)+(C|P)+(Strike)
    • Compute daily VIX-equivalents for each option chain
    • etc
  1. Explore the data in the context of the backtesting and option pricing

    • Beyond noise in the data, what do we see in some of the key option pricing inputs
    • What are the tends in the greeks
    • What are the limitations of the data (i.e., where do bid/ask quotes become meaningless)
    • etc
  1. Develop a simple prototype backtest

    • Select a simple strategy (e.g., a strangle)
    • Select a subset of the available data (e.g., a year's worth of quotes)
    • Select a single entry criterion and a single exit criterion
    • Define the information that would be collected / produced during the backtest
    • Develop a sketch of what it would take to run the strategy across time
  1. Develop a generalized approach

    • Mostly to be determined based on the above
    • however, I know that I will need to learn more about classes and modules
  1. Future work that is too nebulous to outline at this point

    • The best choice of data storage / retrieval
    • How to set-up an interface to the backtest tools

As I encounter difficulties and learn more about Python, I will revisit these topics and augment the development plan.