Skip to main content

Options Testing Framework

This library is a framework for testing stock options strategies. It works along with the popular Backtrader framework. The Backtrader framework is an excellent solution for backtesting stock trading ideas. However, testing options trading strategies is much more complicated. This framework will work with backtrader to test your options trading strategies.

The Options Chain class

The options chain class receives the raw data from the data loader and creates option objects that can be used by the rest of the library.

The Options Portfolio class

This is the class that is directly called from the external program. It is where opening and closing of positions is initiated and communicated to the rest of the program. It keeps a reference to open positions, and also closed positions. This is available to the the external program for evaluating its positions.

The OptionCombination class

This is the base class for any options position, even a single option. It can hold one or more options that are part of an option spread.

Option Spreads

Several common option spread classes are available for convenience. Of course, you can also create any kind of option position with the "custom" type option spread class.

Events

To make coordinating the different modules easier, events cause changes in modules as a result of the timeslot advancing and all the value changes for each advance. There are also events to assure that the portfolio value accurately reflects anything that changes its value, such as option price changes and fees.

Dispatchers

The following classes implement the Dispatcher class and emit events

  • OptionsPortfolio
    • events: new_position_opened, position_closed, next, next_options position_expired
  • Option
    • open_transaction_completed, close_transaction_completed, option_expired, fees_incurred

Event Handling

next

  • Emitted by the OptionPortfolio. The "next" method is called externally when time advances. The option chain needs to get updates with a new time slot's data.

  • Handled by OptionChain.

    • OptionChain handler: on_next - updates all the option data for the given timeslot

next_options

  • Emitted by OptionPortfolio. The "next_options" method emits all the open options. The OptionChain updates each option using the current quote data
  • Handled by OptionChain.

position_closed

  • Emitted by OptionPortfolio when an option position is closed. This is so an external program can receive this event.
  • There are no event handlers in the library for this event. It is provided for the external program to get final price and other information when a position is closed.

position_expired

  • Emitted by OptionPortfolio when an option expires. This is so an external program can receive this event.
  • There are no event handlers in the library for this event. It is provided for the external program to get final price and other information when a position has expired.

open_transaction_completed

  • Emitted by the Option class. It alerts the portfolio that an option has been opened.
  • Handled by OptionPortfolio. The portfolio needs to know how much premium was bought/sold so it can update its cash position. It also adds the position to its open positions list.

close_transaction_completed

  • Emitted by the Option class. It alerts the portfolio that an option has been closed.
  • Handled by OptionPortfolio. The portfolio removes the position from its open positions and moves it to its closed positions. Also, final premium is used to update its cash position.

option_expired

  • Emitted by the Option class. It alerts when the time slot reaches the expiration date while the option is still open.
  • Handled by the OptionPortfolio. Similar to the close transaction event.

fees_incurred

  • Emitted by the Option class. It alerts whenever any fees have been incurred.
  • Handled by the OptionPortfolio class. It needs to update its cash position to account for any fees.

Metadata

Release files for options-framework 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for options-framework 1.0.0
File Size Uploaded
options_framework-1.0.0.tar.gz 3.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for options-framework 1.0.0
File Interpreter ABI Platform
options_framework-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.1 MB

Release files / options_framework-1.0.0.tar.gz

Download URL options_framework-1.0.0.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
dfbb3b47791ec360b31dfe6bd89228c3b3f62deddb33c1c86d12943b1618c0c3
BLAKE2b-256 checksum
How to use checksums
6992c7a258a2dc49910e0d0e5438f50f5f5a76aa47002d3be95203ad202e4d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / options_framework-1.0.0-py3-none-any.whl

Download URL options_framework-1.0.0-py3-none-any.whl
Size 58.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b59e56ee487806c3dd8ab1586a210d88dc19ab967c0970dcf6daa2283e8cb6d
BLAKE2b-256 checksum
How to use checksums
93d15b877abb372b07e613cc22051904f38f9c1df4b6d248234506886f17f16b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page