[Blotter-commits] r421 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 14 20:54:07 CEST 2010
Author: llevenson
Date: 2010-10-14 20:54:07 +0200 (Thu, 14 Oct 2010)
New Revision: 421
Modified:
pkg/quantstrat/R/orders.R
Log:
- fixed multiple as.numeric()
- added isTRUE around is.na()
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2010-10-12 17:33:09 UTC (rev 420)
+++ pkg/quantstrat/R/orders.R 2010-10-14 18:54:07 UTC (rev 421)
@@ -446,7 +446,7 @@
}
} else {
# no depth data, either OHLC or BBO, getPrice explicitly using symbol ?
- if(ordersubset[ii,]$Order.Price==getPrice(mktdata[timestamp], symbol=symbol, prefer='price')){
+ if(as.numeric(ordersubset[ii,]$Order.Price)==getPrice(mktdata[timestamp], symbol=symbol, prefer='price')){
txnprice = as.numeric(ordersubset[ii,]$Order.Price)
txntime = as.character(timestamp)
} else next()
@@ -456,13 +456,13 @@
stoptrailing = {
# if market moved through my price, execute
if(as.numeric(ordersubset[ii,]$Order.Qty)>0){ # positive quantity 'buy'
- if(ordersubset[ii,]$Order.Price>=getPrice(mktdata[timestamp],prefer='offer')){
+ if(as.numeric(ordersubset[ii,]$Order.Price)>=getPrice(mktdata[timestamp],prefer='offer')){ #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 limit
txnprice = as.numeric(ordersubset[ii,]$Order.Price)
txntime = as.character(timestamp)
}
} else { # negative quantity 'sell'
- if(ordersubset[ii,]$Order.Price<=getPrice(mktdata[timestamp],prefer='bid')){
+ if(as.numeric(ordersubset[ii,]$Order.Price)<=getPrice(mktdata[timestamp],prefer='bid')){
# we're willing to sell at a better price than the bid, so execute at the limit
txnprice = as.numeric(ordersubset[ii,]$Order.Price)
txntime = as.character(timestamp)
@@ -484,12 +484,12 @@
} else {
prefer=NULL # see if getPrice can figure it out
}
- if( getPrice(mktdata[timestamp],prefer=prefer)+ordersubset[ii,]$Order.Threshold > ordersubset[ii,]$Order.Price ){
+ if( last(getPrice(mktdata[timestamp],prefer=prefer))+as.numeric(ordersubset[ii,]$Order.Threshold) > as.numeric(ordersubset[ii,]$Order.Price) ){
neworder<-addOrder(portfolio=portfolio,
symbol=symbol,
timestamp=timestamp,
qty=as.numeric(ordersubset[ii,]$Order.Qty),
- price=getgetPrice(mktdata[timestamp],prefer=prefer)+ordersubset[ii,]$Order.Threshold,
+ price=last(getPrice(mktdata[timestamp],prefer=prefer))+as.numeric(ordersubset[ii,]$Order.Threshold),
ordertype=ordersubset[ii,]$Order.Type,
side=ordersubset[ii,]$Order.Side,
threshold=ordersubset[ii,]$Order.Threshold,
@@ -505,7 +505,7 @@
# else next
}
)
- if(!is.null(txnprice)& !is.na(txnprice)){
+ if(!is.null(txnprice) & !isTRUE(is.na(txnprice))){
addTxn(Portfolio=portfolio, Symbol=symbol, TxnDate=txntime, TxnQty=as.numeric(ordersubset[ii,]$Order.Qty), TxnPrice=txnprice , ...=..., TxnFees=txnfees)
ordersubset[ii,]$Order.Status<-'closed'
ordersubset[ii,]$Order.StatusTime<-as.character(timestamp)
More information about the Blotter-commits
mailing list