[Blotter-commits] r284 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 15 21:52:14 CET 2010
Author: braverock
Date: 2010-03-15 21:52:14 +0100 (Mon, 15 Mar 2010)
New Revision: 284
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/R/signals.R
pkg/quantstrat/R/traderules.R
Log:
- updates to fix issues in low-frequency strategy around timestamp matching
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2010-03-14 17:53:29 UTC (rev 283)
+++ pkg/quantstrat/R/orders.R 2010-03-15 20:52:14 UTC (rev 284)
@@ -273,12 +273,12 @@
market = ,
limit = {
if (procorders[ii,]$Order.Type == 'market' ){
- txnprice=as.numeric(getPrice(mktdata[timestamp], prefer='close'))
+ txnprice=as.numeric(getPrice(mktdata[as.character(timestamp)], prefer='close'))
#if(!is.null(ncol(txnprice)) & ncol(txnprice)>1) txnprice = as.numeric(getPrice(mktdata[timestamp], symbol=symbol, prefer='close'))
txntime=prevtime
} else {
# check to see if price moved through the limit
- if(procorders[ii,]$Order.Price>Lo(mktdata[timestamp]) & procorders[ii,]$Order.Price<Hi(mktdata[timestamp]) ) {
+ if(procorders[ii,]$Order.Price>Lo(mktdata[as.character(timestamp)]) & procorders[ii,]$Order.Price<Hi(mktdata[as.character(timestamp)]) ) {
txnprice=as.numeric(procorders[ii,]$Order.Price)
txntime=timestamp
} else {
Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R 2010-03-14 17:53:29 UTC (rev 283)
+++ pkg/quantstrat/R/signals.R 2010-03-15 20:52:14 UTC (rev 284)
@@ -114,7 +114,7 @@
#'
#' Comparison will be applied from the first to the second column in the \code{columns} vector.
#'
-#' Relationship 'op' means 'opposite side. Reasonable attempt will be made to match.
+#' Relationship 'op' means 'opposite' side. Reasonable attempt will be made to match.
#'
#' @param label text label to apply to the output
#' @param data data to apply comparison to
Modified: pkg/quantstrat/R/traderules.R
===================================================================
--- pkg/quantstrat/R/traderules.R 2010-03-14 17:53:29 UTC (rev 283)
+++ pkg/quantstrat/R/traderules.R 2010-03-15 20:52:14 UTC (rev 284)
@@ -30,7 +30,9 @@
#' @export
ruleSignal <- function(mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside, threshold=NULL, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside'), portfolio, symbol, ... ) {
if(!is.function(osFUN)) osFUN<-match.fun(osFUN)
- if (!is.na(mktdata[timestamp][,sigcol]) & mktdata[timestamp][,sigcol] == sigval) {
+ #print(paste(symbol,timestamp))
+ #print(mktdata[timestamp][,sigcol])
+ if (!is.na(mktdata[as.character(timestamp)][,sigcol]) & mktdata[as.character(timestamp)][,sigcol] == sigval) {
#TODO add fancy formals matching for osFUN
if(orderqty=='all'){
orderqty=-1*getPosQty(Portfolio=portfolio,Symbol=symbol,Date=timestamp)
@@ -42,19 +44,19 @@
#calculate order price using pricemethod
pricemethod<-pricemethod[1] #only use the first if not set by calling function
switch(pricemethod,
- opside = {
- if (orderqty>0)
- prefer='ask' # we're buying, so pay what they're asking
- else
- prefer='bid' # we're selling, so give it to them for what they're bidding
- orderprice <- try(getPrice(x=mktdata,symbol=symbol,prefer=prefer))
- },
- market = {
- orderprice <- try(getPrice(x=mktdata,symbol=symbol,prefer=NULL))
- }
+ opside = {
+ if (orderqty>0)
+ prefer='ask' # we're buying, so pay what they're asking
+ else
+ prefer='bid' # we're selling, so give it to them for what they're bidding
+ orderprice <- try(getPrice(x=mktdata,symbol=symbol,prefer=prefer))
+ },
+ market = {
+ orderprice <- try(getPrice(x=mktdata,symbol=symbol,prefer=NULL))
+ }
)
if(inherits(orderprice,'try-error')) orderprice<-NULL
- if(length(orderprice>1)) orderprice<-last(orderprice[timestamp])
+ if(length(orderprice>1)) orderprice<-last(orderprice[as.character(timestamp)])
if(is.null(orderside) & !orderqty == 0){
curqty<-getPosQty(Portfolio=portfolio, Symbol=symbol, Date=timestamp)
if (curqty>0 ){
@@ -72,6 +74,7 @@
}
}
if(!is.null(orderqty) & !orderqty == 0 & !is.null(orderprice)){
+ # print(orderprice)
addOrder(portfolio=portfolio, symbol=symbol, timestamp=timestamp, qty=orderqty, price=orderprice, ordertype=ordertype, side=orderside, threshold=threshold, status="open", replace=replace , delay=delay, ...)
}
}
@@ -138,7 +141,7 @@
getPosLimit <- function(portfolio, symbol, timestamp){
portf<-getPortfolio(portfolio)
# try to get on timestamp, otherwise find the most recent
- toDate = paste('::', timestamp, sep="")
+ toDate = paste('::', as.character(timestamp), sep="")
PosLimit = last(portf[[symbol]]$PosLimit[toDate])
return(PosLimit)
}
More information about the Blotter-commits
mailing list