[Blotter-commits] r1427 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Apr 7 00:10:43 CEST 2013
Author: bodanker
Date: 2013-04-07 00:10:42 +0200 (Sun, 07 Apr 2013)
New Revision: 1427
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/R/strategy.R
Log:
- initiate order book as NULL instead of xts template object (avoids the
potential for the order book index to be different than the data index)
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2013-04-06 14:23:16 UTC (rev 1426)
+++ pkg/quantstrat/R/orders.R 2013-04-06 22:10:42 UTC (rev 1427)
@@ -76,9 +76,7 @@
symbols<-names(pfolio$symbols)
}
if(!is.null(symbols)){
- for (symbol in symbols){
- orders[[portfolio]][[symbol]] <- ordertemplate
- }
+ orders[[portfolio]][symbols] <- list(NULL)
} else {
stop("You must specify a symbols list or a valid portfolio to retrieve the list from.")
}
@@ -114,6 +112,8 @@
orderbook <- getOrderBook(portfolio)
if(!any(names(orderbook[[portfolio]]) == symbol)) stop(paste("symbol",symbol,"does not exist in portfolio",portfolio,"having symbols",names(orderbook[[portfolio]])))
ordersubset<-orderbook[[portfolio]][[symbol]]
+ if(is.null(ordersubset))
+ return(NULL)
#data quality checks
if(!is.null(status) & !length(grep(status,c("open", "closed", "canceled", "revoked","replaced")))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", "revoked", or "replaced"'))
@@ -366,17 +366,12 @@
if(qty[i] != 'all' || getPosQty(portfolio, symbol, timestamp) != 0)
{
- neworder<-xts(as.matrix(t(c(as.character(qty[i]),
- price[i],
- ordertype[i],
- side,
- threshold[i],
- status,
- statustimestamp,
- prefer[i],
- orderset[i],
- TxnFees, label))),
- order.by=(ordertime))
+ neworder <- xts(t(c(as.character(qty[i]), price[i], ordertype[i],
+ side, threshold[i], status, statustimestamp, prefer[i],
+ orderset[i], TxnFees, label)), order.by=ordertime,
+ dimnames=list(NULL, c("Order.Qty", "Order.Price", "Order.Type",
+ "Order.Side", "Order.Threshold", "Order.Status", "Order.StatusTime",
+ "Prefer", "Order.Set", "Txn.Fees", "Rule")))
if(is.null(orders)) orders<-neworder
else orders <- rbind(orders,neworder)
Modified: pkg/quantstrat/R/strategy.R
===================================================================
--- pkg/quantstrat/R/strategy.R 2013-04-06 14:23:16 UTC (rev 1426)
+++ pkg/quantstrat/R/strategy.R 2013-04-06 22:10:42 UTC (rev 1427)
@@ -152,7 +152,7 @@
## Check for open orders
rem.orders <- suppressWarnings(getOrders(portfolio=portfolio, symbol=symbol, status="open")) #, timespan=timespan, ordertype=ordertype,which.i=TRUE)
- if(nrow(rem.orders)>0){pd <- TRUE}
+ if(NROW(rem.orders)>0){pd <- TRUE}
if(pd==TRUE){sret$rules$pathdep<-applyRules(portfolio=portfolio, symbol=symbol, strategy=strategy, mktdata=mktdata, Dates=NULL, indicators=sret$indicators, signals=sret$signals, parameters=parameters, ..., path.dep=TRUE)}
ret[[portfolio]][[symbol]]<-sret
More information about the Blotter-commits
mailing list