python如何计算夏普比率?
1、夏普比率的计算代码:
import numpy as npimport pandas as pd
np.random.seed(0)
# Simulate cumulative returns of 100 days
N = 100
D = pd.DataFrame(np.random.normal(size=N))
R = D.cumsum()
# Calcute returns ratio
r = (R - R.shift(1))/R.shift(1)
sr = r.mean()/r.std() * np.sqrt(252)
print("sharpe ratio =", sr)
2、夏普比率的计算公式为:
以上是 python如何计算夏普比率? 的全部内容, 来源链接: utcz.com/z/527660.html