[Returnanalytics-commits] r2229 - pkg/PortfolioAnalytics/sandbox/attribution

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 9 17:35:31 CEST 2012


Author: ababii
Date: 2012-08-09 17:35:30 +0200 (Thu, 09 Aug 2012)
New Revision: 2229

Modified:
   pkg/PortfolioAnalytics/sandbox/attribution/test_suite.R
Log:
- updates test suit

Modified: pkg/PortfolioAnalytics/sandbox/attribution/test_suite.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/test_suite.R	2012-08-09 14:16:17 UTC (rev 2228)
+++ pkg/PortfolioAnalytics/sandbox/attribution/test_suite.R	2012-08-09 15:35:30 UTC (rev 2229)
@@ -1,7 +1,27 @@
-# TODO: test currencies, fixed effects and Brinson-Fachler
-# I. Check different options
+# Load the data
 data(attrib)
+Rp = attrib.returns[, 1:10]
+Rb = attrib.returns[, 11:20]
+rp = attrib.returns[, 21]
+rb = attrib.returns[, 22]
+Rf = attrib.returns[, 23:32]
+Rpl = attrib.returns[, 33:42]
+Rbl = attrib.returns[, 43:52]
+Rbh = attrib.returns[, 53:62]
 
+Dp = attrib.returns[, 63:72]
+Db = attrib.returns[, 73:82]
+wp = attrib.weights[1, ]
+wb = attrib.weights[2, ]
+wpf = attrib.weights[3, ]
+wbf = attrib.weights[4, ]
+h = attrib.hierarchy
+allocation = attrib.allocation
+F = attrib.currency[, 1:10]
+S = attrib.currency[, 11:20]
+
+# I. Check different options
+
 Attribution(Rp, wp, Rb, wb, method = "top.down", linking = "carino")
 Attribution(Rp, wp, Rb, wb, method = "bottom.up", linking = "menchero")
 Attribution(Rp, wp, Rb, wb, method = "none", linking = "grap")
@@ -16,7 +36,7 @@
 
 Weight.transform(wp, Rp)
 Return.level(Rp, wp, h, level = "MarketCap")
-Weight.level(wp, h, level = "Sector")
+Weight.level(wp, Rp, h, level = "Sector")
 
 Attribution.levels(Rp, wp, Rb, wb, h, c("type", "MarketCap", "currency", "Sector"))
 Attribution.levels(Rp, wp, Rb, wb, h, c("type", "currency", "Sector"))
@@ -25,6 +45,22 @@
 Return.annualized.excess(rp, rb)
 HierarchyQuintiles(h, "MarketCap")
 
+data(managers)
+Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12)
+Modigliani(managers[,1:6], managers[,8,drop=FALSE], managers[,8,drop=FALSE])
+Modigliani(managers[,1:6], managers[,8:7], managers[,8,drop=FALSE])
+MarketTiming(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, method = "HM")
+MarketTiming(managers[80:120,1:6], managers[80:120,7,drop=FALSE], managers[80:120,10,drop=FALSE])
+MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], method = "TM")
+CAPM.dynamic(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, Z=managers[, 9:10])
+CAPM.dynamic(managers[80:120,1:6], managers[80:120,7,drop=FALSE], Rf=managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+CAPM.dynamic(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+
+
+# !!! Run after amzn_test.R demo (from the blotter package) to get a dataset
+AcctReturns("amzn_acct", method = "timeweighted")
+AcctReturns("amzn_acct", method = "dietz") # NA because only 1 month in the data
+
 # II. Comparing with results in books
 # Data
 allocation <- matrix(c(0, -0.0104, -0.0016, -0.0072, -0.0086, 0.0108, 0.025, 0.0175, -0.0075, -0.003, -0.007, 0), 4, 3, TRUE)



More information about the Returnanalytics-commits mailing list