绘制收益
最后,来比较机器学习生成的投资组合与仅持有 SPY 的表现。这样可以作为评估,判断我们的预测是否有效。
由于 algo_cash 和 spy_cash 已经创建完毕,只需把它们传给 plt.plot() 进行展示即可。我们还会在 plt.plot() 中设置 label,以便用 legend 显示各数据集的标签。
本练习是课程的一部分
Python 金融机器学习
练习说明
- 使用
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()