This code takes advantage of some base R functionality that can treat an R object (in this case the internal mktdata object in quantstrat) as an environment or 'frame' using parent.frame
.
This allows the columns of the data to be addressed without any major manipulation, simply by column name. In most cases in quantstrat, this will be either the price/return columns, or columns added by indicators or prior signals.
The formula will return TRUE/FALSE for each row comparison as a time series column which can then be used for rule execution. The formula
will be evaluated using eval
as though in an if statement.
sigFormula(label, data = mktdata, formula, cross = FALSE)
text label to apply to the output
data to apply formula to
a logical expression like that used in an if statement, will typically reference column names in mktdata
if TRUE, will return TRUE only for the first observation to match the formula in a run
This code is adapted from the approach used by Vijay Vaidyanthan in his PAST(AAII/SIPRO) code to construct arbitrary, formulaic, comparisons. Many thanks to Vijay for sharing his expertise.