quantstrat (version 0.14.6)

applyIndicators: apply the indicators in the strategy to arbitrary market data

Description

applyIndicators will take the mktdata object, and will apply each indicator specified in the strategy definition to it.

Usage

applyIndicators(strategy, mktdata, parameters = NULL, ...)

Arguments

strategy

an object of type 'strategy' to add the indicator to

mktdata

an xts object containing market data. depending on indicators, may need to be in OHLCV or BBO formats

parameters

named list of parameters to be applied during evaluation of the strategy

...

any other passthru parameters

Value

mktdata with indicators colums added.

Details

If the indicator function returns an xts object or a vector of the same length as mktdata, the columns created by the indicator function will be added to the mktdata object via cbind.

If the indicator function returns multiple columns, the label will be paste'd to the end of either the returned column names or the respective column number when applying it to mktdata.

If the indicator returns some more complexobject, it will be added to a list in the $indicators slot inside the applyStrategy execution frame. If you want your indicators to return a more complex object, (such as a model specification and output from a regression), be advised that your signal generator, and potentially your rule function, will need to understand, anticipate, and know how to manipulate the internal strategy frame.

Examples

Run this code
# NOT RUN {
strategy("example", store=TRUE)
getSymbols("SPY", src='yahoo')
add.indicator('example', 'SMA', arguments=list(x=quote(Ad(SPY)), n=20))
str(getStrategy('example')$indicators)
out <- applyIndicators('example', SPY)
tail(out)
# }

Run the code above in your browser using DataCamp Workspace