-
Notifications
You must be signed in to change notification settings - Fork 28
Option Contracts
Julian Traversa edited this page Jun 4, 2020
·
3 revisions
strikes = a.get_strike_prices('TSLA')
dates = a.get_exp_dates('tsla')
Ally provides a flexible interface to search for contracts that meet certain criteria, like strike price, or expiration date, among other things.
Queryable fields:
- strikeprice (possible values: 5 or 7.50, integers or decimals)
- xdate (YYYYMMDD)
- xmonth (MM)
- xyear (YYYY)
- put_call ('put' or 'call')
- unique ('strikeprice', 'xdate')
Operators:
- LT (<)
- GT (>)
- LTE (<=)
- GTE (>=)
- EQ (==)
Leave fields
empty to get everything, otherwise specify what you want, in list form, or comma-separated.
available_options = a.search_options(
symbol='SPY',
query=["xdate-eq:20201231","strikeprice-eq:180"], # Mature on 2020-12-31
fields=['bid','ask'] # 'bid,ask' also works. Function properly formats a list or a string
)
The package has a simpler interface to grab the contracts chain for a specific symbol, on a specific date, with some range of the expiration.
Be aware that this call is a little slower than a search, since it grabs the current price before executing the options search.
If direction
has a 'c' in it, it's interpreted as a call. It's probably wisest to use 'call' or 'put' for readability.
gold_chains = a.options_chain(
symbol='gld',
direction='call', # 'c', or 'cat' are all valid
within_pct=20.0, # grab all strikes (80% <= x <= 120%) of current price X
exp_date='20201231' # 2020-12-31
)