{ "info": { "author": "Michael Chu", "author_email": "mchchu88@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6" ], "description": "[![Downloads](https://pepy.tech/badge/optopsy)](https://pepy.tech/project/optopsy)\n[![Maintainability](https://api.codeclimate.com/v1/badges/37b11e992a6900d30310/maintainability)](https://codeclimate.com/github/michaelchu/optopsy/maintainability)\n[![Build Status](https://travis-ci.org/michaelchu/optopsy.svg?branch=master)](https://travis-ci.org/michaelchu/optopsy)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/37b11e992a6900d30310/test_coverage)](https://codeclimate.com/github/michaelchu/optopsy/test_coverage)\n\n# Optopsy\n\nOptopsy is a flexible backtesting framework used to test complex options trading strategies written in Python.\nBacktesting is the process of testing a strategy over a given data set. This framework allows you to mix and match\ndifferent 'filters' to create a 'Strategy', and allow multiple strategies to form an overall more complex trading algorithms.\nThe modular nature of this framework aims to foster the creation of easily testable, re-usable and flexible blocks of strategy logic to facilitate\nthe rapid development of complex options trading strategies.\n\n## Features\n\n### Easy Backtesting\n* Easily set up a backtest in seconds by defining filters for the backtest\n\n### Use Your Data\n* Use data from any source, just define the format of your data source or use pre-existing data structs for popular sources such as CBOE and Historical Options Data.\n\n### Advanced Backtest Parameters:\n\n**Entry rules:**\n* Days to expiration\n* Entry Days (Staggered trades)\n* Absolute Delta\n* Percentage out-of-the-money\n* Contract size\n\n**Exit rules:**\n* Days to expiration\n* Hold days\n* Profit/Stop loss percent\n* Spread delta\n* Spread price\n\n### Option strategy support\n* Single Calls/Puts\n* Vertical Spreads\n* Iron Condors\n* (Coming Soon) Iron Butterfly\n* (Coming Soon) Covered Stock\n* (Coming Soon) Combos (Synthetics/Collars)\n* (Coming Soon) Diagonal Spreads\n* (Coming Soon) Calendar Spreads\n* (Coming Soon) Custom Spreads\n* (Coming Soon) Strangles\n* (Coming Soon) Straddles\n\n### Dependencies\nYou will need Python 3.6.x and Pandas 0.23.1 or newer. It is recommended to install [Miniconda3](https://conda.io/miniconda.html). See [requirements.txt](https://github.com/michaelchu/optopsy/blob/master/requirements.txt) for full details.\n\n### Installation\n```\npip install optopsy\n```\n\n### Usage\n```\npython strategies/sample_strategy.py\n```\nThe sample strategy can be used with [Level 2 Historical CSV Data Sample](http://www.deltaneutral.com/files/Sample_SPX_20151001_to_20151030.csv) from historicaloptiondata.com.\n\nIn order to use it, you will need to define the struct variable to map the column names to the numerical index as per the file format.\n\nFirst we import the library and other nessesary libaries:\n```python\nimport optopsy as op\nfrom datetime import datetime\n```\n\nDefine the data structure with a tuple of tuple format, with first element being the standard column names defined in optopsy and the index that corresponds to the column order of the input source\n```python\nSPX_FILE_STRUCT = (\n ('underlying_symbol', 0),\n ('underlying_price', 1),\n ('option_symbol', 3),\n ('option_type', 5),\n ('expiration', 6),\n ('quote_date', 7),\n ('strike', 8),\n ('bid', 10),\n ('ask', 11),\n ('delta', 15),\n ('gamma', 16),\n ('theta', 17),\n ('vega', 18)\n)\n```\n\nAn example of a simple strategy for trading short call spreads with strikes at 30 and 50 deltas with around 30 days to expiration for the SPX:\n```python\ndef run_strategy():\n\n # provide the absolute file path and data struct to be used.\n data = op.get(FILE, SPX_FILE_STRUCT, prompt=False)\n\n # define the entry and exit filters to use for this strategy, full list of\n # filters is listed in the documentation (WIP).\n filters = {\n 'entry_dte': (27, 30, 31),\n 'leg1_delta': 0.30,\n 'leg2_delta': 0.50,\n 'contract_size': 10\n }\n\n # set the start and end dates for the backtest, the dates are inclusive\n start = datetime(2016, 1, 1)\n end = datetime(2016, 12, 31)\n\n # create the option spreads that matches the entry filters\n trades = op.strategies.short_call_spread(data, start, end, filters)\n\n # call the run method with our data, option spreads and filters to run the backtest\n backtest = op.run(data, trades, filters)\n\n # backtest will return a tuple with the profit amount (first element) and a dataframe\n # (second element) containing the backtest results(the return format may be subject to change)\n backtest[1].to_csv('./strategies/results/results.csv')\n print(\"Total Profit: %s\" % backtest[0])\n```\n\n#### Sample Backtest Results:\n\n\nEntry Trades (First 2 trades):\n\n```\nquote_date option_type expiration underlying_symbol ratio delta underlying_price option_symbol strike bid ask gamma theta vega dte contracts\n2016-01-06 c 2016-02-05 SPXW -1 0.50 1987.42 SPXW160205C01990000 1990 42.1 42.8 0.0 -274.85 224.75 30 10\n2016-01-06 c 2016-02-05 SPXW 1 0.30 1987.42 SPXW160205C02040000 2040 17.4 17.8 0.0 -208.37 196.71 30 10\n2016-01-13 c 2016-02-12 SPXW -1 0.51 1891.49 SPXW160212C01885000 1885 49.8 50.8 0.0 -202.50 213.03 30 10\n2016-01-13 c 2016-02-12 SPXW 1 0.30 1891.49 SPXW160212C01940000 1940 22.4 23.0 0.0 -187.45 185.48 30 10\n...\n```\n\nResults (First 2 trades):\n```\nentry_date exit_date expiration DTE ratio contracts option_type strike entry_delta entry_stk_price exit_stk_price entry_opt_price exit_opt_price entry_price exit_price profit\n2016-01-06 2016-02-05 2016-02-05 30 -1 10 c 1990 0.50 1987.42 1874.12 42.45 0.025 -424.5 -0.25 424.25\n2016-01-06 2016-02-05 2016-02-05 30 1 10 c 2040 0.30 1987.42 1874.12 17.60 0.025 176.0 0.25 -175.75\n2016-01-13 2016-02-12 2016-02-12 30 -1 10 c 1885 0.51 1891.49 1862.40 50.30 0.025 -503.0 -0.25 502.75\n2016-01-13 2016-02-12 2016-02-12 30 1 10 c 1940 0.30 1891.49 1862.40 22.70 0.025 227.0 0.25 -226.75\n...\n\nTotal Profit: 524.50\n```\n\n**Full Documentation Coming Soon!**\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/michaelchu/optopsy", "keywords": "", "license": "GPL-3.0-or-later", "maintainer": "", "maintainer_email": "", "name": "optopsy", "package_url": "https://pypi.org/project/optopsy/", "platform": "", "project_url": "https://pypi.org/project/optopsy/", "project_urls": { "Homepage": "https://github.com/michaelchu/optopsy" }, "release_url": "https://pypi.org/project/optopsy/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "Python Backtesting library for options trading strategies", "version": "1.0.3" }, "last_serial": 4515276, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "ef2a1a0be7df80e5e5373a51458824cd", "sha256": "72b197fe44e5b4b34c2c8a46fe8409753c99a33a2343466d4bba5cc9c370c7a9" }, "downloads": -1, "filename": "optopsy-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ef2a1a0be7df80e5e5373a51458824cd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14709, "upload_time": "2018-11-14T06:31:37", "url": "https://files.pythonhosted.org/packages/74/a1/ddb08456d84fd4ef459ebd022d2afef94e471d349e0af7954296c89b849e/optopsy-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1c1bcd8afd55eb0b45d442af446d4e41", "sha256": "f9cdbccc29becce74faba3509fb3a07b943c834a12f986fb2a6a219a90e7739e" }, "downloads": -1, "filename": "optopsy-1.0.0.tar.gz", "has_sig": false, "md5_digest": "1c1bcd8afd55eb0b45d442af446d4e41", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13098, "upload_time": "2018-11-14T06:31:38", "url": "https://files.pythonhosted.org/packages/10/24/c06214873f9060313450d82cc8308f057f8cc5db863c191ccc8bee68b46a/optopsy-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "7afaa9f1b7efa8e231791d1d0d0bfef1", "sha256": "99bf8d4836d9cd96f71fee0da68c8706434cf13986e1482aabebaceb5e72241b" }, "downloads": -1, "filename": "optopsy-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "7afaa9f1b7efa8e231791d1d0d0bfef1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 27021, "upload_time": "2018-11-14T15:50:03", "url": "https://files.pythonhosted.org/packages/0d/3d/ba2f0468f7e61d9c0a4c63e60511c881807f42e196af2706c325a8ed4fc9/optopsy-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c7c2813fcd24d3b8870aa994f9a4e1a1", "sha256": "6d002e638c00541de381977d22eec1e660a3b9d38db40cedc18c649266a912b8" }, "downloads": -1, "filename": "optopsy-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c7c2813fcd24d3b8870aa994f9a4e1a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13125, "upload_time": "2018-11-14T15:50:04", "url": "https://files.pythonhosted.org/packages/7e/e0/3318d823a8dbee91e1db415392147c74612d915c753d75eebb3233b28d0d/optopsy-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "7bf3a669ce30490696779c3a42729662", "sha256": "05f53936daa4d0da43ab096fcf640511530e460aaa321153ca311dcba9da8539" }, "downloads": -1, "filename": "optopsy-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7bf3a669ce30490696779c3a42729662", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14224, "upload_time": "2018-11-16T06:45:04", "url": "https://files.pythonhosted.org/packages/31/51/f0341af036bef0746e6da2992c4e1189850cbd8e0e504ca55ea7acc868d8/optopsy-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9ab9120d5949180ae0dda36d8cbdef73", "sha256": "bdc310b7a9ac3b3c14790ebb8a64a7e699f7909bc5f92a20bbd270a65a6af6d0" }, "downloads": -1, "filename": "optopsy-1.0.2.tar.gz", "has_sig": false, "md5_digest": "9ab9120d5949180ae0dda36d8cbdef73", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12486, "upload_time": "2018-11-16T06:45:06", "url": "https://files.pythonhosted.org/packages/30/af/5dbc6cafcc9637426f943f48d221cd79e30cf5ec8e4b63b7ab9d71a5c670/optopsy-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "2f00725ee9ab37e877bc9126578aad55", "sha256": "e3fbb281bb4a3385a690d1b54a449aa4336b18f7f6c770dd1df23bbcad2d927e" }, "downloads": -1, "filename": "optopsy-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "2f00725ee9ab37e877bc9126578aad55", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 15232, "upload_time": "2018-11-22T05:08:43", "url": "https://files.pythonhosted.org/packages/dd/6e/cf475f39ff4051267284745f40e9982f8c6b92420c8bbef64c75aded199b/optopsy-1.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "731df33298b6d18a6f9e5f4ba1f4eb76", "sha256": "7d3be9c17e84f05858c98f2989827d52385987786eee000197e412da92a40743" }, "downloads": -1, "filename": "optopsy-1.0.3.tar.gz", "has_sig": false, "md5_digest": "731df33298b6d18a6f9e5f4ba1f4eb76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13246, "upload_time": "2018-11-22T05:08:45", "url": "https://files.pythonhosted.org/packages/14/07/000a3bcd4484eb0fa98dc40f6662248b076040dc5253ea092e298cb67909/optopsy-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2f00725ee9ab37e877bc9126578aad55", "sha256": "e3fbb281bb4a3385a690d1b54a449aa4336b18f7f6c770dd1df23bbcad2d927e" }, "downloads": -1, "filename": "optopsy-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "2f00725ee9ab37e877bc9126578aad55", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 15232, "upload_time": "2018-11-22T05:08:43", "url": "https://files.pythonhosted.org/packages/dd/6e/cf475f39ff4051267284745f40e9982f8c6b92420c8bbef64c75aded199b/optopsy-1.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "731df33298b6d18a6f9e5f4ba1f4eb76", "sha256": "7d3be9c17e84f05858c98f2989827d52385987786eee000197e412da92a40743" }, "downloads": -1, "filename": "optopsy-1.0.3.tar.gz", "has_sig": false, "md5_digest": "731df33298b6d18a6f9e5f4ba1f4eb76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13246, "upload_time": "2018-11-22T05:08:45", "url": "https://files.pythonhosted.org/packages/14/07/000a3bcd4484eb0fa98dc40f6662248b076040dc5253ea092e298cb67909/optopsy-1.0.3.tar.gz" } ] }