mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Add more futures to curve (and probably some more bugs) (#5049)
* Add a while condition for futures curve * Fixes #5047 * Fixes #5014 * point root commands to /usage to avoid 404 * Black wont run in the nightly vs code build lol * #5071 * mypy * pylint * tests * Fix wrong queue to fa
This commit is contained in:
@@ -549,9 +549,9 @@ def generate_sdk(sort: bool = False) -> bool:
|
||||
"""
|
||||
trailmaps = get_trailmaps(sort)
|
||||
try:
|
||||
console.print("[yellow]Generating SDK...[/]")
|
||||
console.print("[yellow]Generating SDK...[/yellow]")
|
||||
BuildCategoryModelClasses(trailmaps).build()
|
||||
console.print("[green]SDK Generated Successfully.[/]")
|
||||
console.print("[green]SDK Generated Successfully.[/green]")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error generating SDK: {e}[/]")
|
||||
return False
|
||||
|
||||
@@ -1340,7 +1340,7 @@ class FixedIncomeController(BaseController):
|
||||
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True
|
||||
)
|
||||
if ns_parser:
|
||||
maturity = list_from_str(ns_parser.maturity)
|
||||
maturity = [m.replace(".0", "") for m in list_from_str(ns_parser.maturity)]
|
||||
category = list_from_str(ns_parser.category)
|
||||
|
||||
fred_view.plot_spot(
|
||||
|
||||
@@ -166,7 +166,7 @@ MOODY_TO_OPTIONS: Dict[str, Dict] = {
|
||||
"Spread": ["treasury", "fed_funds"], # type: ignore
|
||||
}
|
||||
SPOT_TO_OPTIONS = {
|
||||
"Maturity": [f"{i}y" for i in np.arange(1, 100.5, 0.5)],
|
||||
"Maturity": [f"{i}y".replace(".0", "") for i in np.arange(1, 100.5, 0.5)],
|
||||
"Category": ["spot_rate", "par_yield"],
|
||||
}
|
||||
CP_TO_OPTIONS = {
|
||||
|
||||
@@ -174,19 +174,27 @@ def get_curve_futures(
|
||||
|
||||
futures_index = list()
|
||||
futures_curve = list()
|
||||
for i in range(36):
|
||||
i = 0
|
||||
empty_count = 0
|
||||
# Loop through until we find 12 consecutive empty years
|
||||
while empty_count < 12:
|
||||
future = today + relativedelta(months=i)
|
||||
future_symbol = (
|
||||
f"{symbol}{MONTHS[future.month]}{str(future.year)[-2:]}.{exchange}"
|
||||
)
|
||||
|
||||
with HiddenPrints():
|
||||
data = yf.download(future_symbol, progress=False, ignore_tz=True)
|
||||
|
||||
if not data.empty:
|
||||
if data.empty:
|
||||
empty_count += 1
|
||||
|
||||
else:
|
||||
empty_count = 0
|
||||
futures_index.append(future.strftime("%b-%Y"))
|
||||
futures_curve.append(data["Adj Close"].values[-1])
|
||||
|
||||
i += 1
|
||||
|
||||
if not futures_index:
|
||||
return pd.DataFrame()
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ def get_full_chain_eod(symbol: str, date: str, quiet: bool = False) -> pd.DataFr
|
||||
>>> eod_chain = openbb.stocks.options.eodchain("AAPL", date="2022-12-23")
|
||||
|
||||
"""
|
||||
expirations = get_expiration_dates(symbol)
|
||||
expirations = get_expiration_dates(symbol, start=date)
|
||||
# Since we can't have expirations in the past, lets do something fun:
|
||||
# Note that there is an issue with using >= in that when the date = expiration, the dte will be 0, so iv*dte = 0*0
|
||||
expirations = list(filter(lambda x: x > date, expirations))
|
||||
@@ -336,7 +336,12 @@ def get_historical_options(symbol: str) -> pd.DataFrame:
|
||||
pd.DataFrame
|
||||
Dataframe of historical option chain
|
||||
"""
|
||||
historical = pd.DataFrame(api.get_options_prices_eod(symbol).to_dict()["prices"])
|
||||
try:
|
||||
historical = pd.DataFrame(
|
||||
api.get_options_prices_eod(symbol).to_dict()["prices"]
|
||||
)
|
||||
except Exception:
|
||||
return pd.DataFrame()
|
||||
historical = historical[
|
||||
[
|
||||
"date",
|
||||
|
||||
@@ -61,6 +61,10 @@ def display_historical(
|
||||
chain_id = f"{symbol}{''.join(expiry[2:].split('-'))}{'P' if put else 'C'}{str(int(1000*strike)).zfill(8)}"
|
||||
df_hist = intrinio_model.get_historical_options(chain_id)
|
||||
|
||||
if df_hist.empty:
|
||||
console.print(f"[red]No data found for {chain_id}[/red]")
|
||||
return None
|
||||
|
||||
if raw:
|
||||
print_rich_table(
|
||||
df_hist,
|
||||
|
||||
@@ -830,10 +830,7 @@ class OptionsController(BaseController):
|
||||
else None,
|
||||
)
|
||||
|
||||
if (
|
||||
ns_parser.source == "Tradier"
|
||||
and get_current_user().credentials.API_TRADIER_TOKEN != "REPLACE_ME"
|
||||
): # nosec
|
||||
if ns_parser.source == "Tradier": # nosec
|
||||
tradier_view.display_historical(
|
||||
symbol=self.ticker,
|
||||
expiry=self.selected_date,
|
||||
|
||||
@@ -103,14 +103,17 @@ def get_historical_options(
|
||||
else:
|
||||
symbol = chain_id
|
||||
|
||||
response = request(
|
||||
"https://sandbox.tradier.com/v1/markets/history",
|
||||
params={"symbol": {symbol}, "interval": "daily"},
|
||||
headers={
|
||||
"Authorization": f"Bearer {get_current_user().credentials.API_TRADIER_TOKEN}",
|
||||
"Accept": "application/json",
|
||||
},
|
||||
)
|
||||
try:
|
||||
response = request(
|
||||
"https://sandbox.tradier.com/v1/markets/history",
|
||||
params={"symbol": {symbol}, "interval": "daily"},
|
||||
headers={
|
||||
"Authorization": f"Bearer {get_current_user().credentials.API_TRADIER_TOKEN}",
|
||||
"Accept": "application/json",
|
||||
},
|
||||
)
|
||||
except requests.exceptions.ReadTimeout:
|
||||
return pd.DataFrame()
|
||||
|
||||
if response.status_code != 200:
|
||||
console.print("Error with request")
|
||||
|
||||
@@ -7,8 +7,9 @@ import warnings
|
||||
from typing import Optional
|
||||
|
||||
from openbb_terminal import OpenBBFigure
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
from openbb_terminal.decorators import check_api_key, log_start_end
|
||||
from openbb_terminal.helper_funcs import export_data, print_rich_table
|
||||
from openbb_terminal.rich_config import console
|
||||
from openbb_terminal.stocks.options import tradier_model
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -18,6 +19,7 @@ warnings.filterwarnings("ignore")
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
@log_start_end(log=logger)
|
||||
@check_api_key(["API_TRADIER_TOKEN"])
|
||||
def display_historical(
|
||||
symbol: str,
|
||||
expiry: str,
|
||||
@@ -57,6 +59,13 @@ def display_historical(
|
||||
symbol, expiry, strike, put, chain_id
|
||||
)
|
||||
|
||||
if df_hist.empty:
|
||||
if chain_id:
|
||||
console.print(f"No historical data found for {chain_id} ")
|
||||
return None
|
||||
console.print(f"No historical data found for {symbol} {expiry} ")
|
||||
return None
|
||||
|
||||
if raw:
|
||||
print_rich_table(
|
||||
df_hist,
|
||||
|
||||
@@ -745,6 +745,7 @@ class StocksController(StockBaseController):
|
||||
self.start,
|
||||
self.interval,
|
||||
self.stock,
|
||||
self.suffix,
|
||||
self.queue,
|
||||
)
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ def open_openbb_documentation(
|
||||
"news",
|
||||
"account",
|
||||
]:
|
||||
path = "/guides"
|
||||
path = "/usage"
|
||||
command = ""
|
||||
elif command in ["ta", "ba", "qa"]:
|
||||
path = f"/usage?path=/usage/intros/common/{command}"
|
||||
|
||||
Reference in New Issue
Block a user