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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 7 01:48:19 CEST 2016


Author: bodanker
Date: 2016-04-07 01:48:18 +0200 (Thu, 07 Apr 2016)
New Revision: 1746

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/man/getOrders.Rd
Log:
Make explicit that getOrders works with one symbol

getOrders will throw an error if 'symbol' is a vector and not in the
same order as the symbols in the portfolio. If that error is avoided
because the symbols are in the same order, then there will be an error
when we try to subset orderbook[[portfolio]] by a vector, since [[ can
only select a single element.


Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2016-04-03 14:50:14 UTC (rev 1745)
+++ pkg/quantstrat/R/orders.R	2016-04-06 23:48:18 UTC (rev 1746)
@@ -96,8 +96,6 @@
 #' 
 #' It has some use as a reporting or post-hoc analytics tool, but it may not always be exported.
 #' 
-#' should this be symbols instead of symbol?
-#' 
 #' @param portfolio text name of the portfolio to associate the order book with
 #' @param symbol identifier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC) should match these
 #' @param status one of "open", "closed", "canceled", "revoked", or "replaced", default "open"
@@ -116,7 +114,14 @@
     #if(is.null(timespan)) stop("timespan must be an xts style timestring")
     # get order book
     orderbook <- getOrderBook(portfolio)
-    if(!any(names(orderbook[[portfolio]]) == symbol)) stop(paste("symbol",symbol,"does not exist in portfolio",portfolio,"having symbols",names(orderbook[[portfolio]])))
+    if(length(symbol) > 1L) {
+        symbol <- symbol[1L]  # only one symbol at a time is currently supported
+        warning("Only single instruments are currently supported. Using first symbol only.")
+    }
+    if(!any(names(orderbook[[portfolio]]) == symbol)) {
+        stop("symbol ", symbol, " does not exist in portfolio ", portfolio,
+             ", which has symbols: ", paste(names(orderbook[[portfolio]]), collapse=", "))
+    }
 
     ordersubset <- orderbook[[portfolio]][[symbol]]
     if(is.null(ordersubset))

Modified: pkg/quantstrat/man/getOrders.Rd
===================================================================
--- pkg/quantstrat/man/getOrders.Rd	2016-04-03 14:50:14 UTC (rev 1745)
+++ pkg/quantstrat/man/getOrders.Rd	2016-04-06 23:48:18 UTC (rev 1746)
@@ -32,8 +32,6 @@
 }
 \details{
 It has some use as a reporting or post-hoc analytics tool, but it may not always be exported.
-
-should this be symbols instead of symbol?
 }
 \seealso{
 getOrderBook



More information about the Blotter-commits mailing list