mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
Get rid of option expirations in the past for Nasdaq + bugs (#2498)
* Get rid of option expirations in the past for Nasdaq + clean up bug * Add in currency for yfinance financials * Added fixes Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: colin99d <colin99delahunty@gmail.com>
This commit is contained in:
@@ -443,3 +443,12 @@ def get_earnings_history(symbol: str) -> pd.DataFrame:
|
||||
"""
|
||||
earnings = yf.Ticker(symbol).earnings_history
|
||||
return earnings
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def get_currency(symbol) -> str:
|
||||
"""Quick helper to get currency for financial statements"""
|
||||
ticker_info = yf.Ticker(symbol).info
|
||||
if "financialCurrency" in ticker_info:
|
||||
return ticker_info["financialCurrency"]
|
||||
return "Not Specified"
|
||||
|
||||
@@ -433,6 +433,9 @@ def display_fundamentals(
|
||||
if fundamentals.empty:
|
||||
# The empty data frame error handling done in model
|
||||
return
|
||||
|
||||
symbol_currency = yahoo_finance_model.get_currency(symbol)
|
||||
|
||||
if plot:
|
||||
rows_plot = len(plot)
|
||||
fundamentals_plot_data = fundamentals.transpose().fillna(-1)
|
||||
@@ -496,7 +499,7 @@ def display_fundamentals(
|
||||
print_rich_table(
|
||||
fundamentals.iloc[:, :limit].applymap(lambda x: "-" if x == "nan" else x),
|
||||
show_index=True,
|
||||
title=f"{symbol} {title_str}",
|
||||
title=f"{symbol} {title_str} Currency: {symbol_currency}",
|
||||
)
|
||||
export_data(
|
||||
export, os.path.dirname(os.path.abspath(__file__)), statement, fundamentals
|
||||
|
||||
@@ -11,6 +11,7 @@ import requests
|
||||
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
from openbb_terminal.rich_config import console
|
||||
from openbb_terminal.stocks.options.op_helpers import get_dte_from_expiration as get_dte
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -73,6 +74,9 @@ def get_full_chain(symbol: str) -> pd.DataFrame:
|
||||
}
|
||||
)
|
||||
)
|
||||
df["DTE"] = df["expirygroup"].apply(lambda t: get_dte(t))
|
||||
df = df[df.DTE > 0]
|
||||
df = df.drop(columns=["DTE"])
|
||||
return df
|
||||
|
||||
console.print(f"[red]{symbol} Option Chain not found.[/red]\n")
|
||||
|
||||
@@ -4,6 +4,7 @@ __docformat__ = "numpy"
|
||||
from math import e, log
|
||||
from typing import Union
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from scipy.stats import norm
|
||||
@@ -11,6 +12,32 @@ from scipy.stats import norm
|
||||
from openbb_terminal.rich_config import console
|
||||
|
||||
|
||||
def get_dte_from_expiration(date: str) -> float:
|
||||
"""
|
||||
Converts a date to total days until the option would expire.
|
||||
This assumes that the date is in the form %B %d, %Y such as January 11, 2023
|
||||
This calculates time from 'now' to 4 PM the date of expiration
|
||||
This is particularly a helper for nasdaq results.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
date: str
|
||||
Date in format %B %d, %Y
|
||||
|
||||
Returns
|
||||
-------
|
||||
float
|
||||
Days to expiration as a decimal
|
||||
"""
|
||||
# Get the date as a datetime and add 16 hours (4PM)
|
||||
expiration_time = datetime.strptime(date, "%B %d, %Y") + timedelta(hours=16)
|
||||
# Find total seconds from now
|
||||
time_to_now = (expiration_time - datetime.now()).total_seconds()
|
||||
# Convert to days
|
||||
time_to_now /= 60 * 60 * 24
|
||||
return time_to_now
|
||||
|
||||
|
||||
def get_loss_at_strike(strike: float, chain: pd.DataFrame) -> float:
|
||||
"""Function to get the loss at the given expiry
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ class OptionsController(BaseController):
|
||||
if self.expiry_dates and session and obbff.USE_PROMPT_TOOLKIT:
|
||||
self.choices["exp"] = {str(c): {} for c in range(len(self.expiry_dates))}
|
||||
self.choices["exp"]["-d"] = {c: {} for c in self.expiry_dates + [""]}
|
||||
if self.chain:
|
||||
if self.chain and self.source != "Nasdaq":
|
||||
self.choices["hist"] = {
|
||||
str(c): {}
|
||||
for c in self.chain.puts["strike"] + self.chain.calls["strike"]
|
||||
|
||||
Reference in New Issue
Block a user