Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds options helper function for DTE, updates SDK trail map to not use yFinance. #4937

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def options(self):

Attributes:
`chains`: Get Option Chain For A Stock. No greek data is returned\n
`dte`: Gets days to expiration from yfinance option date\n
`dte`: Returns a new column containing the DTE as an integer, including 0.\n
`eodchain`: Get full EOD option date across all expirations\n
`expirations`: Get Option Chain Expirations\n
`generate_data`: Gets x values, and y values before and after premiums\n
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/core/sdk/models/stocks_sdk_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class StocksOptions(Category):

Attributes:
`chains`: Get Option Chain For A Stock. No greek data is returned\n
`dte`: Gets days to expiration from yfinance option date\n
`dte`: Returns a new column containing the DTE as an integer, including 0.\n
`eodchain`: Get full EOD option date across all expirations\n
`expirations`: Get Option Chain Expirations\n
`generate_data`: Gets x values, and y values before and after premiums\n
Expand Down Expand Up @@ -477,7 +477,7 @@ class StocksOptions(Category):
def __init__(self):
super().__init__()
self.chains = lib.stocks_options_sdk_helper.get_full_option_chain
self.dte = lib.stocks_options_yfinance_model.get_dte
self.dte = lib.stocks_options_helpers.get_dte
self.eodchain = lib.stocks_options_intrinio_model.get_full_chain_eod
self.expirations = lib.stocks_options_sdk_helper.get_option_expirations
self.generate_data = lib.stocks_options_yfinance_model.generate_data
Expand Down
1 change: 1 addition & 0 deletions openbb_terminal/core/sdk/sdk_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@
intrinio_model as stocks_options_intrinio_model,
intrinio_view as stocks_options_intrinio_view,
nasdaq_model as stocks_options_nasdaq_model,
op_helpers as stocks_options_helpers,
options_sdk_helper as stocks_options_sdk_helper,
options_view as stocks_options_view,
tradier_model as stocks_options_tradier_model,
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/core/sdk/trail_map.csv
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ stocks.ins.stats,stocks_insider_sdk_helper.stats,
stocks.load,stocks_helper.load,
stocks.news,common_ultima_newsmonitor_model.get_news,
stocks.options.chains,stocks_options_sdk_helper.get_full_option_chain,
stocks.options.dte,stocks_options_yfinance_model.get_dte,
stocks.options.dte,stocks_options_helpers.get_dte,
stocks.options.eodchain,stocks_options_intrinio_model.get_full_chain_eod,
stocks.options.expirations,stocks_options_sdk_helper.get_option_expirations,
stocks.options.generate_data,stocks_options_yfinance_model.generate_data,
Expand Down
19 changes: 16 additions & 3 deletions openbb_terminal/stocks/options/op_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# pylint: disable=too-many-arguments


@log_start_end(log=logger)
def get_strikes(
min_sp: float, max_sp: float, current_price: float
) -> Tuple[float, float]:
Expand Down Expand Up @@ -58,7 +57,6 @@ def get_loss_at_strike(strike: float, chain: pd.DataFrame) -> float:
return loss


@log_start_end(log=logger)
def calculate_max_pain(chain: pd.DataFrame) -> Union[int, float]:
"""Returns the max pain for a given call/put dataframe

Expand Down Expand Up @@ -104,7 +102,6 @@ def convert(orig: str, to: str) -> float:
raise ValueError("Invalid to format, please use '%' or ','.")


@log_start_end(log=logger)
def rn_payoff(x: str, df: pd.DataFrame, put: bool, delta: int, rf: float) -> float:
"""The risk neutral payoff for a stock
Parameters
Expand Down Expand Up @@ -594,3 +591,19 @@ def Vomma(self, change):
* norm.pdf(self.d1)
/ self._sigma
)


def get_dte(chain: pd.DataFrame) -> pd.DataFrame:
"""
Returns a new column containing the DTE as an integer, including 0.
Requires the chain to have the column labeled as, expiration.
"""
if "expiration" not in chain.columns:
raise ValueError("No column labeled 'expiration' was found.")

now = datetime.now()
temp = pd.DatetimeIndex(chain.expiration)
temp_ = (temp - now).days + 1
deeleeramone marked this conversation as resolved.
Show resolved Hide resolved
chain["dte"] = temp_

return chain