mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-12-01 13:44:16 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user