用 Sharpe 比率評估策略表現
Sharpe 比率是由諾貝爾獎得主 William F. Sharpe 提出的風險調整後報酬衡量指標。它的計算方式是將超額報酬(相對於無風險利率)的平均值除以其標準差。
你將計算並檢視一個以訊號為基礎的策略之 Sharpe 比率。該策略使用兩個移動平均指標產生做多或做空的訊號,並以 Google 股票 3 年的歷史價格資料進行回測。回測統計已提供在 resInfo。
本練習屬於課程
Financial Trading in Python
練習說明
- 從
resInfo取得年化報酬與年化波動度,分別存為yearly_mean與yearly_vol。 - 使用
yearly_return與yearly_vol手動計算 Sharpe 比率。 - 列印從
resInfo直接取得的年化 Sharpe 比率。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get annual return and volatility
yearly_return = ____
print('Annual return: %.2f'% yearly_return)
yearly_vol = ____
print('Annual volatility: %.2f'% yearly_vol)
# Calculate the Sharpe ratio manually
sharpe_ratio = ____ / ____
print('Sharpe ratio calculated: %.2f'% sharpe_ratio)
# Print the Sharpe ratio
print('Sharpe ratio %.2f'% ____)