[Blotter-commits] r1256 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Nov 21 02:49:37 CET 2012
Author: opentrades
Date: 2012-11-21 02:49:36 +0100 (Wed, 21 Nov 2012)
New Revision: 1256
Modified:
pkg/quantstrat/R/ruleOrderProc.R
pkg/quantstrat/R/rules.R
Log:
- fixed a bug in fill timestamp of limit orders
- changed fill condition from <High to <=High, and >Lo to >=Lo to have same policy everywhere
Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R 2012-11-20 18:25:52 UTC (rev 1255)
+++ pkg/quantstrat/R/ruleOrderProc.R 2012-11-21 01:49:36 UTC (rev 1256)
@@ -145,15 +145,23 @@
# check to see if price moved through the limit
if((orderQty > 0 && orderType != 'stoplimit') || (orderQty < 0 && (orderType=='stoplimit'))) {
# buy limit, or sell stoplimit
- if( (has.Lo(mktdata) && orderPrice > as.numeric(Lo(mktdataTimestamp))) ||
+ if( (has.Lo(mktdata) && orderPrice >= as.numeric(Lo(mktdataTimestamp))) ||
(!has.Lo(mktdata) && orderPrice >= as.numeric(getPrice(mktdataTimestamp, prefer=prefer))))
{
txnprice = orderPrice
txntime = timestamp
+# if(ordersubset[ii,'Rule']=='EnterLONG')
+# {
+# print('Hebbes!')
+# print(ordersubset[ii,])
+# print(txnprice)
+# print(txntime)
+# print('Hebbes!!')
+# }
} else next() # price did not move through my order, should go to next order
} else if((orderQty < 0 && orderType != 'stoplimit') || (orderQty > 0 && (orderType=='stoplimit'))) {
# sell limit or buy stoplimit
- if ( (has.Hi(mktdata) && orderPrice < as.numeric(Hi(mktdataTimestamp))) ||
+ if ( (has.Hi(mktdata) && orderPrice <= as.numeric(Hi(mktdataTimestamp))) ||
(!has.Hi(mktdata) && orderPrice <= as.numeric(getPrice(mktdataTimestamp,prefer=prefer))) )
{
txnprice = orderPrice
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2012-11-20 18:25:52 UTC (rev 1255)
+++ pkg/quantstrat/R/rules.R 2012-11-21 01:49:36 UTC (rev 1256)
@@ -436,7 +436,14 @@
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?
+ #
+ # current index = which(cross[timespan])[1]
+ # since the soonest we can get filled is next timestamp we are looking for which(cross[timespan])[2].
+ # need to subtract 1 index==1 means current position
+ #
+ # newidx <- curIndex + which(cross[timespan])[1] #- 1 #curIndex/timestamp was 1 in the subset, we need a -1 offset?
+ newidx <- curIndex + which(cross[timespan])[2] - 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...
More information about the Blotter-commits
mailing list