Coder Social home page Coder Social logo

nix1 / bye Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 1.0 30 KB

Backtesting Yield Estimator for Index&Stock Options. A tool for testing long-term option-based trading/investment strategies.

License: MIT License

Python 100.00%
backtest backtester backtesting backtesting-engine backtesting-trading-strategies etf-investments etfs investing investment-analysis investment-simulator investment-strategies options options-trading put-option stock-data stock-market

bye's Introduction

Backtesting Yield Estimator for Stock&Index Options

The goal of the Backtesting Yield Estimator (BYE) is to provide a simple Pythonic way to define and test option trading strategies. This tool aims to allow investors to backtest their option strategies on historical data to estimate the expected yield of their strategies (but see more info on its current state and limitations below).

The focus is on testing long-term investment strategies. Just write and HODL! ๐Ÿ“ˆ๐Ÿ’ฐ

Why?

Because I couldn't find a tool for myself, and I was disappointed by the state of open-source in this area. Let's change that!

Current Status

flake8 and pytest

๐Ÿšง POC / Exploration ๐Ÿšง

BYE is currently in its early stages of development, like a toddler learning to walk and talk. For now, it's just an experiment. But if you're interested in contributing, I'd love to have your help! ๐Ÿ™Œ Check if there are any recent contributions to see if the project is still active. If not, it may have been abandoned. ๐Ÿคทโ€

Features

Implemented Features

BYE currently only has limited support for SPY put-writing strategies based on end-of-day historical data provided by OptionsDX. The author is not affiliated with OptionsDX in any way, I just found their data to be the most convenient to work with.

Key Planned Features

One of the key planned features of BYE is the ability to generate semisynthetic option data based on real historical SPY and VIX values. This will make it much easier to test strategies without the need for actual historical option data (which might be heavy, expensive or perhaps lacking or even not available at all).

Long-term, BYE might support the generation of purely synthetic data to detach itself from what happened in the past, and therefore hopefully better evaluate strategies for the future.

The tool will also provide additional analysis and visualization of backtesting results, to help users identify the most promising strategies.

Project Goals

The following goals are in scope for BYE:

  • ๐Ÿ“ˆ Allow backtesting of options strategies on historical data
    • Support for daily SPY data from OptionsDx
    • Put-write strategies
    • Other and more complex strategies/combinations
    • Keeping track of available capital and enforcing position limits
    • Reporting of results - returns, drawdowns, etc.
    • Charts of results
    • Reporting on metrics - volatility, Sharpe ratio, etc.
    • The impact of commissions and fees
    • Tax implications
    • Margin requirements and interest
  • ๐Ÿ”ฎ Generation of semisynthetic market data based on real SPY and VIX values
    • This is also where tickers other than SPY might be supported, because it will likely be easier to generate semisynthetic data for them than to find decent historical data.
  • ๐Ÿ”ฎ Generation of purely synthetic market data to take into account very rare events (black swans) that might have never occurred in the past.

Anti-Goals

None of the following is planned to be supported by BYE:

  • Backtesting on more frequent data. This is not a day-trading tool, it's for long-term strategies.
  • Exercise and assignment. Let's just focus on options.
    Q: Isn't this limiting?
    A: Not really. Buy the put back just before assignment, and open a synthetic long position instead, if that's really what you want. Also, if your intention was to start selling covered calls, notice that they are effectively the same as selling naked puts.

Usage

To use BYE, you will need to first initialize a virtual environment using the requirements.txt file provided. Like this:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

You also need end-of-day data for the SPY ETF from OptionsDX. Save it in the data/raw/spy_eod_raw directory. Each year should be represented by a separate subdirectory, and each month should be saved as a separate text file.

Once you have downloaded and saved the data, run the 1_load.py script in order to load and join the data. The joined data is saved as a single parquet file, data/interim/spy_eod.parquet.

Then, run the 2_select.py script to drop unnecessary columns and save the processed data at data/processed/spy_eod.parquet.

Finally, run the 3_main.py script to backtest the defined options trading strategies. The script will print the progress of the backtesting process in the terminal. In the future, it should generate a summary of the results for each strategy tested.

How do I define my own strategy?

To define your own strategy, you need to get you hands dirty with code. Create a new class that inherits from any other strategy defined in src/strategies.py. Note that the crucial part is the handle_no_open_positions method, which defines the logic for opening a new position when there are no open positions. Everything else is optional, because whatever position you open, it will eventually expire, and the basic logic for handling expiration is already defined in the base class. Then, make sure to add it to the strategies list in 3_main.py.

Disclaimer

๐Ÿšจ Use at your own risk ๐Ÿšจ

You are responsible for any losses incurred as a result of using this tool. See also the LICENSE.

bye's People

Contributors

nix1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

webclinic017

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.