scan option spreads

Discussion in 'Options' started by met1989, Jul 10, 2019.

  1. met1989

    met1989

    Hey
    i was thinking if it its possible to create a scan on stock options that give me the ratio of the spread max win to max lose meaning if the butterfly has a max win of 300$ and max lose of 30$ so its good is it possible to scan for such thing
     
  2. toonerdy

    toonerdy

    It is obviously possible to write such software. Many brokers, such as Interactive Brokers, TD Ameritrade, and, I think, E-Trade, have programming interfaces for downloading option chains, and it is also possible to scrape them from web sites, such as finance.yahoo.com or nasdaq.com.

    You might want to keep in mind that a maximum profit of $300 and maximum loss of $30 does not necessarily mean that the expected return is positive.

    In case it helps you on your way, here is a shell script that should run on most Unix-like systems that have the "wget" command, which will scrape an option chain from Yahoo. That is, if you put it in a file named script.sh and then do something like "script.sh spy", it should print the option chain for SPY as a comma separated variable spreadsheet.

    #!/bin/bash

    if [ $# != 1 ] ; then
    echo "Usage: $0 symbol" >&2
    exit 1
    fi

    symbol=$1

    extract_word() {
    local word="$1"
    local line="$2"
    local rest=${line#*\"$word\":\{}
    local to_fmt=${rest#*\"fmt\":\"}
    echo "${to_fmt%%\"*}"
    return 0
    }

    print_line_csv() {
    local type="$1"
    local line="$2"
    local word

    echo -n "${type}"
    for word in expiration strike bid ask ; do
    echo -n ','$(extract_word "$word" "$line")
    done
    echo ""
    }

    get_page() {
    local symbol="$1"
    local symbol_and_rest="$2"
    wget --quiet --no-check-certificate --output-document=- \
    "https://finance.yahoo.com/quote/${symbol}/options?p=${symbol_and_rest}" |
    sed 's/>/>\'$'\n'"/g" |
    sed 's/{"contractSymbol":/\'$'\n''{"contractSymbol":/g'
    }

    print_expirations() {
    local line rest expiration
    egrep '^<option value="' |
    while read line ; do
    rest=${line#'<option value="'}
    expiration=${rest%%\"*}
    echo "$expiration"
    done
    }

    print_options() {
    local type
    while read line ; do
    case "$line" in
    *\"calls\":* ) type=call ;;
    *\"puts\":* ) type=put ;;
    \{\"contractSymbol\":* ) print_line_csv "$type" "$line" ;;
    esac
    done
    }

    symbol_cap=$(echo "$symbol" | tr a-z A-Z)

    for expiration in $(get_page "${symbol_cap}" "S{symbol}" | print_expirations) ; do
    get_page "${symbol_cap}" "${symbol}&date=${expiration}" |
    print_options
    done | sort -u
     
    tommcginnis likes this.
  3. ZBZB

    ZBZB

    Try the www.poweropt.com free trial. You can scan an options database on any strategy and multiple criteria. One you have it set up it will email you the results every day.
     
    tommcginnis likes this.
  4. Matt_ORATS

    Matt_ORATS Sponsor

    Good idea met1989 . My firm ORATS has a backtest scanner where you can set many options critieria and backtest the strategy and scan on the results. You can use exit rules as well. For example, we have "Exit Strike Diff %" where you exit once the price of the fly divided by the max profit or strike difference is a certain percentage. This is what you are asking for above to enter a trade (and I have made a request to add this feature on enter). Once you have a position on, our scanner also checks for exit.