我正在尝试使用chart.CumReturns函数进行非常简单的计算。 不知何故,结果看起来完全奇怪。这不可能是正确的。有人可以指出错误吗?
data <- structure(list(Date = structure(c(15005, 15033, 15064, 15093,
15125, 15155, 15184, 15217, 15247, 15278, 15308, 15338, 15370,
15399, 15429, 15460, 15491, 15520, 15552, 15583, 15611, 15644,
15674, 15705, 15736, 15764, 15793, 15825, 15856, 15884, 15917,
15947, 15978, 16009, 16038, 16070, 16101, 16129, 16160, 16190,
16220, 16251, 16282, 16311, 16343, 16374, 16402, 16435, 16465,
16493, 16525, 16555, 16584, 16616, 16647, 16678, 16708, 16738,
16769, 16800, 16829, 16860, 16878), class = "Date"), close = c(28.31,
28.9, 27.95, 28.91, 28.85, 27.57, 26.86, 24.16, 22.94, 24.62,
24.26, 24.77, 25.81, 26.88, 26.58, 26.17, 24.64, 25.51, 26.52,
27, 27.11, 27.33, 27.94, 28.3, 29.11, 29.39, 29.67, 30.2, 30.9,
28.82, 30.39, 30.22, 31.31, 32.57, 32.87, 32.91, 32.41, 34.04,
33.64, 34.22, 35.23, 34.57, 34.03, 34.66, 34.4, 33.89, 35.04,
34.25, 36.98, 39.48, 40.02, 40.08, 40.73, 38.5, 40.14, 36.78,
34.91, 37.83, 38.81, 36.9, 34.28, 33.56, 34.13)), .Names = c("Date",
"close"), row.names = c(NA, -63L), class = "data.frame")
library(PerformanceAnalytics)
x <- xts(data$close, order.by = data$Date)
chart.CumReturns(x)
奇怪的是,我不得不使用order.by =
将数据转换为xts。
该图表看起来不对。回归飙升到最后。
但其他地方都是平坦的。
错误在哪里?
答案 0 :(得分:3)
chart.CumReturns
要求退货而不是价格,您需要将这些价格转换为退货。
e.g。
returns <- Return.calculate(x)
chart.CumReturns(returns)