**R-Chart**, and kindly contributed to R-bloggers)

Want to do some quick, in depth technical analysis of Apple stock price using R? Theres a package for that!

The Quantmod package allows you to develop, testing, and deploy of statistically based trading models. It provides the infrastructure for downloading/importing data from a variety of locations, analyze that data and produce charts that help determine statistical trends. I appreciated Digital Dude calling this package to my attention in a recent comment. I also noticed that Revolution Analytics had highlighted the package on its finance page. Actually, I had come across quantmod a few months ago – and it instantly got me excited about the power of R. To give you an idea of typical usage, the following creates a stock chart of the last three months of Apple stock data.

library(‘quantmod’)

getSymbols(“AAPL”)

chartSeries(AAPL, subset=’last 3 months’)

addBBands()

The getSymbols function is used to retrieve stock data. Data can originate in a number of locations. In the example above, we are obtaining a single stock, Apple. If you wanted to download several different stock quotes, you can do so in a single command.

getSymbols(c(“ORCL”,”IBM”))

You can also merge data to view comparisons.

head(as.xts(merge(ORCL,IBM)))

The chartSeries command creates the plot pictured above. It captures a large amount of information, the date, open and close price, and volume of trading for each day. Finally, the addBBands() call adds Bollinger Bands to the chart. Informally, this amounts to a line indicating moving average and two lines a standard deviation above and below this moving average. For the uninitiated, technical indicators (and overlays) can be broken up into four categories – Trend, Volatility, Momentum, and Volume. Those available in Quantmod are listed below.

**Trend**

Indicator | TTR Name | quantmod Name |
---|---|---|

Welles Wilder’s Directional Movement Indicator | ADX | addADX |

Double Exponential Moving Average | DEMA | addDEMA |

Exponential Moving Average | EMA | addEMA |

Simple Moving Average | SMA | addSMA |

Parabolic Stop and Reverse | SAR | addSAR |

Exponential Volume Weighted Moving Average | EVWMA | addEVWMA |

Moving Average Convergence Divergence | MACD | addMACD |

Triple Smoothed Exponential Oscillator | TRIX | addTRIX |

Weighted Moving Average | WMA | addWMA |

ZLEMA | ZLEMA | addZLEMA |

**Volatility**

Indicator | TTR Name | quantmod Name |
---|---|---|

Average True Range | ATR | addATR |

Bollinger Bands | BBands | addBBands |

Price Envelope | N/A | addEnvelope |

**Momentum**

Indicator | TTR Name | quantmod Name |
---|---|---|

Commodity Channel Index | CCI | addCCI |

Chande Momentum Oscillator | CMO | addCMO |

Detrended Price Oscillator | DPO | addDPO |

momentum | addMomentum | |

Rate of Change | ROC | addROC |

Relative Strength Indicator | RSI | addRSI |

Stocastic Momentum Index | SMI | addSMI |

Williams %R | WPR | addWPR |

**Volume**

Indicator | TTR Name | quantmod Name |
---|---|---|

Chaiken Money Flow | CMF | addCMF |

Volume | N/A | addVo |

This really just scratches the surface of what is possible with quantmod. For instance, see this post on using quantmod with gold related data.

Later posts will include other applications – there is simply too much to cover at one time.

**leave a comment**for the author, please follow the link and comment on his blog:

**R-Chart**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...