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>
This commit is contained in:
DidierRLopes
2022-07-04 08:22:25 +01:00
committed by GitHub
parent 2ffaace7c3
commit 0517135bc9

View File

@@ -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)