Learn R Programming

quantstrat (version 0.16.7)

applyStrategy: apply the strategy to arbitrary market data

Description

This function is the wrapper that holds together the execution of a strategy.

Usage

applyStrategy(strategy, portfolios, mktdata = NULL, parameters = NULL,
  ..., debug = FALSE, symbols = NULL, initStrat = FALSE,
  updateStrat = FALSE, initBySymbol = FALSE, gc = FALSE,
  delorders = FALSE, rule.subset = NULL, mdenv = NULL)

Arguments

strategy

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

portfolios

a list of portfolios to apply the strategy to

mktdata

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

parameters

named list of parameters to be applied during evaluation of the strategy, default NULL

...

any other passthru parameters

debug

if TRUE, return output list

symbols

character vector identifying symbols to initialize a portfolio for, default NULL

initStrat

whether to use (experimental) initialization code, default FALSE

updateStrat

whether to use (experimental) wrapup code, default FALSE

initBySymbol

whether to load and initialize each instrument within the Symbols loop. See initSymbol for details on how to run a custom function. Moreover, if the argument Interval is available (as passthrough to updatePortf via updateStrat), each instrument is downsampled to the frequency specified by Interval for the purpose of marking the Portfolio. Notice that this happenes only after the strategy has been applied.

gc

if TRUE, call gc after each symbol run, default FALSE (experimental)

delorders

if TRUE, delete the order book for a symbol at the end of the symbols loop, will cause issues with rebalancing, default FALSE (experimental)

rule.subset

ISO-8601 subset for period to execute rules over, default NULL

mdenv

environment to look in for market data, default NULL which expands to .GlobalEnv

Details

After the straetgy object has been created, it may be applied to any combination of symbols and parameters.

The symbols to be utilized will be defined in one of two ways, either by specifying a name of a portfolio that has already been initialized with the portfolios argument, or be specifying a symbols argument in addition to setting initStrat=TRUE.

applyStrategy will use the R core function get to load market data for each symbol during stategy evaluation unless the user passes mktdata in the call to applyStrategy

See Also

strategy, applyIndicators, applySignals, applyRules, initStrategy,