[R-SIG-Finance] Using the market (SPY) as an indicator in Quanstrat

Brian G. Peterson brian at braverock.com
Tue Feb 9 11:18:36 CET 2016

On 02/09/2016 03:56 AM, Smith Jimmy wrote:
> I have a portfolio of 50 stocks that I am back testing a strategy on using
> Quantstrat.
> I would like to also use the RSI of the SPY (as an example) as another
> signal in the strategy.
> Eg. Buy Signal - SPY RSI < 20
> However I'm not sure where in the Quanstrat workflow I should be
> implementing it.
> I can't add it to the add.indicator as that references mktdata and the
> add.signal references the columns.
> How should I go about adding this in?

In the future, please provide a minimal reproducible example, per the 
posting guide.  It makes it easier for others to help you.

There is nothing that requires your indicators to reference mktdata. 
That's the most common case, as you typically want to be adding columns 
to the mktdata object, and want mktdata to change as quantstrat loops 
over symbols.

So, for example, if the 'standard' or 'demonstration' construction looks 
something like this:

add.indicator(strategy = 'stratRSI', name = "RSI",
arguments = list(price = quote(getPrice(mktdata))), label="RSI")

where you reference mktdata (and as such, are expecting mktdata to 
change for each instrument, see the 'faber' demo for an example).

You can construct an indicator like so:

add.indicator(strategy = stratRSI, name = "RSI",
arguments = list(price = getPrice(SPY)), label="SPYRSI")

This will cause a 'SPYRSI' column to be added to the mktdata object for 
each symbol in your symbols list, and you may now reference column 
'SPYRSI' in later indicators or signals, as usual.



Brian G. Peterson
Ph: 773-459-4973
IM: bgpbraverock

More information about the R-SIG-Finance mailing list