From c2c2ceb78a6d98a34933d033e4f1a83b2ad9a6ea Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Sun, 3 Jul 2022 14:30:55 +0100 Subject: [PATCH 1/2] fix volatility of crypto --- .../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 11dafb4b7d65..64958a8a07a3 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(364)[-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) > 364: df["Volatility (1Y)"] = ( - str(round(100 * np.sqrt(252) * closes[:-252].pct_change().std(), 2)) + " %" + str(round(100 * np.sqrt(364) * closes[:-364].pct_change().std(), 2)) + " %" ) else: df["Volatility (Ann)"] = ( - str(round(100 * np.sqrt(252) * closes.pct_change().std(), 2)) + " %" + str(round(100 * np.sqrt(364) * closes.pct_change().std(), 2)) + " %" ) if len(volumes) > 7: df["Volume (7D avg)"] = lambda_long_number_format(np.mean(volumes[-9:-2]), 2) From f26c6df2be1a7d5664902d3c63bd68188f656267 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Sun, 3 Jul 2022 15:36:52 +0100 Subject: [PATCH 2/2] fix wrong annual value being used --- openbb_terminal/cryptocurrency/cryptocurrency_helpers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py index 64958a8a07a3..989d256fb0a3 100644 --- a/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py +++ b/openbb_terminal/cryptocurrency/cryptocurrency_helpers.py @@ -321,7 +321,7 @@ def show_quick_performance(crypto_df: pd.DataFrame, symbol: str, current_currenc "1D": 100 * closes.pct_change(2)[-1], "7D": 100 * closes.pct_change(7)[-1], "1M": 100 * closes.pct_change(30)[-1], - "1Y": 100 * closes.pct_change(364)[-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) > 364: + if len(closes) > 365: df["Volatility (1Y)"] = ( - str(round(100 * np.sqrt(364) * closes[:-364].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(364) * 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)