Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Volatility trading using Long and Short Straddle options strategies on Interactive Broker using Yahoo Finance and TWS API

License

NotificationsYou must be signed in to change notification settings

mcf-long-short/ibkr-options-volatility-trading

Repository files navigation

MarketWatcher Python package

Introduction

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).

Trading strategy

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:

Trading Workflow

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 aregreater than5% P&L threashold
  • Short straddle - stocks with absolute daily P&L that arelower than0.5% P&L threashold

Upon getting alerted by the MarketWatcher bot, wehand picked into which long and short straddle positions to enter.

Future improvements

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.

How to use MarketWatcher trading bot?

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

1. Running in Docker

Building docker image:

docker build -t ibkr --rm.

Running CLI from docker-compose:

docker-compose run --rm mw market_watcher_cli start

2. Running in virtual environment

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

Installing MarketWatcher trading bot:

cd srcpip install --editable.market_watcher_cli start --help

Slack requirements

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.

IBKR requirements

Requirements for enablingTrader Workstation API:

  • Download and installTrader Workstation
  • Download and installIB Gateway
  • Enable following setting in the TWS (File -> Global Configuration -> API -> Settings):
    1. Enable ActiveX and Socket Clients
    2. Read-Only API (no order placing, only data reading for our scraping bot)
    3. Socket port: 7497 (Paper)/7496(Live)
    4. Allow connections from localhost only
    5. Create API message log file
    6. 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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp