[Blotter-commits] r207 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 27 21:18:15 CET 2010
Author: braverock
Date: 2010-01-27 21:18:14 +0100 (Wed, 27 Jan 2010)
New Revision: 207
Modified:
pkg/blotter/R/getBySymbol.R
pkg/blotter/R/getPortfolio.R
Log:
- add more error handling
Modified: pkg/blotter/R/getBySymbol.R
===================================================================
--- pkg/blotter/R/getBySymbol.R 2010-01-27 14:57:10 UTC (rev 206)
+++ pkg/blotter/R/getBySymbol.R 2010-01-27 20:18:14 UTC (rev 207)
@@ -17,17 +17,18 @@
# FUNCTION
if(is.null(Date)) # if no date is specified, get all available dates
- Date = time(Portfolio[[1]]$posPL)
- else
- Date = time(Portfolio[[1]]$posPL[Date])
+ Date = time(Portfolio[[1]]$txn)
+# else
+# Date = time(Portfolio[[1]]$txn[Date])
table = xts(NULL, order.by=Date)
## Need a reference time index
if(is.null(Symbols))
symbols=names(Portfolio)
else
symbols = Symbols
- for (i in 1:length(symbols)) {
- table = merge(table, Portfolio[[i]]$posPL[Date,Attribute,drop=FALSE])
+
+ for (symbol in symbols) {
+ table = merge(table, Portfolio[[symbol]]$posPL[Date,Attribute,drop=FALSE])
#table = cbind(table, Portfolio[[i]]$posPL[Date,Attribute,drop=FALSE])
}
colnames(table) = symbols
Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R 2010-01-27 14:57:10 UTC (rev 206)
+++ pkg/blotter/R/getPortfolio.R 2010-01-27 20:18:14 UTC (rev 207)
@@ -1,12 +1,14 @@
getPortfolio <- function(Portfolio, Dates=NULL) #should symbol subsets be supported too? probably not.
{ # @author Brian Peterson
pname<-Portfolio
- Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
+ if(!grepl("portfolio",pname)) Portfolio<-try(get(paste("portfolio",pname,sep='.'),envir=.blotter))
+ else Portfolio<-try(get(pname,envir=.blotter))
if(inherits(Portfolio,"try-error"))
stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio"))
+ if(!inherits(Portfolio,"portfolio")) stop("Portfolio",pname,"passed is not the name of a portfolio object.")
if(!is.null(Dates)){
- message("date subsettingnot yet supported")
+ message("date subsetting not yet supported")
#TODO add date subsetting in getPortfolio
}
More information about the Blotter-commits
mailing list