[Blotter-commits] r1575 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 6 16:54:23 CET 2013
Author: bodanker
Date: 2013-12-06 16:54:23 +0100 (Fri, 06 Dec 2013)
New Revision: 1575
Modified:
pkg/blotter/R/updateAcct.R
pkg/blotter/R/updateEndEq.R
pkg/blotter/R/updatePosPL.R
Log:
- Patch updateAcct and updateEndEq to do nothing if called before there are any
transactions in any portfolios.
- Replace calls to xts:::time.xts() with index()
Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R 2013-11-20 14:10:01 UTC (rev 1574)
+++ pkg/blotter/R/updateAcct.R 2013-12-06 15:54:23 UTC (rev 1575)
@@ -14,8 +14,12 @@
Portfolios = names(Account$portfolios)
- port<-.getPortfolio(Portfolios[1])
- if(is.null(Dates)) Dates <- unique(do.call(c,c(lapply(port$symbols, function(x) index(x[["posPL"]])), use.names=FALSE, recursive=FALSE)))
+ if(is.null(Dates))
+ Dates <- unique(do.call(c,c(lapply(Portfolios, function(x) index(.getPortfolio(x)$summary)), use.names=FALSE, recursive=FALSE)))[-1]
+ # if all the portfolio summary tables only have one observation
+ # then we haven't made any transactions, so there's nothing to update
+ if(!length(Dates))
+ return(name)
#trim to only time prior to Dates
if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){
@@ -150,7 +154,6 @@
Account$summary <- rbind(Account$summary, summary)
# This function does not calculate End.Eq
- #account is already an environment, it's been updated in place
assign(paste("account",name,sep='.'),Account, envir=.blotter)
return(name) #not sure this is a good idea
}
Modified: pkg/blotter/R/updateEndEq.R
===================================================================
--- pkg/blotter/R/updateEndEq.R 2013-11-20 14:10:01 UTC (rev 1574)
+++ pkg/blotter/R/updateEndEq.R 2013-12-06 15:54:23 UTC (rev 1575)
@@ -18,11 +18,15 @@
stop(paste("Account",aname," not found, use initAcct() to create a new account"))
if(is.null(Dates)) # if no date is specified, get all available dates
- Dates = xts:::time.xts(Account$summary)[-1]
+ Dates = index(Account$summary)[-1]
else
- Dates = xts:::time.xts(Account$summary[Dates])
+ Dates = index(Account$summary[Dates])
+ # if the account summary table only has one observation
+ # then we haven't made any transactions, so there's nothing to update
+ if(!length(Dates))
+ return(aname)
- PrevDate = xts:::time.xts(Account$summary[first(Account$summary[Dates,which.i=TRUE])-1,]) # get index of previous end date
+ PrevDate = index(Account$summary[first(Account$summary[Dates,which.i=TRUE])-1,]) # get index of previous end date
PrevEndEq = getEndEq(aname, PrevDate)
Additions = Account$summary[Dates]$Additions
Withdrawals = Account$summary[Dates]$Withdrawals
@@ -34,7 +38,6 @@
EndCapital = PrevEndEq + cumsum(Additions + Withdrawals + NetPerformance)
Account$summary$End.Eq[Dates] <- EndCapital
- #account is already an environment, it's been updated in place
assign(paste("account",aname,sep='.'),Account, envir=.blotter)
return(aname) #not sure this is a good idea
}
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2013-11-20 14:10:01 UTC (rev 1574)
+++ pkg/blotter/R/updatePosPL.R 2013-12-06 15:54:23 UTC (rev 1575)
@@ -37,12 +37,12 @@
# if no date is specified, get all available dates
if(is.null(Dates)) {
- Dates = xts:::time.xts(prices)
+ Dates = index(prices)
} else if(!is.timeBased(Dates)) {
Dates<- if(is.na(.parseISO8601(Dates)$first.time) ||
.parseISO8601(Dates)$first.time < as.POSIXct(first(index(prices)))){
index(prices[paste('/',.parseISO8601(Dates)$last.time,sep='')])
- } else xts:::time.xts(prices[Dates])
+ } else index(prices[Dates])
}
if(!missing(Interval) && !is.null(Interval)) {
ep_args <- .parse_interval(Interval)
More information about the Blotter-commits
mailing list