[Blotter-commits] r694 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 22 16:29:17 CEST 2011
Author: gsee
Date: 2011-07-22 16:29:16 +0200 (Fri, 22 Jul 2011)
New Revision: 694
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/R/traderules.R
Log:
only use first column that getPrice returns
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2011-07-21 23:22:53 UTC (rev 693)
+++ pkg/quantstrat/R/orders.R 2011-07-22 14:29:16 UTC (rev 694)
@@ -443,7 +443,7 @@
daily = {
txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc.
# txntime=as.character(timestamp) # use this if you wanted to transact on the close of the next bar
- txnprice=as.numeric(getPrice(last(mktdata[txntime]), ...=...))
+ txnprice=as.numeric(getPrice(last(mktdata[txntime]), ...=...)[,1])
}, #end daily
{
txntime = timestamp
@@ -453,12 +453,12 @@
#and, for sell orders you'll be filled at either orderPrice or the current mkt bid -- whichever is worse.
if(orderQty > 0){ # positive quantity 'buy'
#fill at max(orderPrice,newMktAsk price)
- txnprice = max(orderPrice, as.numeric(getPrice(mktdataTimestamp,prefer='ask')))
+ txnprice = max(orderPrice, as.numeric(getPrice(mktdataTimestamp,prefer='ask')[,1]))
} else { # negative quantity 'sell'
- txnprice = min(orderPrice, as.numeric(getPrice(mktdataTimestamp,prefer='bid'))) #presumes unique timestamp
+ txnprice = min(orderPrice, as.numeric(getPrice(mktdataTimestamp,prefer='bid')[,1])) #presumes unique timestamp
}
#e.g. if pricemethod was opside, it sent a buy order at mktAsk. fill at greater of that ask, and current ask
- } else txnprice = as.numeric(getPrice(mktdataTimestamp)) #filled at 'price'
+ } else txnprice = as.numeric(getPrice(mktdataTimestamp)[,1]) #filled at 'price'
}) # end switch on frequency
},
limit= ,
@@ -483,17 +483,17 @@
} else if(isBBOmktdata){
# check side/qty
if(orderQty > 0){ # positive quantity 'buy'
- if(orderPrice >= as.numeric(getPrice(mktdataTimestamp,prefer='ask'))){
+ if(orderPrice >= as.numeric(getPrice(mktdataTimestamp,prefer='ask')[,1])){
# price we're willing to pay is higher than the offer price, so execute at the prevailing price
#txnprice = orderPrice
- txnprice = as.numeric(getPrice(mktdataTimestamp,prefer='ask')) #presumes unique timestamps
+ txnprice = as.numeric(getPrice(mktdataTimestamp,prefer='ask')[,1]) #presumes unique timestamps
txntime = timestamp
} else next()
} else { # negative quantity 'sell'
- if(orderPrice <= as.numeric(getPrice(mktdataTimestamp,prefer='bid'))){
+ if(orderPrice <= as.numeric(getPrice(mktdataTimestamp,prefer='bid')[,1])){
# we're willing to sell at a better price than the bid, so execute at the prevailing price
# txnprice = orderPrice
- txnprice = as.numeric(getPrice(mktdataTimestamp,prefer='bid')) #presumes unique timestamp
+ txnprice = as.numeric(getPrice(mktdataTimestamp,prefer='bid')[,1]) #presumes unique timestamp
txntime = timestamp
} else next()
}
@@ -503,7 +503,7 @@
symbol=symbol,
timestamp=timestamp,
qty=orderQty,
- price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)),
+ price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)[,1]),
ordertype=orderType,
side=ordersubset[ii,"Order.Side"],
threshold=orderThreshold,
@@ -517,7 +517,7 @@
}
} else {
# no depth data, either OHLC or BBO, getPrice explicitly using symbol ?
- if(orderPrice == getPrice(mktdataTimestamp, symbol=symbol, prefer='price')){
+ if(orderPrice == getPrice(mktdataTimestamp, symbol=symbol, prefer='price')[,1]){
txnprice = orderPrice
txntime = timestamp
} else next()
@@ -529,20 +529,20 @@
if(orderQty > 0){ # positive quantity 'buy'
if(isBBOmktdata){
prefer='offer'
- if(orderPrice >= getPrice(mktdataTimestamp,prefer=prefer)){ #TODO maybe use last(getPrice) to catch multiple prints on timestamp?
+ if(orderPrice >= getPrice(mktdataTimestamp,prefer=prefer)[,1]){ #TODO maybe use last(getPrice) to catch multiple prints on timestamp?
# price we're willing to pay is higher than the offer price, so execute at the prevailing price
#txnprice = orderPrice
- txnprice = as.numeric(getPrice(mktdataTimestamp,prefer=prefer)) #presumes unique timestamps
+ txnprice = as.numeric(getPrice(mktdataTimestamp,prefer=prefer)[,1]) #presumes unique timestamps
txntime = timestamp
}
}
} else { # negative quantity 'sell'
if(isBBOmktdata){
prefer='bid'
- if(orderPrice <= getPrice(mktdataTimestamp,prefer=prefer)){
+ if(orderPrice <= getPrice(mktdataTimestamp,prefer=prefer)[,1]){
# we're willing to sell at a better price than the bid, so execute at the prevailing price
# txnprice = orderPrice
- txnprice = as.numeric(getPrice(mktdataTimestamp,prefer=prefer)) #presumes unique timestamp
+ txnprice = as.numeric(getPrice(mktdataTimestamp,prefer=prefer)[,1]) #presumes unique timestamp
txntime = timestamp
}
}
@@ -575,9 +575,9 @@
# check if we need to move the stop
mvstop=FALSE
if(orderQty > 0){ # positive quantity 'buy'
- if( as.numeric(last(getPrice(x=mktdataTimestamp,prefer=prefer)))+orderThreshold < orderPrice ) mvstop=TRUE
+ if( as.numeric(last(getPrice(x=mktdataTimestamp,prefer=prefer)[,1]))+orderThreshold < orderPrice ) mvstop=TRUE
} else { # negative quantity 'sell'
- if( as.numeric(last(getPrice(x=mktdataTimestamp,prefer=prefer)))+orderThreshold > orderPrice ) mvstop=TRUE
+ if( as.numeric(last(getPrice(x=mktdataTimestamp,prefer=prefer)[,1]))+orderThreshold > orderPrice ) mvstop=TRUE
}
if( isTRUE(mvstop) ){
@@ -585,7 +585,7 @@
symbol=symbol,
timestamp=timestamp,
qty=orderQty,
- price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)),
+ price=as.numeric(getPrice(mktdataTimestamp,prefer=prefer)[,1]),
ordertype=orderType,
side=ordersubset[ii,"Order.Side"],
threshold=orderThreshold,
Modified: pkg/quantstrat/R/traderules.R
===================================================================
--- pkg/quantstrat/R/traderules.R 2011-07-21 23:22:53 UTC (rev 693)
+++ pkg/quantstrat/R/traderules.R 2011-07-22 14:29:16 UTC (rev 694)
@@ -119,6 +119,7 @@
)
if(inherits(orderprice,'try-error')) orderprice<-NULL
if(length(orderprice>1) & !pricemethod=='maker') orderprice<-last(orderprice[timestamp])
+ if(!is.null(orderprice) && ncol(orderprice) > 1) orderprice <- orderprice[,1]
if(is.null(orderside) & !isTRUE(orderqty == 0)){
curqty<-getPosQty(Portfolio=portfolio, Symbol=symbol, Date=timestamp)
More information about the Blotter-commits
mailing list