python如何计算夏普比率?
2024-08-01
来源:知网教育
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、夏普比率的计算公式为: