[Blotter-commits] r1493 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 14 05:08:04 CEST 2013
Author: bodanker
Date: 2013-08-14 05:08:03 +0200 (Wed, 14 Aug 2013)
New Revision: 1493
Modified:
pkg/blotter/R/updatePortf.R
Log:
- another attempt to remove duplicate indices in summary data
(also remove some of Brian's tabs... :)
Modified: pkg/blotter/R/updatePortf.R
===================================================================
--- pkg/blotter/R/updatePortf.R 2013-08-13 18:01:30 UTC (rev 1492)
+++ pkg/blotter/R/updatePortf.R 2013-08-14 03:08:03 UTC (rev 1493)
@@ -74,26 +74,22 @@
if(is.null(summary)) {summary=result}
else {summary=cbind(summary,result)}
}
-
- # get rid of duplicated indices in the summary data,
- # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it
- d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE)
- if(any(d)){
- f <- function(x) {
- cLast <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value')
- cSums <- c('Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
- setNames(suppressWarnings(
- merge(last(x[,cLast]),
- xts(t(colSums(x[,cSums],na.rm=TRUE)),order.by=last(index(x))))
- )
- ,nm=colnames(x))
- }
-
- slist <- do.call(rbind, lapply(split(summary[d,], .index(summary[d,])), f))
- summary <- merge(summary[!d,], slist) #put it all back together
- }
-
-
+
+ # get rid of duplicated indices in the summary data,
+ # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it
+ d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE)
+ if(any(d)){
+ f <- function(x) {
+ cLast <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value')
+ cSums <- c('Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
+ setNames( merge(last(x[,cLast]), xts(t(colSums(x[,cSums],na.rm=TRUE)),last(index(x)))), colnames(x) )
+ }
+ summary.dups <- summary[d,]
+ ds <- duplicated(.index(summary.dups))
+ slist <- period.apply(summary.dups, c(0, which(ds)), f)
+ summary <- rbind(summary[!d,], slist) # put it all back together
+ }
+
if(!is.timeBased(Dates)) Dates = xts:::time.xts(Portfolio$symbols[[1]][["posPL"]][Dates])
startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001
# trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary
More information about the Blotter-commits
mailing list