[Blotter-commits] r1365 - in pkg: blotter/R blotter/man quantstrat/R quantstrat/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 17 00:24:38 CET 2013


Author: opentrades
Date: 2013-01-17 00:24:38 +0100 (Thu, 17 Jan 2013)
New Revision: 1365

Modified:
   pkg/blotter/R/getAccount.R
   pkg/blotter/R/getPortfolio.R
   pkg/blotter/man/addTxn.Rd
   pkg/blotter/man/getAccount.Rd
   pkg/blotter/man/getPortfolio.Rd
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/strategy.R
   pkg/quantstrat/man/getOrderBook.Rd
   pkg/quantstrat/man/getStrategy.Rd
Log:
- added envir parameter to get functions to allow retrieval of objects from environment different from default environment



Modified: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/blotter/R/getAccount.R	2013-01-16 23:24:38 UTC (rev 1365)
@@ -3,13 +3,14 @@
 #' Retrieves an account object from the \code{.blotter} environment.  Useful for local examination or charting, or storing interim results for later reference.
 #'
 #' @param Account string identifier for the account
+#' @param envir the environment to retrieve the account from, defaults to .blotter
 #' @return Account object
 #' @export
-getAccount <- function(Account) #should symbol subsets be supported too?  probably not.
+getAccount <- function(Account, envir=.blotter) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     aname<-Account
-    if(!grepl("account\\.",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=.blotter), silent=TRUE)
-    else Account<-try(get(aname,envir=.blotter), silent=TRUE)
+    if(!grepl("account\\.",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=envir), silent=TRUE)
+    else Account<-try(get(aname,envir=envir), silent=TRUE)
     if(inherits(Account,"try-error"))
         stop(paste("Account ",aname," not found, use initAcct() to create a new account"))
     if(!inherits(Account,"account")) stop("Account ",aname," passed is not the name of an account object.")

Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/blotter/R/getPortfolio.R	2013-01-16 23:24:38 UTC (rev 1365)
@@ -1,12 +1,13 @@
 #' get a portfolio object
 #' @param Portfolio string identifying portfolio
 #' @param Dates dates subset, not yet supported
+#' @param envir the environment to retrieve the portfolio from, defaults to .blotter
 #' @export
