Skip to content

CelebrateVC/OptionChainDecomp

Repository files navigation

OptionChainDecomp

One of the most powerful tools for option pricing for market makers is the Black-Scholes Model, which at it's base takes an understood forecast for the price of the underlying asset and performs a calculation to figure out the likelihood and payout amount at various prices and calculates the expected payout of the option under that assumption.

This tool looks to reverse that process to get an understanding of the future prices of the asset by investigating one expiration time and building up a combination of distributions that best models the option price.

To find an approximation of Pr(x) for the probability that the underlying asset reaches price x, Such that it satisfies

CallEquation

and

PutEquation

Pr(x) is determined using recursive minimization until a sufficient fit is produced following the logic below

The nature of the minimization is different between the two python files:

parser.py

this file will minimize changing every and all means, STD, and weights of all distributions, this is slower and generally does not lead to better results than the other file

optim.py

this file will minimize all weights and only the newest distribution's mean and STD. That is to say on iteration 1 it performs exactly the same as the other file, however after that the distriubtuion found in iteration 1 will be frozen and only it's weighting in the final output will change and so on for the next until iteration stops.


Regardless of the minimization used, the error function is as follows

That is to say:

  • The sum for each option k
    • the Sum for each weighted distribution i
      • the calculated price of a call as the integral above, using a Gaussian Standard Normal with given Mean and Standard Deviation
      • weighted by weighting factor
    • that result is the estimated call price (or put price if the specific option is a put, not pictured for brevity sake)
    • less the mark price of the option
    • the quantity squared
    • result multiplied by the natural log of the open interest for the option
  • divided by the sum of the natural logs of the open interest
  • the whole quantity under a square root

Inputs

Code takes in a MessagePack serialized format for increased space efficency from JSON the format of the file is a such

{
"GME":{  # Underlying ticker 
   150: { # Strike Price of Option
     "P": RobinhoodScrape
     "C": RobinhoodScrape
   } 
 }
}

Where the RobinhoodScrape objects are minimally

{
   "mark_price": 35.675,
   "open_interest": 45
}

or more auspicously, the full package from the api.robinhood.com/marketdata/options/?instruments= authenticated endpoint

{
    "occ_symbol": "GME   210430P00187500",
    "adjusted_mark_price": 35.68,
    "ask_price": 36.65,
    "ask_size": 41,
    "bid_price": 34.7,
    "bid_size": 67,
    "break_even_price": 151.82,
    "high_price": NaN,
    "instrument": "https://api.robinhood.com/options/instruments/dd6aa0c2-e238-48fc-9f4b-dc5ab25e20fb/",
    "instrument_id": "dd6aa0c2-e238-48fc-9f4b-dc5ab25e20fb",
    "last_trade_price": 34.05,
    "last_trade_size": 1.0,
    "low_price": NaN,
    "mark_price": 35.675,
    "open_interest": 45,
    "previous_close_date": "2021-04-20",
    "previous_close_price": 37.73,
    "volume": 0,
    "symbol": "GME",
    "chance_of_profit_long": 0.484926,
    "chance_of_profit_short": 0.515074,
    "delta": "-0.711753",
    "gamma": 0.008651,
    "implied_volatility": 1.588772,
    "rho": "-0.036565",
    "theta": "-0.747129",
    "vega": 0.084762,
    "high_fill_rate_buy_price": 36.34,
    "high_fill_rate_sell_price": 34.94,
    "low_fill_rate_buy_price": 35.6,
    "low_fill_rate_sell_price": 35.68,
    "Type": "P"
}

Make your own fancy scraper if you want

-or-

just have the devtools open (F12 on most browsers) and filter down on GET queries for "/marketdata/options/" view the pages that you want and right click save as HAR

This HAR will be a JSON file and in ["log"]["entries"][i]["responce"]["content"]["text"] there should be a json object as text, parse it and within that ["results"] should be a list of these objects that I have been using

all the heirarchial information is in the occ_symbol

  • the first 6 characters contain the ticker
  • the next 6 are the date in YYMMDD
  • the next 1 is if it is a Put or call
  • and the remaining characters are the strike price *1000

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages