[Blotter-commits] r616 - in pkg/quantstrat: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jun 8 19:30:22 CEST 2011
Author: gsee
Date: 2011-06-08 19:30:21 +0200 (Wed, 08 Jun 2011)
New Revision: 616
Modified:
pkg/quantstrat/DESCRIPTION
pkg/quantstrat/R/rules.R
Log:
-orders were being compared to wrong columns to check for fills.
-curIndex was being decremented where it should not have been.
-PLEASE TEST. This is fundamentally a big change.
Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION 2011-06-08 17:27:27 UTC (rev 615)
+++ pkg/quantstrat/DESCRIPTION 2011-06-08 17:30:21 UTC (rev 616)
@@ -3,7 +3,7 @@
Title: Quantitative Strategy Model Framework
Version: 0.4.0
Date: $Date$
-Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey A. Ryan, Joshua Ulrich
+Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey A. Ryan, Joshua Ulrich, Garrett See
Depends: xts(>= 0.7-6.15),TTR(>= 0.2),blotter(>= 0.7.2), FinancialInstrument, quantmod (>= 0.3-14)
Suggests: PerformanceAnalytics,PortfolioAnalytics
Maintainer: Jeffrey A. Ryan <jeff.a.ryan at gmail.com>
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2011-06-08 17:27:27 UTC (rev 615)
+++ pkg/quantstrat/R/rules.R 2011-06-08 17:30:21 UTC (rev 616)
@@ -296,7 +296,7 @@
#we could maybe do something more sophisticated, but this should work
if(isTRUE(path.dep)){
- dindex<-c(1,length(Dates)-1) # set the dimension reduction/loop jumping index vector
+ dindex<-c(1,length(Dates))# -1) # set the dimension reduction/loop jumping index vector
assign.dindex(dindex)
#pre-process for dimension reduction here
for ( type in names(strategy$rules)){
@@ -347,7 +347,7 @@
isOHLCmktdata <- is.OHLC(mktdata)
isBBOmktdata <- is.BBO(mktdata)
#check for open orders at curIndex
- timespan<-paste(timestamp,"::",sep='')
+ timespan<-paste(timestamp,"::",sep='') #no check to see if timestamp came through dots? Does it come from the search path? -gsee
if(nrow(ordersubset[oo.idx,][timespan])==0){
# no open orders between now and the next index
nidx=FALSE
@@ -374,7 +374,7 @@
tmpprice<-as.numeric(ordersubset[oo.idx[lorder],'Order.Price'])
if(tmpqty>0){
#buying
- relationship="gte"
+ relationship="lte" #look for places where Mkt Ask <= our Bid
if(isBBOmktdata) {
col<-first(colnames(mktdata)[has.Ask(mktdata,which=TRUE)])
} else if (isOHLCmktdata) {
@@ -386,7 +386,7 @@
}
} else {
#selling
- relationship="lte"
+ relationship="gte" #look for places where Mkt Bid >= our Ask
if(isBBOmktdata) {
col<-first(colnames(mktdata)[has.Bid(mktdata,which=TRUE)])
} else if (isOHLCmktdata) {
@@ -400,7 +400,13 @@
cross<-sigThreshold(label='tmplimit',column=col,threshold=tmpprice,relationship=relationship)
if(any(cross[timespan])){
# find first index that would cross after this index
- newidx <- curIndex + which(cross[timespan])[1] - 1 #curIndex/timestamp was 1 in the subset, we need a -1 offset?
+ newidx <- curIndex + which(cross[timespan])[1] #- 1 #curIndex/timestamp was 1 in the subset, we need a -1 offset?
+ #if there are is no cross curIndex will be incremented on line 496
+ # with curIndex<-min(dindex[dindex>curIndex]).
+ #we cannot get filled at this timestamp. The soonest we could get filled is next timestamp...
+ #see also that market order increments curIndex before returning it. Going by the docs,
+ #I think this is by design. i.e. no instant fills. -gsee
+
# insert that into dindex
assign.dindex(c(get.dindex(),newidx))
} else{
@@ -482,12 +488,12 @@
} # end if for trailing orders
} # end else clause for any open orders in this timespan
} # end any open orders closure
- if(nidx) {
+ if(nidx) { #This will never evaluate to TRUE; if it has a purpose, it's a bug. -gsee
curIndex <- curIndex+1
dindex<-get.dindex()
} else {
dindex<-get.dindex()
- curIndex<-min(dindex[dindex>curIndex])
+ curIndex<-min(dindex[dindex>curIndex])
}
if (is.na(curIndex) || curIndex >= length(index(mktdata))) curIndex=FALSE
@@ -563,7 +569,7 @@
}
) # end switch
} #end type loop
- if(isTRUE(path.dep)) curIndex<-nextIndex(curIndex, ...)
+ if(isTRUE(path.dep)) curIndex<-nextIndex(curIndex, ...) #timestamp comes from environment, not dots? -gsee
else curIndex=FALSE
} # end index while loop
@@ -578,7 +584,8 @@
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
# Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson,
+# Jeffrey Ryan, Joshua Ulrich, and Garrett See
#
# This library is distributed under the terms of the GNU Public License (GPL)
# for full details see the file COPYING
More information about the Blotter-commits
mailing list