[Blotter-commits] r419 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Oct 12 17:56:29 CEST 2010
Author: braverock
Date: 2010-10-12 17:56:29 +0200 (Tue, 12 Oct 2010)
New Revision: 419
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/R/rules.R
Log:
- fix bug in stoplimit processing on low-frequency data in ruleOrderPorc
- fix s/mkdata/mktdata/ typo in applyRules
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2010-10-12 13:39:58 UTC (rev 418)
+++ pkg/quantstrat/R/orders.R 2010-10-12 15:56:29 UTC (rev 419)
@@ -372,20 +372,21 @@
# next process daily
for (ii in procorders ){
txnprice=NULL
- txntime=as.character(index(ordersubset[ii,]))
- txnfees=ordersubset[ii, ]$Txn.Fees
+ #txntime=as.character(index(ordersubset[ii,])) #wrong if order time and txn time are different
+ txntime=as.character(timestamp)
+ txnfees=ordersubset[ii, ]$Txn.Fees
if(is.null(txnfees)) txnfees=0
switch(ordersubset[ii,]$Order.Type,
market = {
- txnprice=as.numeric(getPrice(mktdata[txntime], prefer='close'))
+ txnprice=as.numeric(getPrice(last(mktdata[timestamp]), prefer='close'))
#if(!is.null(ncol(txnprice)) & ncol(txnprice)>1) txnprice = as.numeric(getPrice(mktdata[timestamp], symbol=symbol, prefer='close'))
},
limit = ,
stoplimit = {
# check to see if price moved through the limit
tmpprices<-last(mktdata[timestamp])
- if ( isTRUE(ordersubset[ii, ]$Order.Price > getPrice(tmpprices, prefer = "Lo")) &
- isTRUE(ordersubset[ii, ]$Order.Price < getPrice(tmpprices, prefer = "Hi")) ) {
+ if ( as.numeric(ordersubset[ii, ]$Order.Price) > getPrice(tmpprices, prefer = "Lo") &
+ as.numeric(ordersubset[ii, ]$Order.Price) < getPrice(tmpprices, prefer = "Hi")) {
txnprice=as.numeric(ordersubset[ii,]$Order.Price)
txntime=as.character(timestamp)
} else {
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2010-10-12 13:39:58 UTC (rev 418)
+++ pkg/quantstrat/R/rules.R 2010-10-12 15:56:29 UTC (rev 419)
@@ -242,7 +242,7 @@
} #end type loop
} # end dates loop
- mkdata<<-mktdata
+ mktdata<<-mktdata
if(is.null(ret)) {
return(mktdata)
}
More information about the Blotter-commits
mailing list