Skip to main content

Python Backtesting library for options trading strategies

Project description

Downloads Build Status Black

Optopsy

NOTE: This library is no longer in active development, however, I hope that this project will be a good basis for other trading/options backtesting projects in the future. As such, I will keep this project active on Github for reference. I am also open to transfering ownership of this repo to those who are interested. Please feel free to contact me if you have any issues, I will try my best to help!

Optopsy is a nimble backtesting libary for option strategies, it is designed to act as an API for your option chain datasets and allows you to focus on what matters, your trading strategy.

The library is designed to compose well into your data analysis work and uses Pandas extensively under the hood. It extends PandasObject to faciliate common functional composition used in quant finance. As such, please note that importing optopsy modifies pandas.core.base.PandasObject to provide added functionality to pandas objects, including DataFrames.

Usage

Use Your Data

  • Use data from any source, just provide a Pandas dataframe with the required columns when calling optopsy functions.

Advanced Backtest Parameters:

  • Optopsy allows you to mix and match different 'filters' to create an option strategy. Results will be returned as Pandas dataframes so that complex strategies can be composed upon. It is highly encourage to make use of pandas.DataFrame.pipe functions and chain methods wherever possible make your code cleaner. To learn more about the subject, I highly recommend reading the following blog post.

Entry rules:

  • Days to expiration
  • Entry Days (Staggered trades)
  • Absolute Delta
  • Percentage out-of-the-money
  • Contract size

Exit rules:

  • Days to expiration
  • Hold days
  • Profit/Stop loss percent
  • Spread delta
  • Spread price

Option strategy support

  • Single Calls/Puts
  • Vertical Spreads
  • Iron Condors
  • (Coming Soon) Iron Butterfly
  • (Coming Soon) Covered Stock
  • (Coming Soon) Combos (Synthetics/Collars)
  • (Coming Soon) Diagonal Spreads
  • (Coming Soon) Calendar Spreads
  • (Coming Soon) Custom Spreads
  • (Coming Soon) Strangles
  • (Coming Soon) Straddles

Dependencies

You will need Python 3.7.x and Pandas 0.24.1 or newer. It is recommended to install Miniconda3. See requirements.txt for full details.

Installation

pip install optopsy

Usage

Optopsy is best used with Jupyter notebooks, however, it is also possible to incorporate it into your python scripts:

The following example uses Level 2 Historical CSV Data Sample from historicaloptiondata.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optopsy-1.0.4.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

optopsy-1.0.4-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file optopsy-1.0.4.tar.gz.

File metadata

  • Download URL: optopsy-1.0.4.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for optopsy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 48e8d83a71fc7bd3b3f6ba38a82538c28027be50392bfc9e776ebe76c896d74f
MD5 fcb7b6891f1525f75385735354083ef5
BLAKE2b-256 ed98646d73716cdbe842780aab19b9c6645480431609ccb114b1e2056ec9ee1d

See more details on using hashes here.

File details

Details for the file optopsy-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: optopsy-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for optopsy-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8a05b288121122e603c8590121e6020aeb089e686f8a7ae8970120962a6c67c8
MD5 1d83944d5674817e0c269a8c96162131
BLAKE2b-256 81da8b10b628b67763d5250349aeac36f4c73c6d4b20370ac6563988a93f6583

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page