OptionSuite Save

Option and stock backtester / live trader

Project README

OptionSuite

Option / stock strategy backtester and live trader* framework.

Getting started decribes what you need in order to get started backtesting.

Please note that you need to purchase a data package in order to use this library since the sample data is quite limited.

Objective

The objective of the OptionSuite library is to create a general framework to backtest options strategies and to be extensible enough to handle live trading.

*Live trader is currently not supported, but the general framework is in place to enable support for live trading.

Overview of Library

The library is designed in a modular way, and several abstractions are provided which allow the user to add additional features. The directory structure of the library is as follows:

base - contains the abstract options class (option.py) and the two derived classes (call.py and put.py), which serve as the general options types for all other classes.

dataHandler - contains the abstract class (dataHandler.py), which is set up to handle loading option data from different sources. The framework has been tested with CSV data, and a CSV data handler class (csvData.py) is provided to load tick data provided through the CSV format. Any example CSV format is provided in the sampleData directory. More information on the CSV data needed for back testing is covered in the getting started section section.

dataProviders.json - this file configures the columns of the CSV data source that you are using for the backtest.

pricingConfig.json - this file configures the commission and fee structure for the brokerage used.

events - the entire library / framework is event driven, and the abstract event class (event.py) handles the creation and deletion of events. The framework currently supports two different types of events: tick events (tickEvent.py) and signal events (signalEvent.py). The tick events are used to load data from the dataHandler and create the base option types (puts and calls). Signal events are generated to indicate that the criteria for the strategy in strategyManager has been successfully met.

optionPrimitives - option primitives allow for naked puts and calls as well as combinations of puts and calls. For example, an option primtive could describe a naked put, or it could describe a strangle, which is a combination of puts and calls. Since certain trades like strangles are common, the option primitives abstract class (optionPrimitive.py) wraps the base types (calls and puts), and describes the functionality needed to create and update the primitive. The strangle primitive (strangle.py) and put vertical primitive (putVertical.py) are fully functional.

portfolioManager - the portfolio manager (portfolio.py) holds and manages all of the open positions. Potential positions are first generated by the strategyManager, and the portfolio manager opens a new positions if all risk paramters have been met. The portfolio is current held in memory, but a future implementation would ideally store the positions into a database or other non-volatile source.

sampleData - a single file aapl_sample_ivolatility.csv is provided. This file is used for several of the units tests in the different classes, and it also serves as an example of the CSV data format provided by iVolatility.

strategyManager - the strategy manager module provides an abstract class (strategy.py) which defines the basic parameters needed for an options strategy. The purpose of the strategy manager module is to filter the incoming tick data (by means of a tick event) to determine if a position should be opened (which would in turn fire a signal event). A strangle stategy (StrangleStrat.py) and put vertical strategy (putVerticalOnDownMoveStrat.py) are provided.

riskManagement - the risk management module is used to determine when the trade should be exited. The risk management flag is stored along with each trade and accessed in the portfolio.

backTester.py - this is the "main" method for the library. It sets up all parameters for a backtesting session, and initializes the dataHandler class, the portfolioManager class, the strategyManager class, and the riskManagement class. It is helpful to start with this file to see how all of the modules work together.

Getting Started

The library has been tested with Python 3.0+

To get started, you need a Python environment with pandas installed. You'll also need some historical data for the backtests.

Getting the Data

The combinedCSV.csv file used during development and testing contains SPX data from 1990 to 2017 provided by iVolatility. If you'd like to use the same dataset I did, then you want to request the EOD Raw IV dataset for SPX.

There is a 10% discount on all orders greater than $100 if you use code SupraCV10PCTOFF in the "Please tell us what data you want to receive:" field.

You can request different time periods. A large time period such as 1990 to 2017 is broken up into multiple CSVs.

Loading the Data

Once you have downloaded the data, simply update the two lines below, and you are ready to run backTester.py.

dataProvider = 'iVolatility'
filename = '/Users/msantoro/PycharmProjects/Backtester/marketData/iVolatility/SPX/combinedCSV.csv'

Troubleshooting

Please send bugs or any other issues you encounter to [email protected]. I will do my best to help you get up and running. You can also report an issue using GitHub's issue tracker.

Open Source Agenda is not affiliated with "OptionSuite" Project. README Source: sirnfs/OptionSuite
Stars
188
Open Issues
0
Last Commit
9 months ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating