[Blotter-commits] r1421 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 3 23:08:23 CEST 2013
Author: opentrades
Date: 2013-04-03 23:08:22 +0200 (Wed, 03 Apr 2013)
New Revision: 1421
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/R/ruleSignal.R
Log:
- moved check for exit/all order with pos==0 from ruleSignal() into addOrder() to make sure that replace==TRUE is respected
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2013-04-01 16:02:29 UTC (rev 1420)
+++ pkg/quantstrat/R/orders.R 2013-04-03 21:08:22 UTC (rev 1421)
@@ -361,23 +361,27 @@
orders<-NULL
for (i in 1:length(price)) {
if(is.null(prefer[i])) prefer[i] = ''
- 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))
-
- if(is.null(orders)) orders<-neworder
- else orders <- rbind(orders,neworder)
+
+ 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))
+
+ if(is.null(orders)) orders<-neworder
+ else orders <- rbind(orders,neworder)
+ }
}
- if(ncol(orders)!=11) {
+ if(!is.null(orders) && ncol(orders)!=11) {
print("bad order(s):")
print(orders)
return()
@@ -399,11 +403,14 @@
statustimestamp=timestamp)
}
# get order book
- orderbook <- getOrderBook(portfolio)
- orderbook[[portfolio]][[symbol]]<-rbind(orderbook[[portfolio]][[symbol]],orders)
- # assign order book back into place (do we need a non-exported "put" function?)
- assign(paste("order_book",portfolio,sep='.'),orderbook,envir=.strategy)
- rm(orderbook)
+ if(!is.null(orders))
+ {
+ orderbook <- getOrderBook(portfolio)
+ orderbook[[portfolio]][[symbol]]<-rbind(orderbook[[portfolio]][[symbol]],orders)
+ # assign order book back into place (do we need a non-exported "put" function?)
+ assign(paste("order_book",portfolio,sep='.'),orderbook,envir=.strategy)
+ rm(orderbook)
+ }
return()
} else {
return(orders)
Modified: pkg/quantstrat/R/ruleSignal.R
===================================================================
--- pkg/quantstrat/R/ruleSignal.R 2013-04-01 16:02:29 UTC (rev 1420)
+++ pkg/quantstrat/R/ruleSignal.R 2013-04-03 21:08:22 UTC (rev 1421)
@@ -205,8 +205,8 @@
if(!is.null(orderqty) && orderqty!=0 && !is.null(orderprice)) #orderprice could have length > 1
{
- if(orderqty != 'all' || getPosQty(portfolio, symbol, timestamp) != 0)
- {
+# if(orderqty != 'all' || getPosQty(portfolio, symbol, timestamp) != 0)
+# {
addOrder(portfolio=portfolio,
symbol=symbol,
timestamp=timestamp,
@@ -224,7 +224,7 @@
prefer=prefer,
TxnFees=TxnFees,
label=label)
- }
+# }
}
}
if(sethold) hold <<- TRUE
More information about the Blotter-commits
mailing list