- Notifications
You must be signed in to change notification settings - Fork53
Volatility trading using Long and Short Straddle options strategies on Interactive Broker using Yahoo Finance and TWS API
License
mcf-long-short/ibkr-options-volatility-trading
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Volatility trading
usingequity options
andlong/short straddle
option strategies combined with amomentum strategy
to profit from a high/low volatility on a daily level in the US equities.
For testing that strategy Interactive Brokers Trader Workstation was used with paper trading account. In order to quickly react on the market moves, simplemarket watcher
/trading bot
was implemented.MarketWatcher bot
uses data fromYahoo Finance andPython TWS API.
This repository represents group project work for implementing option trading strategies (course in Financial Derivatives for advanced degreeMasters in Computational Finance, Union University).
Our trading strategy is based onvolatility trading
. To exploit and profit from both the high and low volatility, we day traded - getting in and out of the positions in the same trading session. Some positions were held overnight as well.
In order to profit on a high or low volatility in the equities we tradedoptions
usinglong straddle
andshort stradle
strategy respectively. For intuition about these strategies we highly recommend watching following videos:
Firstly, we started with doing basic market research and findinghistorically the most and least volatile stocks
in the past1 week
,2 week
and a1 month
period in theRussel 3000 index
(in order to capture both the large-cap and the small-cap companies). From those stocks we chose the top 50 stocks with highest and the top 50 lowest historical weighted volatility:Weighted volatility = 0.5 * Vol_1_week + 0.3 * Vol_2_week + 0.2 * Vol_1_month
.
Using naive expecation for the future volatility based on the historical volatility, combined with the momentum detected from the daily P&L for the target companies, we enter intolong straddle
orshort straddle
positions.
Our MarketWatcher bot was alerting us for all potential investment opportunities. From the provided list oftarget stocks
, trading bot was sending usalerts via Email and Slack
, when target stocks havereached configured daily P&L threashold
:
- Long straddle - stocks with absolute daily P&L that are
greater
than5% P&L threashold
- Short straddle - stocks with absolute daily P&L that are
lower
than0.5% P&L threashold
Upon getting alerted by the MarketWatcher bot, wehand picked
into which long and short straddle positions to enter.
In the next iteration of development we intend to ship more IBKR TWS API functionality so that daily P&L is fetched from there. We would also like to automate the whole process, by first adding support to our trading bot to place orders on TWS and after that to fully implement algotrading strategy.
After cloning the repo, rename theenv.template
file to.env
and populate it with your settings:email notification interval time
,daily P&L threashold values
,email settings
,slack channel webhook links
, ...
Create.yaml file with target stocks
(ticker and long/short straddle strategy indicator for that ticker). MarketWatcher engine listens to real-time ticker data feed and notifies you when there is apotential opportunity for entering into long or short straddle options position
, with that stock as an underlying.
You can control MarketWatcher trading bot using simpleCLI
. After bot is started it will send us an email/slack messages for each investment opportunity it finds.
CLI commands:
market_watcher_cli --helpmarket_watcher_cli startmarket_watcher_cli stopmarket_watcher_cli config
Example CLI output upon starting MarketWatcher engine:
______ _ _ _ _ _ | ___ \ | | _ | || || | _ | | | | _ | | ____ ____| | _ ____| |_| || || | ____| |_ ____| | _ ____ ____ | || || |/ _ |/ ___) | / ) _ ) _) ||_|| |/ _ | _)/ ___) || \ / _ )/ ___) | || || ( ( | | | | |< ( (/ /| |_| |___| ( ( | | |_( (___| | | ( (/ /| | |_||_||_|\_||_|_| |_| \_)____)\___)______|\_||_|\___)____)_| |_|\____)_| MarketWatcher tool for finding investiments opportunities on Interacive Brokers for volatility trading on equity market using long and short options strategy. version: v0.1.0 Starting MarketWatcher... MarketWatcher started Reading target stocks from file: src/market_watcher/research/target_stocks.yaml Instantiating email notifier... Instantiating slack notifier... Instantiating MarketWatcher and running the engine
You can run cli tool from:
- Docker container (using docker-compose)
- Python virtual environment
Building docker image:
docker build -t ibkr --rm.
Running CLI from docker-compose:
docker-compose run --rm mw market_watcher_cli start
Install and activatre virtual environment for python 3.x:
python3 -m venv /path/to/new/virtual/environmentsource .venv/bin/activate
Install requirements:
pip install -r requirements.txt
Installibapi
(client for IBKR TWS API):
# Installing ibapicd src/market_watcher/ib_clientpython setup.py bdist_wheelpip install src/ib_client/dist/ibapi-9.76.1-py3-none-any.whl# Running ibapi testspython -m unittest discover -s src/ib_client/tests
cd srcpip install --editable.market_watcher_cli start --help
In order to receive the investment opportunities from MarketWatcher bot asSlack messages, you must first create a new Slack app in your workspace and enableIncoming-Webhooks. We expect to have two separate channels - one for receiving opportunities for a long straddle and the other for the short straddle strategies (see image bellow). Links for Slack webhooks need to be put in the.env
file.
Requirements for enablingTrader Workstation API:
- Download and installTrader Workstation
- Download and installIB Gateway
- Enable following setting in the TWS (
File -> Global Configuration -> API -> Settings
):- Enable ActiveX and Socket Clients
- Read-Only API (no order placing, only data reading for our scraping bot)
- Socket port: 7497 (Paper)/7496(Live)
- Allow connections from localhost only
- Create API message log file
- Logging Level: Error
- DownloadTWS API source code
About
Volatility trading using Long and Short Straddle options strategies on Interactive Broker using Yahoo Finance and TWS API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.