'Strange behavior with PerformanceAnalytics::FindDrawdown() function

require("quantmod"); require("PerformanceAnalytics");

ticker = "btc-usd"

FROM = "2015-01-01"
stk <- getSymbols(ticker,from=FROM,auto.assign = FALSE)
stkRETS = ROC(Ad(stk),type = "discrete")

findDrawdowns(na.omit(head(stkRETS$`BTC-USD.Adjusted`,n=291) ))

ERROR

Error in checkData(R) : The data cannot be converted into a time series. If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'. Rownames should have standard date formats, such as '1985-03-15'. In addition: Warning message: In if (class(x) == "numeric") { : the condition has length > 1 and only the first element will be used;


Ok let's try with n == 290:

findDrawdowns(na.omit(head(stkRETS$`BTC-USD.Adjusted`,n=290) ))
$return
[1]  0.0000000 -0.4346511

$from
[1] 1 2

$trough
[1]  1 13

$to
[1]   2 290

$length
[1]   2 289

$peaktotrough
[1]  1 12

$recovery
[1]   1 277

The findDrawdowns() function gives no error.

Inside the head() function when n == 291 the findDrawdown() returns a error, when n== 290 the the findDrawdown() dont return a error. Why this happen if the line 291 have a correct date and a non-NA value? Those two lines are basically this:

2015-10-17    0.02956235750
2015-10-18   -0.03324345810


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source