繪製報酬
最後,來將機器學習產生的投資組合表現,和單純持有 SPY 的表現放在一起比較。你可以用這個結果來評估模型預測是否有效。
因為我們已經建立好 algo_cash 與 spy_cash,接下來只要把它們提供給 plt.plot() 顯示即可。同時,我們也會在 plt.plot() 中設定 label,並用 legend 顯示資料集的標籤。
本練習屬於課程
Python 金融 Machine Learning
練習說明
- 使用
plt.plot()繪製algo_cash(標籤為'algo')與spy_cash(標籤為'SPY')。 - 使用
plt.legend()顯示圖例。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the algo_cash and spy_cash to compare overall returns
plt.plot(____, ____)
plt.plot(spy_cash, label='SPY')
____ # show the legend
plt.show()