[Returnanalytics-commits] r2226 - pkg/PortfolioAnalytics/sandbox/attribution/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 9 14:59:55 CEST 2012
Author: ababii
Date: 2012-08-09 14:59:54 +0200 (Thu, 09 Aug 2012)
New Revision: 2226
Modified:
pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R
pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R
Log:
- stop and display warning if portfolio and benchmark returns are not conformable
Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R 2012-08-09 08:15:01 UTC (rev 2225)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R 2012-08-09 12:59:54 UTC (rev 2226)
@@ -106,7 +106,20 @@
wp = Weight.transform(wp, Rp)
wb = Weight.transform(wb, Rb)
wbf = Weight.transform(wbf, Rb)
-
+ if (ncol(Rb) == 1){
+ Rb = matrix(rep(coredata(Rb), ncol(Rp)), nrow(Rp), ncol(Rp))
+ }
+ if (ncol(Rb) != ncol(Rp)){
+ stop("Please use benchmark xts that has columns with benchmarks for each
+ asset or one common benchmark for all assets")
+ }
+ if (ncol(Db) == 1){
+ Db = matrix(rep(coredata(Db), ncol(Dp)), nrow(Dp), ncol(Dp))
+ }
+ if (ncol(Db) != ncol(Dp)){
+ print("Please use benchmark xts that has columns with benchmarks for each
+ asset or one common benchmark for all assets")
+ }
if (is.vector(WP) & is.vector(WB) & is.vector(WBF)){
rp = Return.portfolio(Rp, WP, geometric = geometric)
rb = Return.portfolio(Rb, WB, geometric = geometric)
Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R 2012-08-09 08:15:01 UTC (rev 2225)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R 2012-08-09 12:59:54 UTC (rev 2226)
@@ -205,6 +205,13 @@
Rp = Rp[2:nrow(Rp)]
Rb = Rb[2:nrow(Rb)]
}
+ if (ncol(Rb) == 1){
+ Rb = matrix(rep(coredata(Rb), ncol(Rp)), nrow(Rp), ncol(Rp))
+ }
+ if (ncol(Rb) != ncol(Rp)){
+ stop("Please use benchmark xts that has columns with benchmarks for each
+ asset or one common benchmark for all assets")
+ }
method = method[1]
linking = linking[1]
Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R 2012-08-09 08:15:01 UTC (rev 2225)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R 2012-08-09 12:59:54 UTC (rev 2226)
@@ -79,6 +79,13 @@
Rp = Rp[2:nrow(Rp)]
Rb = Rb[2:nrow(Rb)]
}
+ if (ncol(Rb) == 1){
+ Rb = matrix(rep(coredata(Rb), ncol(Rp)), nrow(Rp), ncol(Rp))
+ }
+ if (ncol(Rb) != ncol(Rp)){
+ stop("Please use benchmark xts that has columns with benchmarks for each
+ asset or one common benchmark for all assets")
+ }
levels <- unlist(list(...))
if (!is.null(levels)) stopifnot(is.character(levels))
More information about the Returnanalytics-commits
mailing list