[Returnanalytics-commits] r1973 - pkg/PerformanceAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jun 3 23:36:12 CEST 2012
Author: ababii
Date: 2012-06-03 23:36:12 +0200 (Sun, 03 Jun 2012)
New Revision: 1973
Modified:
pkg/PerformanceAnalytics/R/aggregate.R
Log:
Modified: pkg/PerformanceAnalytics/R/aggregate.R
===================================================================
--- pkg/PerformanceAnalytics/R/aggregate.R 2012-06-03 20:25:56 UTC (rev 1972)
+++ pkg/PerformanceAnalytics/R/aggregate.R 2012-06-03 21:36:12 UTC (rev 1973)
@@ -17,10 +17,11 @@
#'
aggregate <-
function(Rp, wp, h, level = "Sector"){
-
+
h = split(h$primary_id, h[level])
+ returns = as.xts(matrix(NA, ncol = length(h), nrow = nrow(Rp)), index(Rp))
for(j in 1:length(h)){
- for(i in length(h[[j]])){
+ for(i in 1:length(h[[j]])){
asset = h[[j]][i]
r = as.data.frame(Rp)[asset] * as.data.frame(wp)[asset]
r = as.xts(r)
@@ -30,13 +31,9 @@
} else{
rp = rp + r
}
- colnames(rp) = names(h[j])
}
- if (j == 1){
- returns = rp
- } else {
- returns = cbind(returns, rp)
- }
+ returns[, j] = rp
+ colnames(returns) = names(h)
}
return(returns)
}
@@ -61,5 +58,7 @@
colnames(wp) <- colnames(Rp)
# 2. Aggregate portfolio
-Rp <- aggregate(Rp, wp, hierarchy, "Sector")
-Rp
\ No newline at end of file
+Rp
+aggregate(Rp, wp, hierarchy, level = "Sector")
+aggregate(Rp, wp, hierarchy, level = "type")
+aggregate(Rp, wp, hierarchy, level = "currency")
\ No newline at end of file
More information about the Returnanalytics-commits
mailing list