python如何计算夏普比率?
来源 :中华考试网 2020-11-28
中1、夏普比率的计算代码:
import numpy as np
import 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、夏普比率的计算公式为: