0

次の列を持つリターン時系列で構成されるデータフレームがあります

date x1 x3 x8 x11

x.Rリターンで構成される私のデータフレームです

パフォーマンス分析ツールでメソッド findDrawdowns を使用して、各時系列に適用したいと考えています。findDrawdowns からのすべての出力にアクセスできるように、結果をリストに保存したいと思います

sapply(x.R,  sortDrawdowns(findDrawdowns))

上記のコマンドは、以下を生成します。値にアクセスする方法がわからない..どんな助けでも大歓迎です!

             x1          x3         x8         x11      
return       Numeric,47 Numeric,47 Numeric,47 Numeric,49
from         Numeric,47 Numeric,47 Numeric,47 Numeric,49
trough       Numeric,47 Numeric,47 Numeric,47 Numeric,49 
to           Numeric,47 Numeric,47 Numeric,47 Numeric,49 
length       Numeric,47 Numeric,47 Numeric,47 Numeric,49 
peaktotrough Numeric,47 Numeric,47 Numeric,47 Numeric,49
recovery     Numeric,47 Numeric,47 Numeric,47 Numeric,49 
4

1 に答える 1

0

2次元で表示できないすべてのドローダウンを返すsapplyため、ネストが必要です(つまり、上記のテーブルの各セルにはすべてのドローダウンが含まれています。データを作成したソリューションは次のとおりです:sortDrawdowns

# Make up data
len=29
data <- data.frame(
  x1=rnorm(len, 0, .05),
  x3=rnorm(len, 0, .05),
  x8=rnorm(len, 0, .05),
  x11=rnorm(len, 0, .05)
)    
rownames(data) <- as.character(as.Date("2013-12-01") - (len:1))

# Get worst drawdowns    
sapply(
  names(data),    # for each entry in df
  function(x) {   
    sapply(       # cycle through each item in a drawDown object
      sortDrawdowns(findDrawdowns(data[, x, drop=F])),  # get drawdows sorted
      `[[`, 1                                           # extract 1st item
    )
  } 
)
#                      x1         x3         x8        x11
# return       -0.1887651 -0.3425831 -0.1592202 -0.2928802
# from         17.0000000  5.0000000 16.0000000  1.0000000
# trough       20.0000000 24.0000000 27.0000000 16.0000000
# to           25.0000000 30.0000000 30.0000000 30.0000000
# length        9.0000000 26.0000000 15.0000000 30.0000000
# peaktotrough  4.0000000 20.0000000 12.0000000 16.0000000
# recovery      5.0000000  6.0000000  3.0000000 14.0000000
于 2013-12-20T22:23:22.853 に答える