mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
add option to configure options that get shown
This commit is contained in:
@@ -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
|
||||

|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user