[Blotter-commits] r442 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 5 05:29:25 CET 2010
Author: bodanker
Date: 2010-11-05 05:29:22 +0100 (Fri, 05 Nov 2010)
New Revision: 442
Modified:
pkg/quantstrat/R/orders.R
Log:
- Move more variable-creation to top of loops to avoid repeated calls
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2010-11-04 19:40:35 UTC (rev 441)
+++ pkg/quantstrat/R/orders.R 2010-11-05 04:29:22 UTC (rev 442)
@@ -405,19 +405,21 @@
#switch on frequency
freq = periodicity(mktdata)
neworders<-NULL
+ mktdataTimestamp <- mktdata[timestamp]
+ #str(mktdataTimestamp)
+ # Should we only keep the last observation per time stamp?
+ if( NROW(mktdataTimestamp) > 1 ) mktdataTimestamp <- last(mktdataTimestamp)
+ isOHLCmktdata <- is.OHLC(mktdata)
+ isBBOmktdata <- is.BBO(mktdata)
for (ii in procorders ){
txnprice=NULL
txnfees=ordersubset[ii,"Txn.Fees"]
orderPrice <- as.numeric(ordersubset[ii,"Order.Price"])
orderQty <- as.numeric(ordersubset[ii,"Order.Qty"])
orderThreshold <- as.numeric(ordersubset[ii,"Order.Threshold"])
- mktdataTimestamp <- mktdata[timestamp]
- # Should we only keep the last observation per time stamp?
- if( NROW(mktdataTimestamp) > 1 ) mktdataTimestamp <- last(mktdataTimestamp)
- isOHLCmktdata <- is.OHLC(mktdata)
- isBBOmktdata <- is.BBO(mktdata)
+ orderType <- ordersubset[ii,"Order.Type"]
- switch(ordersubset[ii,"Order.Type"],
+ switch(orderType,
market = {
txnprice = as.numeric(getPrice(mktdataTimestamp))
#TODO extend this to figure out which side to prefer
@@ -427,7 +429,7 @@
stoplimit =,
iceberg = {
if (isOHLCmktdata){
- if( ordersubset[ii,"Order.Type"] == 'iceberg'){ # switch takes care of this
+ if( orderType == 'iceberg'){
stop("iceberg orders not supported for OHLC data")
}
# check to see if price moved through the limit
@@ -455,19 +457,19 @@
txntime = as.character(timestamp)
} else next()
}
- if( ordersubset[ii,"Order.Type"] == 'iceberg'){
+ if( orderType == 'iceberg'){
#we've transacted, so the old order was closed, put in a new one
neworder<-addOrder(portfolio=portfolio,
symbol=symbol,
timestamp=timestamp,
qty=orderQty,
price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)),
- ordertype=ordersubset[ii,"Order.Type"],
+ ordertype=orderType,
side=ordersubset[ii,"Order.Side"],
threshold=orderThreshold,
status="open",
replace=FALSE, return=TRUE,
- ,...=..., TxnFees=ordersubset[ii,"Txn.Fees"])
+ ,...=..., TxnFees=txnfees)
if (is.null(neworders)) neworders=neworder else neworders = rbind(neworders,neworder)
ordersubset[ii,"Order.Status"]<-'replaced'
ordersubset[ii,"Order.StatusTime"]<-as.character(timestamp)
@@ -542,12 +544,12 @@
timestamp=timestamp,
qty=orderQty,
price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)),
- ordertype=ordersubset[ii,"Order.Type"],
+ ordertype=orderType,
side=ordersubset[ii,"Order.Side"],
threshold=orderThreshold,
status="open",
replace=FALSE, return=TRUE,
- ,...=..., TxnFees=ordersubset[ii,"Txn.Fees"])
+ ,...=..., TxnFees=txnfees)
if (is.null(neworders)) neworders=neworder else neworders = rbind(neworders,neworder)
ordersubset[ii,"Order.Status"]<-'replaced'
ordersubset[ii,"Order.StatusTime"]<-as.character(timestamp)
More information about the Blotter-commits
mailing list