開始使用免費開始

檢視回測的報酬結果

你用簡單移動平均指標實作了一個順勢策略。你以 2019 到 2020 年的 Amazon 股價歷史資料進行回測,右側顯示了結果圖。現在你想要檢視回測結果中的報酬統計。

bt 的回測結果已提供在 bt_result,可直接使用。

本練習屬於課程

Financial Trading in Python

檢視課程

練習說明

  • bt_result 取得所有回測統計,並儲存到 resInfo
  • resInfo 列印日、月、年報酬。
  • resInfo 列印複合年成長率(CAGR)。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Obtain all backtest stats
resInfo = ____

# Get daily, monthly, and yearly returns
print('Daily return: %.4f'% ____)
print('Monthly return: %.4f'% ____)
print('Yearly return: %.4f'% ____)

# Get the compound annual growth rate
print('Compound annual growth rate: %.4f'% ____)
編輯並執行程式碼