Skip to content

Commit

Permalink
Adds options helper function for DTE, updates SDK trail map to not us…
Browse files Browse the repository at this point in the history
…e yFinance. (#4937)

* adds options helper function for DTE

* removes logging decorator

* More decorators

---------

Co-authored-by: James Maslek <[email protected]>
  • Loading branch information
deeleeramone and jmaslek authored May 1, 2023
1 parent 25b8bd9 commit 845564c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
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
chain["dte"] = temp_

return chain

0 comments on commit 845564c

Please sign in to comment.