add option to configure options that get shown

This commit is contained in:
Jamie
2021-04-19 13:57:40 -04:00
parent a158e02594
commit afee28a997
2 changed files with 34 additions and 12 deletions

View File

@@ -84,6 +84,17 @@ Display options chains. [Source: Tradier]
* --puts : Flag to show puts only
* -m : Minimum strike price to consider.
* -M : Maximum strike price to consider.
* -d : Columns to display. Should be comma separated. Must be in `['bid', 'ask', 'strike', 'bidsize', 'asksize', 'volume', 'open_interest',
'delta', 'gamma', 'theta', 'vega', 'ask_iv', 'bid_iv','mid_iv']`
<img width="948" alt="chains" src="https://user-images.githubusercontent.com/25267873/115161876-f708ff80-a097-11eb-8073-195979862a45.png">
To change what columns are displayed, one can use the `-d` flag. To show the same as above, but only the ask, ask size
delta and theta variables, we would do:
````
chains -m 129 -M 135 -d ask,ask_size,delta,theta
````
Which outputs
![im2](https://user-images.githubusercontent.com/18151143/115276719-640cab80-a111-11eb-84a2-4dc6a1685946.png)

View File

@@ -27,6 +27,15 @@ greek_columns = ["delta", "gamma", "theta", "vega", "ask_iv", "bid_iv", "mid_iv"
df_columns = option_columns + greek_columns
column_map = {"mid_iv": "iv", "open_interest": "oi", "volume": "vol"}
default_columns = [
"mid_iv",
"delta",
"volume",
"open_interest",
"bid",
"ask",
]
def process_chains(response: requests.models.Response) -> pd.DataFrame:
"""
@@ -124,25 +133,26 @@ def display_chains(symbol: str, expiry: str, other_args: List[str]):
default=-1,
help="maximum strike price to consider.",
)
parser.add_argument(
"-d",
"--display",
dest="to_display",
default=default_columns,
help="columns to look at",
)
chains_df = get_option_chains(symbol, expiry)
default_columns = [
"mid_iv",
"delta",
"volume",
"open_interest",
"bid",
"ask",
"strike",
"option_type",
]
chains_df = chains_df[default_columns].rename(columns=column_map)
try:
ns_parser = parse_known_args_and_warn(parser, other_args)
if not ns_parser:
return
if isinstance(ns_parser.to_display, str):
columns = list(ns_parser.to_display.split(",")) + ["strike", "option_type"]
if isinstance(ns_parser.to_display, list):
columns = ns_parser.to_display + ["strike", "option_type"]
chains_df = chains_df[columns].rename(columns=column_map)
if ns_parser.max_sp == -1 and ns_parser.min_sp == -1:
min_strike = np.percentile(chains_df["strike"], 25)
max_strike = np.percentile(chains_df["strike"], 75)
@@ -209,3 +219,4 @@ def display_chains(symbol: str, expiry: str, other_args: List[str]):
print(e)
print("")
return