[R-SIG-Finance] label in add.indicator not accepted (quantstrat)

Brian G. Peterson brian at braverock.com
Mon Aug 1 16:14:14 CEST 2011


On Sun, 2011-07-31 at 15:32 +0200, Daniel Krizian wrote:
> Hello,
> 
> assigning labels via add.indicator function (in quantstrat) does not work
> for TTR function "momentum" or "ROC" and generally other functions having
> output with non-null column names. Labelling works properly only for
> indicator functions that have empty column names, e.g. RSI, SMA used in
> demos.
> getSymbols('AAPL')
> head(RSI(Cl(AAPL)))
> head(SMA(Cl(AAPL)))
> head(momentum(Cl(AAPL)))
> head(ROC(Cl(AAPL)))
> 
> For example, I have line, in which assignment label="momentum" will be
> totally ignored later by applyIndicators:
> 
> mystrat <- add.indicator(strategy = mystrat, name = "momentum", arguments =
> list(x=quote(Cl(mktdata))), label = "mom" )
> 
> This piece of code in applyIndicators causes the behavior:
> if (is.null(names(tmp_val)) & ncol(tmp_val) == 1)
>    names(tmp_val) <- indicator$label
> 
> My suggestion is to replace it with more intuitive behavior:
> if (!is.null(indicator$label) & ncol(tmp_val) == 1)
>    names(tmp_val) <- indicator$label
> 
> Thank you.

Daniel,

I like the spirit of your suggestion, but I'm not sure about the exact
implementation.  In the current code, label is never NULL, because of
this line in add.indicator

    if(is.null(label)) label = paste(name,"ind",sep='.')

Your suggested patch would ignore any names set by an indicator
function, which seems to be counterproductive where indicator functions
add meaningful names.

Perhaps, instead, we need to test to see if the returned tmp_val column
name is duplicated in the mktdata, and overwrite with label in that
case.

-- 
Brian



More information about the R-SIG-Finance mailing list