# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['thetagang']

package_data = \
{'': ['*']}

install_requires = \
['click-log>=0.3.2,<0.4.0',
 'click>=7.1.2,<8.0.0',
 'colorama>=0.4.4,<0.5.0',
 'ib_insync>=0.9.66,<0.10.0',
 'python-dateutil>=2.8.1,<3.0.0',
 'pytimeparse>=1.1.8,<2.0.0',
 'schema>=0.7.3,<0.8.0',
 'toml>=0.10.2,<0.11.0']

entry_points = \
{'console_scripts': ['thetagang = thetagang.entry:cli',
                     'vscode = vscode:vscode']}

setup_kwargs = {
    'name': 'thetagang',
    'version': '0.1.27',
    'description': 'ThetaGang is an IBKR bot for getting money',
    'long_description': '[![Docker publish](https://github.com/brndnmtthws/thetagang/workflows/Docker%20publish/badge.svg)](https://hub.docker.com/r/brndnmtthws/thetagang) [![Python Publish](https://github.com/brndnmtthws/thetagang/workflows/Python%20Publish/badge.svg)](https://pypi.org/project/thetagang/) [![Docker Pulls](https://img.shields.io/docker/pulls/brndnmtthws/thetagang)](https://hub.docker.com/r/brndnmtthws/thetagang) [![PyPI download month](https://img.shields.io/pypi/dm/thetagang?label=PyPI%20downloads)](https://pypi.python.org/pypi/thetagang/)\n\n[💬 Join the Matrix chat, we can get money together](https://matrix.to/#/#thetagang:frens.io).\n\n# Θ ThetaGang Θ\n\n*Beat the capitalists at their own game with ThetaGang 📈*\n\n![Decay my sweet babies](thetagang.jpg)\n\nThetaGang is an [IBKR](https://www.interactivebrokers.com/) trading bot for\ncollecting premium by selling options using "The Wheel" strategy. The Wheel\nis a strategy that [surfaced on\nReddit](https://www.reddit.com/r/options/comments/a36k4j/the_wheel_aka_triple_income_strategy_explained/),\nbut has been used by many in the past. This bot implements a slightly\nmodified version of The Wheel, with my own personal tweaks.\n\nI\'ve been streaming most of the work on this project [on Twitch, so follow me\nover there](https://www.twitch.tv/letsmakestuff).\n\n## How it works\n\nStart by reading [the Reddit\npost](https://www.reddit.com/r/options/comments/a36k4j/the_wheel_aka_triple_income_strategy_explained/)\nto get some background.\n\nThe strategy, as implemented here, does a few things differently from the one\ndescribed in the post above. For one, it\'s intended to be used to augment a\ntypical index-fund based portfolio with specific asset allocations. For\nexample, you might want to use a 60/40 portfolio with SPY (S&P500 fund) and\nTLT (20 year treasury fund). This strategy reduces risk, but may also limit\ngains from big market swings. By reducing risk, one can increase leverage.\n\nThe main difference between ThetaGang and simply buying and holding index\nfunds is that this script will attempt to harvest volatility by selling\noptions, rather than buying shares directly. This works because implied\nvolatility is typically higher than realized volatility on average. Instead\nof buying shares, you write puts. This has pros and cons, which are outside\nthe scope of this README.\n\nYou could use this tool on individual stocks, but I personally don\'t\nrecommend it because I am not smart enough to understand which stocks to buy.\nThat\'s why I just buy index funds.\n\nThetaGang will try to acquire your desired allocation of each stock or ETF\naccording to the weights you specify in the config. To acquire the positions,\nthe script will write puts when conditions are met (adequate buying power,\nacceptable contracts are available, enough shares needed, etc).\n\nThetaGang will continue to roll any open option positions indefinitely, with\nthe only exception being ITM puts. Once puts are in the money, they will be\nignored until they expire and are exercised (after which you will own the\nunderlying).\n\nIf puts are exercised due to being ITM at expiration, you will own the\nstock, and ThetaGang switches from writing puts to writing calls at a strike\nat least as high as the average cost of the stock held.\n\nPlease note: this strategy is based on the assumption that implied volatility\nis, on average, always higher than realized volatility. In cases where this\nis not true, this strategy will cause you to lose money.\n\nIn the case of deep ITM calls, the bot will prefer to roll the calls to next\nstrike or expiration rather than allowing the underlying to get called away. If you\ndon\'t have adequate buying power available in your account, it\'s possible\nthat the options may get exercised instead of rolling forward and the process\nstarts back at the beginning. Please keep in mind this may have tax\nimplications, but that is outside the scope of this README.\n\nIn normal usage, you would run the script as a cronjob on a daily, weekly, or\nmonthly basis according to your preferences. Running more frequently than\ndaily is not recommended, but the choice is yours.\n\n![Paper account sample output](sample.gif)\n\n## Project status\n\nThis project is, in its current state, considered to be complete. I\'m open\nto contributions, but I am unlikely to accept PRs or feature requests that\ninvolve significant changes to the underlying algorithm.\n\nIf you find something that you think is a bug, or some other issue, please\n[create a new issue](https://github.com/brndnmtthws/thetagang/issues/new).\n\n## "Show me your gains bro" – i.e., what are the returns?\n\nAs discussed elsewhere in this README, you must conduct your own research,\nand I suggest starting with resources such as CBOE\'s BXM and BXDM indices,\nand comparing those to SPX. I\'ve had a lot of people complain because "that\nstrategy isn\'t better than buy and hold BRUH"–let me assure you, that is not\nmy goal with this.\n\nThere are conflicting opinions about whether selling options is good or bad,\nmore or less risky, yadda yadda, but generally the risk profile for covered\ncalls and naked puts is no worse than the worst case for simply holding an\nETF or stock. In fact, I\'d argue that selling a naked put is better than\nbuying SPY with a limit order, because at least if SPY goes to zero you keep\nthe premium from selling the option. The main downside is that returns are\ncapped on the upside. Depending on your goals, this may not matter. If you\'re\nlike me, then you\'d rather have consistent returns and give up a little bit\nof potential upside.\n\nGenerally speaking, the point of selling options is not to exceed the returns\nof the underlying, but rather to reduce risk. Reducing risk is an important\nfeature because it, in turn, allows one to increase risk in other ways\n(i.e., allocate higher percentage to stocks or buy riskier assets).\n\nWhether you use this or not is up to you. I have not one single fuck to give,\nwhether you use it or not. I am not here to convince you to use it, I merely\nwant to share knowledge and perhaps help create a little bit of wealth\nredistribution.\n\n💫\n\n## Requirements\n\nThe bot is based on the [ib_insync](https://github.com/erdewit/ib_insync)\nlibrary, and uses [IBC](https://github.com/IbcAlpha/IBC) for managing the API\ngateway.\n\nTo use the bot, you\'ll need an Interactive Brokers account with a working\ninstallation of IBC. If you want to modify the bot, you\'ll need an\ninstallation of Python 3.8 or newer with the\n[`poetry`](https://python-poetry.org/) package manager.\n\nOne more thing: to run this on a live account, you\'ll require enough capital\nto purchase at least 100 shares of the stocks or ETFs you choose. For\nexample, if SPY is trading at $300/share you\'d need $30,000 available. You\ncan search for lower priced alternatives, but these tend to have low volume\non options which may not be appropriate for this strategy. You should\ngenerally avoid low volume ETFs/stocks. If you don\'t have that kind of\ncapital, you\'ll need to keep renting out your time to the capitalists until\nyou can become a capitalist yourself. That\'s the way the pyramid scheme we\ncall capitalism works.\n\n## Installation\n\n*Before running ThetaGang, you should set up an IBKR paper account to test the\ncode.*\n\n```console\n$ pip install thetagang\n```\n\nIt\'s recommended you familiarize yourself with\n[IBC](https://github.com/IbcAlpha/IBC) so you know how it works. You\'ll need\nto know how to configure the various knows and settings, and make sure things\nlike API ports are configured correctly. If you don\'t want to mess around too\nmuch, consider [running ThetaGang with Docker](#running-with-docker).\n\n## Usage\n\n```console\n$ thetagang -h\n```\n\n## Up and running with Docker\n\nMy preferred way for running ThetaGang is to use a cronjob to execute Docker\ncommands. I\'ve built a Docker image as part of this project, which you can\nuse with your installation. There\'s a [prebuilt Docker image\nhere](https://hub.docker.com/repository/docker/brndnmtthws/thetagang).\n\nTo run ThetaGang within Docker, you\'ll need to pass `config.ini` for [IBC\nconfiguration](https://github.com/IbcAlpha/IBC/blob/master/userguide.md) and\n[`thetagang.toml`](/thetagang.toml) for ThetaGang. There\'s a sample\n[`ibc-config.ini`](/ibc-config.ini) included in this repo for your convenience.\n\nThe easiest way to get the config files into the container is by mounting a\nvolume.\n\nTo get started, grab a copy of `thetagang.toml` and `config.ini`:\n\n```console\n$ mkdir ~/thetagang\n$ cd ~/thetagang\n$ curl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/thetagang.toml -o ~/thetagang/thetagang.toml\n$ curl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/ibc-config.ini -o ~/thetagang/config.ini\n```\n\nEdit `~/thetagang/thetagang.toml` to suit your needs. Pay particular\nattention to the symbols and weights. At a minimum, you must change the\nusername, password, and account number. You may also want to change the\ntrading move from paper to live when needed.\n\nNow, to run ThetaGang with Docker:\n\n```console\n$ docker run --rm -i --net host \\\n    -v ~/thetagang:/etc/thetagang \\\n    brndnmtthws/thetagang:latest \\\n    --config /etc/thetagang/thetagang.toml\n```\n\nLastly, to run ThetaGang as a daily cronjob Monday to Friday at 9am, add\nsomething like this to your crontab (on systems with a cron installation, use\n`crontab -e` to edit your crontab):\n\n```crontab\n0 9 * * 1-5 docker run --rm -i -v ~/ibc:/etc/thetagang brndnmtthws/thetagang:latest --config /etc/thetagang/thetagang.toml\n```\n\n## Determining which ETFs or stocks to run ThetaGang with\n\nI leave this as an exercise to the reader, however I will provide a few\nrecommendations and resources:\n\n### Recommendations\n\n* Stick with high volume ETFs or stocks\n* Careful with margin usage, you\'ll want to calculate the worst case scenario\n  and provide plenty of cushion for yourself based on your portfolio\n\n\n### Resources\n\n* For discussions about selling options, check out\n  [r/thetagang](https://www.reddit.com/r/thetagang/)\n* For backtesting portfolios, you can use [this\n  tool](https://www.portfoliovisualizer.com/backtest-portfolio) and [this\n  tool](https://www.portfoliovisualizer.com/optimize-portfolio) to get an idea\n  of drawdown and typical volatility\n\n## Development\n\nCheck out the code to your local machine and install the Python dependencies:\n\n```shell\n$ poetry install\n$ poetry run autohooks activate\n$ poetry run thetagang -h\n...\n```\n\nYou are now ready to make a splash! 🐳\n\n## FAQ\n\n| Error                                                                                                      | Cause                                                                                                                            | Resolution                                                                                                                                                                                                                                                                                                                                                                                                                                         |\n| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Requested market data is not subscribed.                                                                   | Requisite market data subscriptions have not been set up on IBKR.                                                                | [Configure](https://www.interactivebrokers.com/en/software/am3/am/settings/marketdatasubscriptions.htm) your market data subscriptions. The default config that ships with this script uses the `Cboe One Add-On Bundle` and the `US Equity and Options Add-On Streaming Bundle`. **Note**: You _must_ fund your account before IBKR will send data for subscriptions. Without funding you can still subscribe but you will get an error from ibc. |\n| No market data during competing live session                                                               | Your account is logged in somewhere else, such as the IBKR web portal, the desktop app, or even another instance of this script. | Log out of all sessions and then re-run the script.                                                                                                                                                                                                                                                                                                                                                                                                |\n| `ib_insync.wrapper ERROR Error 200, reqId 10: The contract description specified for SYMBOL is ambiguous.` | IBKR needs to know which exchange is the primary exchange for a given symbol.                                                    | You need to specify the primary exchange for the stock. This is normal for companies, typically. For ETFs it usually isn\'t required. Specify the `primary_exchange` parameter for the symbol, i.e., `primary_exchange = "NYSE"`.                                                                                                                                                                                                                   |\n\n## Support and sponsorship\n\nIf you get some value out of this, please consider [sponsoring me](https://github.com/sponsors/brndnmtthws)\nto continue maintaining this project well into the future. Like\neveryone else in the world, I\'m just trying to survive.\n\nIf you like what you see but want something different, I am willing\nto work on bespoke or custom trading bots for a fee. Reach out\nto me directly through my GitHub profile.\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/brndnmtthws/thetagang.svg)](https://starchart.cc/brndnmtthws/thetagang)\n',
    'author': 'Brenden Matthews',
    'author_email': 'brenden@brndn.io',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/brndnmtthws/thetagang',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
