Fix scientific notation for zeros and options greeks (#1859)

* Force greeks table to show many zeros

* Disable scientific notation for zero

Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
This commit is contained in:
Theodore Aptekarev
2022-05-25 02:27:45 +03:00
committed by GitHub
parent 5f8eb43620
commit 46da0fca5e
3 changed files with 27 additions and 6 deletions

View File

@@ -159,8 +159,8 @@ def print_rich_table(
Title for index column
headers: List[str]
Titles for columns
floatfmt: str
String to
floatfmt: Union[str, List[str]]
Float number formatting specs as string or list of strings. Defaults to ".2f"
"""
if obbff.USE_TABULATE_DF:
@@ -197,7 +197,11 @@ def print_rich_table(
row += [
str(x)
if not isinstance(x, float)
else (f"{x:{floatfmt[idx]}}" if abs(x) >= 0.001 else f"{x:.2e}")
else (
f"{x:{floatfmt[idx]}}"
if isinstance(floatfmt, list)
else (f"{x:.2e}" if 0 < abs(x) <= 0.0001 else f"{x:floatfmt}")
)
for idx, x in enumerate(values)
]
table.add_row(*row)

View File

@@ -23,6 +23,7 @@ from .yfinance_view import plot_oi as oi_yf
from .yfinance_view import plot_plot as plot
from .yfinance_view import show_parity as parity
from .yfinance_view import show_binom as binom
from .yfinance_view import show_greeks as greeks
from .yfinance_view import display_vol_surface as vsurf

View File

@@ -1010,8 +1010,8 @@ def display_vol_surface(
@log_start_end(log=logger)
def show_greeks(
ticker: str,
div_cont: float,
expire: str,
div_cont: float = 0,
rf: float = None,
opt_type: int = 1,
mini: float = None,
@@ -1087,9 +1087,25 @@ def show_greeks(
"Vega",
"Theta",
]
column_formatting = [
".1f",
".4f",
".6f",
".6f",
".6f",
".6f",
]
if show_all:
columns += ["Rho", "Phi", "Charm", "Vanna", "Vomma"]
additional_columns = ["Rho", "Phi", "Charm", "Vanna", "Vomma"]
columns += additional_columns
column_formatting += [".6f"] * len(additional_columns)
df = pd.DataFrame(strikes, columns=columns)
print_rich_table(df, headers=list(df.columns), show_index=False, title="Greeks")
print_rich_table(
df,
headers=list(df.columns),
show_index=False,
title="Greeks",
floatfmt=column_formatting,
)
return None