{"id":13449685,"url":"https://github.com/brndnmtthws/thetagang","last_synced_at":"2025-05-14T20:10:36.594Z","repository":{"id":41963829,"uuid":"318309101","full_name":"brndnmtthws/thetagang","owner":"brndnmtthws","description":"ThetaGang is an IBKR bot for collecting money","archived":false,"fork":false,"pushed_at":"2025-04-08T12:13:45.000Z","size":101705,"stargazers_count":2181,"open_issues_count":4,"forks_count":288,"subscribers_count":74,"default_branch":"main","last_synced_at":"2025-04-28T13:59:08.629Z","etag":null,"topics":["bot","buying-shares","get-rich-slowly","ibkr","money","strategy","thetagang","trading-bot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brndnmtthws.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"brndnmtthws"}},"created_at":"2020-12-03T20:17:09.000Z","updated_at":"2025-04-28T08:13:42.000Z","dependencies_parsed_at":"2023-12-25T17:11:34.980Z","dependency_job_id":"b1c67478-55a2-4aa0-9def-a987707af024","html_url":"https://github.com/brndnmtthws/thetagang","commit_stats":{"total_commits":649,"total_committers":8,"mean_commits":81.125,"dds":"0.29429892141756553","last_synced_commit":"a29a4798fc916d9c15a42c3c3c2e1feb96d5d045"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brndnmtthws%2Fthetagang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brndnmtthws%2Fthetagang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brndnmtthws%2Fthetagang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brndnmtthws%2Fthetagang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brndnmtthws","download_url":"https://codeload.github.com/brndnmtthws/thetagang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254219374,"owners_count":22034397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","buying-shares","get-rich-slowly","ibkr","money","strategy","thetagang","trading-bot"],"created_at":"2024-07-31T06:00:51.439Z","updated_at":"2025-05-14T20:10:31.586Z","avatar_url":"https://github.com/brndnmtthws.png","language":"Python","funding_links":["https://github.com/sponsors/brndnmtthws"],"categories":["Trading bots","Alpha Collections","Python","Uncategorized","repos:"],"sub_categories":["Cryptocurrencies","General Alpha","Uncategorized"],"readme":"[![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\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\u0026P500 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\nThetaGang is quite configurable, and you can adjust the parameters to suit your\npreferences and needs, but the default configuration is designed to be a good\nstarting point. ThetaGang makes some assumptions about how to run this strategy,\nbut you can tweak it to your liking by modifying the\n[`thetagang.toml`](https://github.com/brndnmtthws/thetagang/blob/main/thetagang.toml)\nfile.\n\nThe main difference between ThetaGang and simply buying and holding index funds\nis that this script will attempt to harvest volatility by selling options,\nrather than buying shares directly. This works because implied volatility is\ntypically higher than realized volatility on average. Instead of buying shares,\nyou write puts. This has pros and cons, which are outside the scope of this\nREADME.\n\nThetaGang can also be used in combination with other strategies such as PMCCs,\nZebra, stock replacement, and so forth. For these strategies, however, ThetaGang\nwill not manage long positions for you. You will need to manage these positions\nyourself. ThetaGang will, however, continue to execute the short legs of these\nstrategies as long as you have the buying power available and set the\nappropriate configuration (in particular, by setting\n`write_when.calculate_net_contracts = true`).\n\nYou could use this tool on individual stocks, but I don't\nrecommend it because I am not smart enough to understand which stocks to buy.\nThat's why I 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 (config parameters, adequate\nbuying power, acceptable contracts are available, enough shares needed, etc).\n\nThetaGang will continue to roll any open option positions indefinitely, with the\nonly exception being ITM puts (although this is configurable). Once puts are in\nthe money, they will be ignored until they expire and are exercised (after which\nyou will own the underlying). When rolling puts, the strike of the new contracts\nare capped at the old strike plus the premium received (to prevent your account\nfrom blowing due to over-ratcheting up the buying power usage).\n\nIf puts are exercised due to being ITM at expiration, you will own the stock,\nand ThetaGang switches from writing puts to writing calls at a strike at least\nas high as the average cost of the stock held. To avoid missing out on upward\nmoves, you can limit the number of calls that are written with\n`write_when.calls.cap_factor`, such as setting this to 0.5 to limit the number\nof calls to 50% of the shares 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\nyou don'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.png)\n\n### VIX call hedging\n\nThetaGang can optionally hedge your account by purchasing VIX calls for the next\nmonth based on specified parameters. The strategy is based on the [Cboe VIX Tail\nHedge Index](https://www.cboe.com/us/indices/dashboard/vxth/), which you can\nread about on the internet. You can enable this feature in `thetagang.toml`\nwith:\n\n```toml\n[vix_call_hedge]\nenabled = true\n```\n\nDefault values are provided, based on the VXTH index, but you may configure\nthem to your taste (refer to\n[`thetagang.toml`](https://github.com/brndnmtthws/thetagang/blob/6eab3823120c10c0563e02c5d7f30dfcc0e333fc/thetagang.toml#L294-L331)\nfor details).\n\nBuying VIX calls is not free, and it _will_ create some drag on your portfolio,\nbut in times of extreme volatility–such as the COVID-related 2020 market\npanic–VIX calls can provide outsized returns.\n\n### Cash management\n\nAt the time of writing, interest rates have reached yields that make bonds look\nattractive. To squeeze a little more juice, thetagang can do some simple cash\nmanagement by purchasing a fund when you have extra cash. Although you do earn\na yield on your cash balance, it's not the juiciest yield you can get, so a\nlittle optimization might help you earn 1 or 2 extra pennies to take the edge\noff your rent payments.\n\nThere are quite a few ETFs that might be a decent place to stash your cash, and\nyou should do some internet searches to find the most appropriate one for you\nand your feelings. Here are some internet web searches that you can test out to\nget some information on cash funds (ETFs):\n\n- [\"cash etf reddit\"](https://www.google.com/search?q=cash+etf+reddit)\n- [\"sgov reddit\"](https://www.google.com/search?q=sgov+reddit)\n- [\"shv reddit\"](https://www.google.com/search?q=shv+reddit)\n- [\"short term government bond etf reddit\"](https://www.google.com/search?q=short+term+government+bond+etf+reddit)\n\nYou can enable cash management with:\n\n```toml\n[cash_management]\nenabled = true\n```\n\nRefer to [`thetagang.toml`](https://github.com/brndnmtthws/thetagang/blob/4fc34653786ec17fe6ce6ec2406b2d861277f934/thetagang.toml#L330-L377) for all the options.\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, and\nI suggest starting with resources such as CBOE's BXM and BXDM indices and\ncomparing 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 my\ngoal 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. 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 a 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_async](https://github.com/ib-api-reloaded/ib_async)\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.10 or newer with the\n[`uv`](https://docs.astral.sh/uv/) 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\npip 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\nthetagang -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`](https://github.com/brndnmtthws/thetagang/blob/main/thetagang.toml) for ThetaGang. There's a sample\n[`ibc-config.ini`](https://github.com/brndnmtthws/thetagang/blob/main/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\nmkdir ~/thetagang\ncd ~/thetagang\ncurl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/thetagang.toml -o ./thetagang.toml\ncurl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/ibc-config.ini -o ./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\ndocker run --rm -i --net host \\\n    -v ~/thetagang:/etc/thetagang \\\n    brndnmtthws/thetagang:main \\\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 ~/thetagang:/etc/thetagang brndnmtthws/thetagang:main --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### 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```console\n# Install the pre-commit hooks\nuv run pre-commit install\n# Run thetagang\nuv run thetagang -h\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_async.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| IBKey and MFA-related authentication issues | IBKR requires MFA for the primary account user. | Create a second account with limited permissions using the web portal (remove withdrawal/transfer, client management, IP restriction, etc permissions) and set an IP restriction if possible. When logging into the second account, ignore the MFA nags and do not enable MFA. A [more detailed set of instructions can be found here](https://github.com/Voyz/ibeam/wiki/Runtime-environment#using-a-secondary-account), from a different project. |\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrndnmtthws%2Fthetagang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrndnmtthws%2Fthetagang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrndnmtthws%2Fthetagang/lists"}