[R-SIG-Finance] Using quantstrat indicators against columns other than "Close"

Brian G. Peterson brian at braverock.com
Fri Feb 10 17:37:58 CET 2012


On Fri, 2012-02-10 at 08:26 -0800, Sergey Pisarenko wrote:
> Hi,
> 
> I have started using 'quantstrat' to model strategies and cannot
> figure out a way to add an indicator that would be calculated against
> a column other than "Close". For example, in the code below I create a
> 5-day SMA:
> 
> s         <- add.indicator(strategy=s, name='SMA',
> arguments=list(x=quote(Cl(mktdata)), n=5), label='SMA5')
> 
> This creates a column with 5-day SMA calculated for the closing price
> of the instrument. What is the correct approach of using indicators
> against other columns, such as "Volume"?

the Cl() function there should be the clue...

Cl(), Op(), Vo(), etc are all utility functions provided by quantmod to
extract specific columns by common name.  You could also use standard R
subsetting to get any column you want out of your data.

Regards,

   - Brian
 
-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list