计算R中数据框的缩编

时间:2019-10-04 19:41:33

标签: r time-series finance

我有一个数据框已重塑为以下格式:

>library(PerformanceAnalytics)
>library(timeSeries)
>head(sapply(tseries, class))

$prhr
[1] "POSIXct" "POSIXt" 

$wind
[1] "numeric"

$AEC
[1] "numeric"

$AECI
[1] "numeric"

$ALTW
[1] "numeric"

$AMRN
[1] "numeric"

> head(tseries)
                 prhr wind       AEC      AECI      ALTW      AMRN       BBA       BCA      BLKW      BRAZ      BUBA BUFFALO_DUNES_WIND
1 2019-10-02 01:00:00 9738  2.939796  4.633800 -1.687404 -1.687404 -1.687404 -1.687404 -80.99390 -1.687404 -1.687404          -73.14030
2 2019-10-02 02:00:00 9971  6.154412  7.471112 -5.705150 -5.705150 -5.705150 -5.705150 -74.04989 -5.705150 -5.705150          -71.19274
3 2019-10-02 03:00:00 9490  2.248296  2.748600 -6.451404 -6.451404 -6.451404 -6.451404 -79.88890 -6.451404 -6.451404          -71.97920
4 2019-10-02 04:00:00 9409  0.098604  0.803304 -5.192604 -5.192604 -5.192604 -5.192604 -82.37130 -5.192604 -5.192604          -69.78970
5 2019-10-02 05:00:00 9342 -2.082600 -1.396896 -6.031800 -6.031800 -6.031800 -6.031800 -79.91960 -6.031800 -6.031800          -67.88330
6 2019-10-02 06:00:00 8844  2.253204  4.024800 -3.826596 -3.826596 -3.826596 -3.826596 -91.23570 -3.826596 -3.826596          -74.39740

“ prhr”列是以小时为单位的时间戳。数字列是该小时位置(AEC,AECI,ALTW等)的PnL。我想计算这些位置中的每个位置的压降。

我正在尝试使用Performance Analytics软件包进行计算。我曾尝试使用xts和zoo,但仍然收到错误“ drawdowns(x)中的错误:is.timeSeries(x)不正确”

我是R的新人。

0 个答案:

没有答案