From 0517135bc93476fd9329c408a76827950b3e6000 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Mon, 4 Jul 2022 08:22:25 +0100 Subject: [PATCH] Fix volatility of crypto (#2039) * fix volatility of crypto * fix wrong annual value being used Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com> --- .../cryptocurrency/cryptocurrency_helpers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py index 11dafb4b7d6..989d256fb0a 100644 --- a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py +++ b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py @@ -319,9 +319,9 @@ def show_quick_performance(crypto_df: pd.DataFrame, symbol: str, current_currenc perfs = { "1D": 100 * closes.pct_change(2)[-1], - "7D": 100 * closes.pct_change(5)[-1], - "1M": 100 * closes.pct_change(21)[-1], - "1Y": 100 * closes.pct_change(252)[-1], + "7D": 100 * closes.pct_change(7)[-1], + "1M": 100 * closes.pct_change(30)[-1], + "1Y": 100 * closes.pct_change(365)[-1], } first_day_current_year = str(datetime.now().date().replace(month=1, day=1)) if first_day_current_year in closes.index: @@ -333,13 +333,13 @@ def show_quick_performance(crypto_df: pd.DataFrame, symbol: str, current_currenc df = pd.DataFrame.from_dict(perfs, orient="index").dropna().T df = df.applymap(lambda x: str(round(x, 2)) + " %") df = df.applymap(lambda x: f"[red]{x}[/red]" if "-" in x else f"[green]{x}[/green]") - if len(closes) > 252: + if len(closes) > 365: df["Volatility (1Y)"] = ( - str(round(100 * np.sqrt(252) * closes[:-252].pct_change().std(), 2)) + " %" + str(round(100 * np.sqrt(365) * closes[:-365].pct_change().std(), 2)) + " %" ) else: df["Volatility (Ann)"] = ( - str(round(100 * np.sqrt(252) * closes.pct_change().std(), 2)) + " %" + str(round(100 * np.sqrt(365) * closes.pct_change().std(), 2)) + " %" ) if len(volumes) > 7: df["Volume (7D avg)"] = lambda_long_number_format(np.mean(volumes[-9:-2]), 2)