Giter VIP home page Giter VIP logo

tos_options_dashboard's Introduction

ThinkOrSwim (TOS) Options Dashboard

Project Description:

An interactive dashboard to filter and analyze stock options contracts (Built using data from ThinkOrSwim's Option Chain API and Plotly Dash components). It is useful for quickly scanning option chains to look for individual profitable options contracts to trade on.

Filter options include:

  • Return of Investment (ROI) Range: Percentage of premium received (by selling an contract) over the underlying amount (strike price * 100)
  • Delta Range: Represents current probability that the option contract will expire in-the-money (i.e. Option is exercised)
  • Option Contract Type: Call/Put/All (both call and put options)
  • Days to expiration: No. of days till options contract is set to expire
  • Confidence Level: Represents the level of confidence in which the stock price is likely to be within the probability cone. A higher confidence level would result in a wider probability cone.
  • Historical Volatility Period: Changes the width of the probability cone calculation based on past period historical volatility (Past month, past 3 months, past year). For example, historical volatility of 40% would result in a wider probability curve than that based on a historical volatility of 25%.

Pre-requisites:

  1. Set-up a TDAmeritrade Developer account to receive an API key. This key is necessary to authenticate each API call to extract the necessary data (e.g. stock quote date, option chain data) to required to perform financial analysis.

  2. Activate virtual environment in the directory of choice and install the necessary libraries outlined in requirements.txt .

    pip install -r requirements.txt
  3. [Docker Option] To build and run the docker container, run the following lines in the terminal/command prompt. After running docker run, proceed with step 2 of the Usage section.

    docker build -t tos_options_dashboard .
    docker run -p 8050:8050 tos_options_dashboard
    
    • Note: You can override the default value of the TOS API Key set in Dockerfile by running the following command during build

      docker build --build-arg api_key=<NEW_API_KEY> -t tos_options_dashboard .

Usage:

  1. Run the python file dashboard.py

    python dashboard.py
  2. The Dashboard would be running on local host (Port: 8050) by default. Open the web browser and enter the corresponding localhost address (http://127.0.0.1:8050/) to view the Dashboard.

  3. To start using the Dashboard, activate Ticker mode before entering the stock ticker of interest (e.g. AAPL for Apple Inc. stock).

    Alternatively, you can type 'Apple' without activating Ticker mode to search for a particular option underlying.

    There are several options property filter options to choose from:

    • Return on Investment (ROI) Range: (Default: More than 1%)
    • Delta Range: (Default: Ignore Delta value)
    • Option Contract Type: Call/Put/All (Default: All)
    • Day(s) to Expiration: 0-100 days (Default: 0-14 days)
    • Confidence Level: (Default: 30% Confidence)
    • Historical Volatility Level: (Default: 1 Month)
    • Volaility Estimator: (Default: Log Returns/Standard Deviation)

    To proceed with the search function, select on the Submit button.

    step3-search

  4. The corresponding historical price charts for the specified stock ticker is generated along with the associated cone of probability (Default: 30% confidence level).

    step4-results

  5. The open interest and volume of the options chain is generated with the rolling estimated volatilities using different estimators. Note: The options chain with expiry date closest to the 'Day(s) to Expiration' field is used before manual selection from the dropdown field (i.e. if option 0-14 days is selected, the graph will show the option chain with number of expiry days closest to 14 first)

    • Standard Deviation: Using defintion of standard deviation to derive volatility
    • Parkinson: The Parkinson model uses daily High and Low prices and has no drift term. Its efficiency intuitively comes from the fact that the price range of intraday gives more information regarding the future volatility than two arbitrary points in the series. It uses range the highest value –the lowest value variance instead of a widely used method for estimating variance of Log- transformed stock returns.
    • Garman & Klass: The Garman & Klass volatility estimator which make use of daily Opening, Closing, High and Low prices of the stock. The estimator assumes the underlying process is govern by Brownian motion with zero drift and has no opening jump.
    • Rogers & Satchell: Rogers & Satchell volatility estimator is independent of the drift and Independent of opening gaps weighted average is the Rogers-Satchell. The estimator makes use of the Open-Close volatility and Close-Open volatility. When the estimator is heavily dominated by opening jumps, its performance degrades to the classical Close-to-Close estimator
    • Yang Zhang: Yang Zhang volatility estimator has the following properties:
      1. Independent of the drift;
      2. Independent of opening gaps weighted average of Rogers-Satchell, Open-Close and Close-Open volatility;
      3. When heavily dominated by opening jumps, the performance degrades to classical Close-to-Close volatility estimator.

    step5-results

  6. The dashboard also measures the Call / Put skew of the specified ticker, as well as listing the option contracts that matches the filter requirements in Step 3.

    • Put Skew: Defined as the price of 10% OTM puts/10% OTM calls for the next monthly option expiry
    • Call Skew: Defined as the price of 10% OTM calls/10% OTM puts for the next monthly option expiry.

    step6-results

Citations

  1. Oyediran, Oyelami & Sambo, Eric. (2017). Comparative Analysis of Some Volatility Estimators: An Application to Historical Data from the Nigerian Stock Exchange Market. 4. 13-35.
  2. jasonstrimpel (2021) volatility-trading [Source Code]. https://github.com/jasonstrimpel/volatility-trading

tos_options_dashboard's People

Contributors

bernardcheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tos_options_dashboard's Issues

Numpy failure (Prereq Related)

Ran into this after "python dashboard.py"

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
.....................
Please note and check the following:

  * The Python version is: Python3.7 from "/usr/bin/python"
  * The NumPy version is: "1.19.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory

This error happens even if the pre-reqs are met

pi@raspberrypi:~/tos/tos_options_dashboard $ python -V
Python 3.7.3
pi@raspberrypi:~/tos/tos_options_dashboard $ which python
/usr/bin/python
pi@raspberrypi:~/tos/tos_options_dashboard $ pip list|grep -i numpy
numpy                     1.19.1

This is apparently due to Numpy 14772 the root cause is explained within. Anyways the solution works in case anyone else runs into the same issue

sudo apt-get install libatlas-base-dev

Feature: add error reporting

the update_search function should add error reporting. Currently there is no indication of why the UI doesnt accept ticker values which can happen if the API_KEY is invalid.

  def update_search(search_value, ticker_switch, value):  
        print ('search value',search_value, 'ticker',ticker_switch, value)
       

        if not search_value:
            print ('preventing updates')
            raise PreventUpdate
        
        if ticker_switch:
            json_data = tos_search(search_value, projection='symbol-search', apiKey=API_KEY)
        else:
            json_data = tos_search(search_value, projection='desc-search', apiKey=API_KEY)
        
        if 'error' in json_data:
            print (f'Error in query results. Possible API key issues: json_data erturned: {json_data}')

contract type not working

contract_type was not getting used - following change fixes it

    # Temporarily stores JSON data in the browser (generally safe to store up to 2MB of data)
    @app.callback(Output('storage-option-chain-all', 'data'),
                [Input('submit-button-state', 'n_clicks'), Input('storage-historical', 'data'), Input('storage-quotes', 'data')],
                [State('memory-ticker', 'value'), State('memory-expdays','value'), State('memory-confidence','value'),State('memory-contract-type','value')]
                )
    def get_option_chain_all(n_clicks, hist_data, quotes_data, ticker, expday_range, confidence_lvl, contract_type):

        if ticker is None:
            raise PreventUpdate 

        json_data = tos_get_option_chain(ticker, contractType=contract_type, rangeType='ALL', apiKey=API_KEY) # changed from 'ALL'

New features.

Great tool , add please max pain plot (price between open put/call interest) and % OTM indicator like ROI in main dashboard πŸ™πŸ»

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.