[Returnanalytics-commits] r2336 - pkg/PerformanceAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 17 14:25:54 CEST 2013


Author: braverock
Date: 2013-04-17 14:25:53 +0200 (Wed, 17 Apr 2013)
New Revision: 2336

Modified:
   pkg/PerformanceAnalytics/R/Return.portfolio.R
Log:
- use sum of the weights rather than 1 for first return after a conversation with Chinmay Patel to help account for leverage

Modified: pkg/PerformanceAnalytics/R/Return.portfolio.R
===================================================================
--- pkg/PerformanceAnalytics/R/Return.portfolio.R	2013-04-06 14:35:22 UTC (rev 2335)
+++ pkg/PerformanceAnalytics/R/Return.portfolio.R	2013-04-17 12:25:53 UTC (rev 2336)
@@ -184,8 +184,9 @@
       result = wealthindex
       result[2:length(result)] = result[2:length(result)] /
         lag(result)[2:length(result)] - 1
-      result[1] = result[1] - 1
-      w = matrix(rep(NA), ncol(wealthindex.assets) * nrow(wealthindex.assets), ncol = ncol(wealthindex.assets), nrow = nrow(wealthindex.assets))
+      #result[1] = result[1] - 1
+      result[1] = result[1] / sum(abs(weights[1,])) #divide by the sum of the first weighting vector to account for possible leverage
+	  w = matrix(rep(NA), ncol(wealthindex.assets) * nrow(wealthindex.assets), ncol = ncol(wealthindex.assets), nrow = nrow(wealthindex.assets))
       w[1, ] = weights
       w[2:length(wealthindex), ] = (wealthindex.weighted / rep(wealthindex, ncol(wealthindex.weighted)))[1:(length(wealthindex) - 1), ]
       weightedreturns = R[, colnames(weights)] * w



More information about the Returnanalytics-commits mailing list