XTS 被称为“x”,具有七种货币的每日回报。
x=structure(c(0, 0, -0.00237747604278071, -4.10901316858503e-05,
-0.00292075554430804, -0.00327746821541597, 0, 0, -0.0024832242245989,
-7.13774881431206e-05, -0.00288771987280823, -0.00239072530655426,
0, 0, -0.00238446679144366, -0.00169293890925615, -0.0036441365731773,
-0.00370471543592221, 0, 0, -0.00244664834224606, 0, -0.00285354593582876,
-0.00288034192721653, 0, 0, -0.00310375411764707, -0.00146643546387215,
-0.00427725501167975, -0.00376793265740194, 0, 0, -0.00183281566844917,
0, -0.00294652695187159, -0.0021703202366018, 0, 0, -0.00243030417112311,
-0.000372071536924534, -0.00330455837816801, -0.00245257154873846
), class = c("xts", "zoo"), index = structure(c(1297296000, 1297382400,
1297641600, 1297728000, 1297814400, 1297900800), tzone = "UTC", tclass = "Date"), .Dim = 6:7, .Dimnames = list(
NULL, c("AUD", "EUR", "GBP", "JPY", "KRW", "TWD", "USD")))
我已经使用 PerformanceAnalytics 函数 Drawdowns 来计算和绘制累积下降,这很好。但是,我也想要滚动 60 天的回撤,并尝试了 rollapply 和 apply.rolling 但没有运气。
任何人都可以推荐一个解决方案吗?
structure(c(0.00371570839572193, 0.00118836834224599, -0.00237747604278075,
0.00234195385026738, -0.00287978374331551, -0.000357757593582888,
0.00265543171122995, 0.000720424064171123, -0.00248322422459893,
0.00241785080213904, -0.00281654342245989, 0.000498433903743315,
0.00302572497326203, 0.00161579593582888, -0.00238446679144385,
0.000693180748663102, -0.00195450652406417, -6.08004278074866e-05,
0.00387943005347594, 0.00128238518716578, -0.00244664834224599,
0.00274308647058824, -0.00285354593582888, -2.68726737967914e-05,
0.00367270588235294, 0.00235053556149733, -0.00310375411764706,
0.00164241631016043, -0.00281494748663102, 0.000511510213903743,
0.00330757946524064, 0.00212843374331551, -0.0018328156684492,
0.00260363310160428, -0.00294652695187166, 0.000778500588235294,
0.00273476534759358, 0.000962438395721925, -0.00243030417112299,
0.00206324695187166, -0.00293357834224599, 0.000854811604278075
), class = c("xts", "zoo"), index = structure(c(1297296000, 1297382400,
1297641600, 1297728000, 1297814400, 1297900800), tzone = "UTC", tclass = "Date"), .Dim = 6:7, .Dimnames = list(
NULL, c("AUD", "EUR", "GBP", "JPY", "KRW", "TWD", "USD")))
rollapply(x, width = 60, FUN = Drawdowns)
数组中的错误(ans, c(len.a%/%d2, d.ans), if (!is.null(names(dn.ans)) || : 'dimnames' [1] 的长度不等于数组程度
apply.rolling(x, width = 60, FUN = SharpeRatio)
rbind(calcs, calc) 中的错误:矩阵的列数必须匹配(参见参数 2)