I'm testing out quantstrat using a simple one-indicator strategy.
The error I get after applyStrategy(...) is

Error in .xts(e, .index(e1), .indexCLASS = indexClass(e1), .indexFORMAT = indexFormat(e1),  :
  index length must match number of observations
In addition: Warning messages:
1: In match.names(column, colnames(data)) :
  all columns not located in roc_15 for STOXX.Open STOXX.High STOXX.Low STOXX.Close STOXX.Close.1
2: In min(j, na.rm = TRUE) :
  no non-missing arguments to min; returning Inf
3: In max(j, na.rm = TRUE) :
  no non-missing arguments to max; returning -Inf

my code:

####################################################
#                              Environments                                     #
####################################################

if( !exists(".instrument") ) .instrument <<- new.env()
if( !exists(".blotter") ) .blotter <<- new.env()
if( !exists(".strategy") ) .strategy <<- new.env()

suppressWarnings( rm("account.STOXX", "portfolio.STOXX", pos=.blotter) )
suppressWarnings( rm("stratROC", "initDate", "initEq") )
suppressWarnings( rm("order_book.STOXX", pos=.strategy) )

##################################################
#                                Get Data                                      #
##################################################

ch <- odbcConnect("PostgreSQL35W")

tablenames <- sqlTables(ch, schema = "marketdata")[,"TABLE_NAME"]

chooseTable <- function(table.name) x <- table.name

table.name <- guiv(chooseTable,
                   argList = list(table.name = tablenames))

data.df <- sqlFetch(ch,
                    paste("marketdata",
                          table.name,
                          sep = "."),
                    colnames = TRUE,
                    rownames = TRUE)

data.xts <- as.xts(data.df)
STOXX <- xts( cbind( as.numeric(data.xts$open),
              as.numeric(data.xts$high),
              as.numeric(data.xts$low),
              as.numeric(data.xts$close) ),
              order.by=index(data.xts) )
colnames(STOXX) <- c("STOXX.Open", "STOXX.High", "STOXX.Low", "STOXX.Close")

rm(table.name, tablenames, ch, chooseTable)

stock('STOXX', currency="ZAR", multiplier=1)

mktdata <- STOXX

spot <- as.xts( as.numeric(data.xts$spot),
                order.by=index(data.xts) )
colnames(spot) <- "spot"

################################################
#                               Initialise                                     #
################################################

initDate = index( first(data.xts) )

initEq = 100

currency("ZAR")

initPortf('STOXX', symbols='STOXX', initDate=initDate)

initAcct('STOXX', portfolios='STOXX', initDate=initDate, initEq=100)

initOrders(portfolio='STOXX', initDate=initDate)

stratROC <- strategy("ROC")

#####################################################
#                            Construct Strategy                                 #
#####################################################

stratROC <- add.indicator( strategy = stratROC,
                           name = "ROC",
                           arguments=list( x=Cl(STOXX) ),
                           label="roc_15" )

# gte
stratROC <- add.signal( stratROC,
                        name="sigThreshold",
                        arguments = list(column="roc_15",
                                         Threshold=5,
                                         relationship="gte"),
                        label="roc.gte" )

# lte
stratROC <- add.signal( stratROC,
                        name="sigThreshold",
                        arguments = list(column="roc_15",
                                         Threshold=-5,
                                         relationship="lte"),
                        label="roc.lte" )

# long enter
stratROC <- add.rule( stratROC,
                      name='ruleSignal',
                      arguments = list(sigcol="roc.gte", sigval=TRUE, orderqty=1,
                                       ordertype='market', orderside='long', pricemethod='market', TxnFees=-2),
                      type='enter', path.dep=TRUE )

# long exit
stratROC <- add.rule( stratROC,
                      name='ruleSignal',
                      arguments = list(sigcol="roc.lte", sigval=TRUE, orderqty='all',
                                       ordertype='market', orderside='long', pricemethod='market', TxnFees=-2),
                      type='exit', path.dep=TRUE )

# short enter
stratROC <- add.rule( stratROC,
                      name='ruleSignal',
                      arguments = list(sigcol="roc.lte", sigval=TRUE, orderqty=-1,
                                       ordertype='market', orderside='short', pricemethod='market', TxnFees=-2),
                      type='enter', path.dep=TRUE )

# short exit
stratROC <- add.rule( stratROC,
                      name='ruleSignal',
                      arguments = list(sigcol="roc.gte", sigval=TRUE, orderqty='all',
                                       ordertype='market', orderside='short', pricemethod='market', TxnFees=-2),
                      type='exit', path.dep=TRUE )

out <- try( applyStrategy(strategy=stratROC, portfolios='STOXX') )

updatePortf( Portfolio='STOXX', Dates=paste('::', as.Date(Sys.time()), sep='') )

#################################################
#                                  End                                          #
#################################################


Any help would be much appreciated.

Steven Kukard












	[[alternative HTML version deleted]]

