开始使用免费开始使用

历史回撤

股票市场长期来看往往上涨,但这并不意味着不会经历回撤期。

回撤可以衡量为相对于历史最高点的累计回报的百分比亏损。

在 Python 中,您可以使用 .accumulate().maximum() 函数计算运行中的最大值,并使用下面的简单公式计算回撤:

$$ \text{Drawdown} = \frac{r_t}{RM} - 1$$

  • $r_t$:时点 t 的累计回报
  • $RM$:运行中的最大值

USO(跟踪油价的 ETF)的累计回报已存储在变量 cum_rets 中。

本练习是课程的一部分

Python 投资组合风险管理入门

查看课程

练习说明

  • 使用 np.maximum.accumulate() 计算 USO 原油 ETF(cum_rets)的累计回报的运行最大值。
  • 当运行最大值(running_max)低于 1 时,将其设为 1。
  • 使用上面的简单公式结合 cum_retsrunning_max 计算 drawdown
  • 查看图表。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Calculate the running maximum
running_max = ____(cum_rets)

# Ensure the value never drops below 1
running_max[____] = 1

# Calculate the percentage drawdown
drawdown = (____)/____ - 1

# Plot the results
drawdown.plot()
plt.show()
编辑并运行代码