简体   繁体   English

R 中的动物园系列和总回报

[英]zoo series and aggregate returns in R

I want to have overall returns for data series over the whole of zoo series time perid, which I have in both a prices or daily returns;我想在整个动物园系列时间段内获得数据系列的总体回报,我在价格或每日回报中都有;

eg例如

                   GOLD           PA           PL  SLV
2001-05-22  0.000000000 -0.009132420 -0.004838710  0.0

or as prices where simple return would be last prices in series minus first / first或者作为简单回报将是系列中的最后价格减去第一个/第一个的价格

        GOLD   PA  PL SLV
2020-10-09 1920 2454 888  25

I've tried some performance analytic packages but I know the returns are wrong.我尝试了一些性能分析包,但我知道返回值是错误的。

Returns退货

Assuming the input data shown reproducibly in the Note at the end and using returns:假设输入数据在末尾的注释中可重复显示并使用返回值:

apply(rets + 1, 2, prod) - 1
##        GOLD          PA          PL         SLV 
##  0.00000000 -0.02714782 -0.01444600  0.00000000 

or要么

library(PerformanceAnalytics)
Return.cumulative(rets)
##                   GOLD          PA        PL SLV
## Cumulative Return    0 -0.02714782 -0.014446   0

or approximating using sums:或使用总和进行近似:

colSums(rets)
##        GOLD          PA          PL         SLV 
##  0.00000000 -0.02739726 -0.01451613  0.00000000 

Prices价格

or using prices:或使用价格:

n <- nrow(prices)
diff(prices[c(1, n)], arith = FALSE) - 1
##            GOLD PA          PL  SLV
## 2020-10-11    0  0 0.002252252 0.08

or using n from above:或从上面使用n

exp(diff(log(prices[c(1, n)]))) - 1
##            GOLD PA          PL  SLV
## 2020-10-11    0  0 0.002252252 0.08

Note笔记

Lines <- "
Date               GOLD           PA           PL  SLV
2001-05-22  0.000000000 -0.009132420 -0.004838710  0.0
2001-05-23  0.000000000 -0.009132420 -0.004838710  0.0
2001-05-24  0.000000000 -0.009132420 -0.004838710  0.0"

Lines2 <- "
Date       GOLD   PA  PL SLV
2020-10-09 1920 2454 888  25
2020-10-10 1900 2454 899  26
2020-10-11 1920 2454 890  27"

library(zoo)
rets <- read.zoo(text = Lines, header = TRUE)
prices <- read.zoo(text = Lines2, header = TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM