如题,学渣求解`
def calculate_sharpe(code):
'''
计算股票的夏普比率
:param code:
:return:
'''
data = ds.get_csv_price(code, 'price') # 打开file
daily_return = data['close'].pct_change() # 计算daily涨幅
avg_return = daily_return.mean() # daily平均
sharpe = avg_return/daily_return.std()
sharpe_year = sharpe*np.sqrt((252)) # 转换年夏普