-getPortfolio <- function(Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
+getPortfolio <- function(Portfolio, Dates=NULL, envir=.blotter) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     pname<-Portfolio
-    if(!grepl("portfolio\\.",pname)) Portfolio<-suppressWarnings(try(get(paste("portfolio",pname,sep='.'),envir=.blotter),silent=TRUE))
-    else Portfolio<-suppressWarnings(try(get(pname,envir=.blotter),silent=TRUE))
+    if(!grepl("portfolio\\.",pname)) Portfolio<-suppressWarnings(try(get(paste("portfolio",pname,sep='.'),envir=envir),silent=TRUE))
+    else Portfolio<-suppressWarnings(try(get(pname,envir=envir),silent=TRUE))
     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.")

Modified: pkg/blotter/man/addTxn.Rd
===================================================================
--- pkg/blotter/man/addTxn.Rd	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/blotter/man/addTxn.Rd	2013-01-16 23:24:38 UTC (rev 1365)
@@ -3,7 +3,7 @@
 \title{Add transactions to a portfolio.}
 \usage{
   addTxn(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ...,
-    TxnFees = 0, ConMult = NULL, verbose = TRUE,
+    TxnFees = 0, ConMult = NULL, verbose = FALSE,
     eps = 0.000001)
 }
 \arguments{

Modified: pkg/blotter/man/getAccount.Rd
===================================================================
--- pkg/blotter/man/getAccount.Rd	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/blotter/man/getAccount.Rd	2013-01-16 23:24:38 UTC (rev 1365)
@@ -2,10 +2,13 @@
 \alias{getAccount}
 \title{Get an account object from the .blotter environment}
 \usage{
-  getAccount(Account)
+  getAccount(Account, envir = .blotter)
 }
 \arguments{
   \item{Account}{string identifier for the account}
+
+  \item{envir}{the environment to retrieve the account
+  from, defaults to .blotter}
 }
 \value{
   Account object

Modified: pkg/blotter/man/getPortfolio.Rd
===================================================================
--- pkg/blotter/man/getPortfolio.Rd	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/blotter/man/getPortfolio.Rd	2013-01-16 23:24:38 UTC (rev 1365)
@@ -2,12 +2,15 @@
 \alias{getPortfolio}
 \title{get a portfolio object}
 \usage{
-  getPortfolio(Portfolio, Dates = NULL)
+  getPortfolio(Portfolio, Dates = NULL, envir = .blotter)
 }
 \arguments{
   \item{Portfolio}{string identifying portfolio}
 
   \item{Dates}{dates subset, not yet supported}
+
+  \item{envir}{the environment to retrieve the portfolio
+  from, defaults to .blotter}
 }
 \description{
   get a portfolio object

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/quantstrat/R/orders.R	2013-01-16 23:24:38 UTC (rev 1365)
@@ -3,14 +3,15 @@
 #' I don't think this should be exported, but it is for now while we're in test mode.
 #' 
 #' @param portfolio text name of the portfolio the order book is associated with
+#' @param envir the environment to retrieve the orderbook object from, defaults to .strategy
 #' @seealso addOrder
 #' @seealso getOrders
 #' @concept order book
 #' @export
-getOrderBook <- function(portfolio) #should symbol subsets be supported too?  probably not.
+getOrderBook <- function(portfolio, envir=.strategy) #should symbol subsets be supported too?  probably not.
 { 
-    if(!grepl("order_book",portfolio)) orders<-try(get(paste("order_book",portfolio,sep='.'),envir=.strategy),silent=TRUE)
-    else orders<-try(get(portfolio,envir=.strategy),silent=TRUE)
+    if(!grepl("order_book",portfolio)) orders<-try(get(paste("order_book",portfolio,sep='.'),envir=envir),silent=TRUE)
+    else orders<-try(get(portfolio,envir=envir),silent=TRUE)
     if(inherits(orders,"try-error"))
         stop(paste("Orders for ",portfolio," not found, use initOrders() to create a new order book for this portfolio"))
     if(!inherits(orders,"order_book")) stop("Order Book for portfolio",portfolio,"does not appear to name an order book object.")

Modified: pkg/quantstrat/R/strategy.R
===================================================================
--- pkg/quantstrat/R/strategy.R	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/quantstrat/R/strategy.R	2013-01-16 23:24:38 UTC (rev 1365)
@@ -175,9 +175,10 @@
 
 #' retrieve strategy from the container environment
 #' @param x string name of object to be retrieved
+#' @param envir the environment to retrieve the strategy object from, defaults to .strategy
 #' @export
-getStrategy <- function(x){
-    tmp_strat<-get(as.character(x),pos=.strategy, inherits=TRUE)
+getStrategy <- function(x, envir=.strategy){
+    tmp_strat<-get(as.character(x),pos=envir, inherits=TRUE)
     if( inherits(tmp_strat,"try-error") | !is.strategy(tmp_strat) ) {
         warning(paste("Strategy",x," not found, please create it first."))
         return(FALSE)

Modified: pkg/quantstrat/man/getOrderBook.Rd
===================================================================
--- pkg/quantstrat/man/getOrderBook.Rd	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/quantstrat/man/getOrderBook.Rd	2013-01-16 23:24:38 UTC (rev 1365)
@@ -2,11 +2,14 @@
 \alias{getOrderBook}
 \title{get the order book object}
 \usage{
-  getOrderBook(portfolio)
+  getOrderBook(portfolio, envir = .strategy)
 }
 \arguments{
   \item{portfolio}{text name of the portfolio the order
   book is associated with}
+
+  \item{envir}{the environment to retrieve the orderbook
+  object from, defaults to .strategy}
 }
 \description{
   I don't think this should be exported, but it is for now

Modified: pkg/quantstrat/man/getStrategy.Rd
===================================================================
--- pkg/quantstrat/man/getStrategy.Rd	2013-01-16 23:10:17 UTC (rev 1364)
+++ pkg/quantstrat/man/getStrategy.Rd	2013-01-16 23:24:38 UTC (rev 1365)
@@ -2,10 +2,13 @@
 \alias{getStrategy}
 \title{retrieve strategy from the container environment}
 \usage{
-  getStrategy(x)
+  getStrategy(x, envir = .strategy)
 }
 \arguments{
   \item{x}{string name of object to be retrieved}
+
+  \item{envir}{the environment to retrieve the strategy
+  object from, defaults to .strategy}
 }
 \description{
   retrieve strategy from the container environment



More information about the Blotter-commits mailing list