[Blotter-commits] r1027 - in pkg/blotter: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri May 18 19:49:04 CEST 2012
Author: braverock
Date: 2012-05-18 19:49:04 +0200 (Fri, 18 May 2012)
New Revision: 1027
Added:
pkg/blotter/man/is.account.Rd
Modified:
pkg/blotter/DESCRIPTION
pkg/blotter/R/getAccount.R
pkg/blotter/R/updatePosPL.R
Log:
- add check for valid dates from prices before trying to update in .updatePosPL, thanks to algotr8der for the report
- add is.account utility function
- bump version
Modified: pkg/blotter/DESCRIPTION
===================================================================
--- pkg/blotter/DESCRIPTION 2012-05-18 17:40:23 UTC (rev 1026)
+++ pkg/blotter/DESCRIPTION 2012-05-18 17:49:04 UTC (rev 1027)
@@ -2,7 +2,7 @@
Type: Package
Title: Tools for transaction-oriented trading systems
development.
-Version: 0.8.8
+Version: 0.8.9
Date: $Date$
Author: Peter Carl, Brian G. Peterson
Maintainer: Brian G. Peterson <brian at braverock.com>
Modified: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R 2012-05-18 17:40:23 UTC (rev 1026)
+++ pkg/blotter/R/getAccount.R 2012-05-18 17:49:04 UTC (rev 1027)
@@ -22,6 +22,31 @@
return(Account)
}
+#' generic is.function for account, will take either a string or an object
+#'
+#' If \code{x} is a string, \code{\link{getAccount}} will be called with
+#' string \code{x} and tested. Otherwise, the object passed will be tested.
+#'
+#' @param x an object or string to be tested as a account
+#' @param \dots any other passthru parameters
+#' @seealso \code{\link{getAccount}}
+#' @export
+is.account <- function(x,...)
+{ # @author Brian Peterson
+ if(inherits(x,'account')) return(TRUE)
+ else if(is.character(x)){
+ if(!grepl("account\\.",x)) res <- suppressWarnings(try(get(paste("account",x,sep='.'),envir=.blotter),silent=TRUE))
+ else res <- suppressWarnings(try(get(x,envir=.blotter),silent=TRUE))
+ #res<-suppressWarnings(try(getaccount(x))) #causes spurious error if you're checking whether account exists
+ if(!inherits(res,"account")) {
+ message("account ",x," needs to be created first.")
+ return(FALSE)
+ } else {
+ return(TRUE)
+ }
+ } else return(FALSE)
+}
+
###############################################################################
# Blotter: Tools for transaction-oriented trading systems development
# for R (see http://r-project.org/)
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2012-05-18 17:40:23 UTC (rev 1026)
+++ pkg/blotter/R/updatePosPL.R 2012-05-18 17:49:04 UTC (rev 1027)
@@ -31,7 +31,10 @@
} else {
prices=Prices
}
-
+ if(.parseISO8601(Dates)$first.time <first(index(Prices))|| is.na(.parseISO8601(Dates)$first.time)){
+ Dates<-index(prices[paste('/',.parseISO8601(Dates)$last.time,sep='')])
+ }
+
if(is.null(Dates)) {# if no date is specified, get all available dates
Dates = time(prices)
} else if(!is.timeBased(Dates)) Dates = time(prices[Dates])
Added: pkg/blotter/man/is.account.Rd
===================================================================
--- pkg/blotter/man/is.account.Rd (rev 0)
+++ pkg/blotter/man/is.account.Rd 2012-05-18 17:49:04 UTC (rev 1027)
@@ -0,0 +1,20 @@
+\name{is.account}
+\alias{is.account}
+\title{generic is.function for account, will take either a string or an object}
+\usage{
+ is.account(x, ...)
+}
+\arguments{
+ \item{x}{an object or string to be tested as a account}
+
+ \item{\dots}{any other passthru parameters}
+}
+\description{
+ If \code{x} is a string, \code{\link{getAccount}} will be
+ called with string \code{x} and tested. Otherwise, the
+ object passed will be tested.
+}
+\seealso{
+ \code{\link{getAccount}}
+}
+
More information about the Blotter-commits
mailing list