Skip to content

Quantstrat problem

2 messages · Emanuel Burgener, Brian G. Peterson

#
On 12/28/2010 05:16 AM, Emanuel Burgener wrote:
I really try not to code custom indicators to give integer results like 
this.  I find that they are typically difficult to understand and debug. 
  See the 'macd' and 'rsi' demos for examples of how to use an indicator 
that you believe has some predictive power without having to further 
transform your indicator.  In practice, we use more 'sigFormula' calls 
than the simpler sigThreshold and sigCrossover calls, since this lets us 
do things like combine indicators (or prior signals) to get more 
business-oriented logic into the strategy.
Your indicator function doesn't name the columns but your sigCrossover 
expects columns named:

"minusOne","minusZero","Indicator"

Which will never work.

traceback says:

 > out<-applyStrategy(strategy=stratTest , portfolios="Test")
Error in do.call(opr, list(data[, colNums[1]], data[, colNums[2]])) :
   'what' must be a character string or a function
 > traceback()
7: do.call(opr, list(data[, colNums[1]], data[, colNums[2]]))
6: sigComparison(label = label, data = data, columns = columns[c(i,
        lng)], relationship = relationship)
5: diff(sigComparison(label = label, data = data, columns = columns[c(i,
        lng)], relationship = relationship))
4: function (label, data = mktdata, columns, relationship = c("gt",
        "lt", "eq", "gte", "lte"))
    {
        ret_sig = FALSE
        lng <- length(columns)
        for (i in 1:(lng - 1)) {
            ret_sig = ret_sig | diff(sigComparison(label = label,
                data = data, columns = columns[c(i, lng)], relationship 
= relationship)) ==
                1
        }
        is.na(ret_sig) <- which(!ret_sig)
        colnames(ret_sig) <- label
        return(ret_sig)
    }(label = "signal.sell1", data = mktdata, columns = c("minusOne",
    "minusZero", "Indicator"), relationship = "op")
3: do.call(fun, .formals)
2: applySignals(strategy = strategy, mktdata = mktdata, sret$indicators,
        parameters = parameters, ...)
1: applyStrategy(strategy = stratTest, portfolios = "Test")

Please look at the 'macross' demo, which does what you are trying to do 
in your example here. You'll probably be better served by extending it 
than by writing from scratch.
'blotter' is for transaction P&L.  I *never* call blotter by hand, 
except for the occasional addTxn call from inside a custom risk rule 
function or something similar.

We wrote quantstrat to simplify strategy modeling, and to reduce the 
amount of code needed to model and test a strategy.  I never 
contemplated using blotter for strategy modeling, just for P&L, so there 
in no 'simple' way to translate custom strategy code to quantstrat.  For 
an example of 'similar' things done in blotter and then again in 
quantstrat, see the 'longtrend' demo in blotter and the 'faber' example 
in quantstrat.  We'll be working on generalized capital-based order 
sizing functions in the next few weeks, so hopefully you'll have some 
examples of more sophisticated order sizing logic soon too.
Regards,

   - Brian