diff --git a/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py b/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py index 6153e6da712f..e59f1e8dfdb8 100644 --- a/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py +++ b/openbb_terminal/core/sdk/controllers/stocks_sdk_controller.py @@ -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 diff --git a/openbb_terminal/core/sdk/models/stocks_sdk_model.py b/openbb_terminal/core/sdk/models/stocks_sdk_model.py index e1fe2fee3767..54c967b6918c 100644 --- a/openbb_terminal/core/sdk/models/stocks_sdk_model.py +++ b/openbb_terminal/core/sdk/models/stocks_sdk_model.py @@ -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 @@ -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 diff --git a/openbb_terminal/core/sdk/sdk_init.py b/openbb_terminal/core/sdk/sdk_init.py index 2fff36da3312..97e14106038f 100644 --- a/openbb_terminal/core/sdk/sdk_init.py +++ b/openbb_terminal/core/sdk/sdk_init.py @@ -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, diff --git a/openbb_terminal/core/sdk/trail_map.csv b/openbb_terminal/core/sdk/trail_map.csv index d1eeeba203e8..4a312a04d245 100644 --- a/openbb_terminal/core/sdk/trail_map.csv +++ b/openbb_terminal/core/sdk/trail_map.csv @@ -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, diff --git a/openbb_terminal/stocks/options/op_helpers.py b/openbb_terminal/stocks/options/op_helpers.py index 9b8a1dbb175d..55b205d74739 100644 --- a/openbb_terminal/stocks/options/op_helpers.py +++ b/openbb_terminal/stocks/options/op_helpers.py @@ -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]: @@ -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 @@ -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 @@ -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 + chain["dte"] = temp_ + + return chain