tags:

views:

70

answers:

1
+1  Q: 

Drawdown duration

Hello

How can I get the duration of the drawdowns in a zoo serie? the drawdowns can be calculated with cummax(mydata)-mydata. Whenever this value is above zero I have a drawdown. The Drawdown is the measure of the decline from a historical peak (maximum). It lasts till this value is reached again.

A: 

The PerformanceAnalytics package has several functions to do this operation.

> library(PerformanceAnalytics)
> data(edhec)
> dd <- findDrawdowns(edhec[,"Funds of Funds", drop=FALSE])
> dd$length
 [1]  3  3  6  5  4 11 14  5  2 10  2  6  3  2  4  9  2  2 13  8  5  5  4  2  7
[26]  6 11  3  2 23

As a side note, if you have two dates in a time series and need to know the time between them, just use diff. You can also use the lubridate package.

Shane
I'm sorry for posting my comments as answers.I've used performanceAnalytics Drawdowns but it doens't work for me, even with the sample data supplied."Error en 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'."Anyway, how can I calculate the drawdown durations without using this package?thanks
Any solution with rle?