Commit 1b407b48 authored by 赵杰's avatar 赵杰

nan充值为0

parent a8ad4861
......@@ -91,7 +91,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 波动率
volatility_ = volatility(resample_df["cum_return_ratio"], n_freq)
folio_report_data["volatility"] = float(volatility_)
folio_report_data["volatility"] = float(volatility_) if not math.isnan(volatility_) else 0.0
# 最大回撤
drawdown = max_drawdown(resample_df["cum_return_ratio"])
......@@ -104,7 +104,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
sharpe = sharpe_ratio(exc, sim, n_freq)
except ZeroDivisionError:
sharpe = 0.0
folio_report_data["sharpe"] = float(sharpe)
folio_report_data["sharpe"] = float(sharpe) if not math.isnan(sharpe) else 0.0
# 期末资产
ending_assets = cumulative_profit + total_cost
......@@ -581,7 +581,7 @@ class UserCustomerResultAdaptor(UserCustomerDataAdaptor):
# 波动率
volatility_ = volatility(fund_nav_df["cum_return_ratio"], n_freq)
result["volatility"] = float(volatility_)
result["volatility"] = float(volatility_) if not math.isnan(volatility_) else 0.0
# 最大回撤
drawdown = max_drawdown(fund_nav_df["cum_return_ratio"])
......
......@@ -53,6 +53,8 @@ def sharpe_ratio(excess_return, simple_return, n):
d = math.sqrt(n) * excess_return / simple_return.std(ddof=1)
if d == float("inf") or d == float("-inf"):
return 0.0
if math.isnan(d):
return 0.0
except:
return 0.0
return d
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment