【问题标题】:why maxDrawdown function in package PerformanceAnalytics returns wrong result?为什么包 PerformanceAnalytics 中的 maxDrawdown 函数返回错误的结果?
【发布时间】:2015-11-17 17:08:23
【问题描述】:

我想使用 PerformanceAnalytics 包中的maxDrawdown 函数来计算最大回撤,但发现它总是返回零(不是)。

我像这样使用maxDrawdown

> maxDrawdown(my.xts)
[1] 0

我的xts是这样的:

> my.xts
           value
2004-06-16 4.150
2004-06-17 4.225
2004-06-18 4.025
2004-06-21 4.000
2004-06-23 4.425
2004-06-24 4.450
2004-06-25 4.400
2004-06-28 4.325
2004-06-29 4.325
2004-06-30 4.300
2004-07-02 4.350
2004-07-06 4.400
2004-07-07 4.275
2004-07-08 4.100
2004-07-09 4.075
2004-07-12 4.000
2004-07-13 4.025
2004-07-14 3.800
2004-07-15 3.675
2004-07-16 3.700

str(my.xts) 返回

An ‘xts’ object on 2004-06-16/2004-07-16 containing:
  Data: num [1:20, 1] 4.15 4.22 4.03 4 4.42 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "value"
  Indexed by objects of class: [POSIXct,POSIXt] TZ:-
  xts Attributes:--
 NULL

而且,我写了一个函数来验证

my.mmd <- function(v) {
  max(1 - v / cummax(v))
}

结果不为零。

> my.mmd(my.xts$value)
[1] 0.1741573

为什么 maxDrawdown 返回 0 ?


我使用http://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp 构造一个案例。

other.xts <- xts(c(500,750,400,600,350, 800), Sys.Date() + 1:6)
maxDrawdown(other.xts) # --> here still returns 0!
my.mmd(other.xts)  # -> my function returns 0.5333333, seems right.

也许我以错误的方式使用maxDrawdown 函数!但是我再次浏览了文档(),仍然无法得到它。我在使用这个功能时有什么遗漏吗?

【问题讨论】:

  • xts 中没有maxDrawdown。您是指PerformanceAnalytics 中的maxDrawdown 吗?
  • 对不起.. 是的,我的意思是 PerformanceAnalytics。
  • 使用data(edhec)x &lt;- edhec[,"Funds of Funds"]maxDrawdown(x)给出0.2059145,而你的函数(my.mmd(x))给出2.416092

标签: r xts performanceanalytics


【解决方案1】:

您的 xts 对象包含价格数据与退货,这就是您收到 maxDrawdown = 0 的原因

例如:

 # Using Prices instead of returns to calculate Drawdowns
a <- Ad(getSymbols("AAPL", auto.assign = FALSE))

head(a)
           AAPL.Adjusted
2007-01-03      11.19449
2007-01-04      11.44295
2007-01-05      11.36147
2007-01-08      11.41757
2007-01-09      12.36603
2007-01-10      12.95782

maxDrawdown(head(a))
[1] 0

现在使用 Returns:

# Nice wrapper to calculate returns via PerformanceAnalytics
ret <-CalculateReturns(head(a), "discrete")

> head(ret)
           AAPL.Adjusted
2007-01-03            NA
2007-01-04   0.022195570
2007-01-05  -0.007121151
2007-01-08   0.004938271
2007-01-09   0.083070194
2007-01-10   0.047855606
> maxDrawdown(ret)
[1] 0.007121151

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2016-05-28
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多