How can I get the durati开发者_JAVA技巧on 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.
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.
加载中,请稍侯......
精彩评论