The quantmod package is great for quickly generating stock charts. This article is a very brief overview of charting with quantmod. We recommend reading the documentation for any of the functions we use in our examples so you can see their full functionality (we just use the defaults for all of the arguments in our examples). This article assumes a basic working knowledge of R.
About quantmod
“The quantmod package for R is designed to assist the quantitative trader in the development, testing, and deployment of statistically based trading models.” – quantmod documentation (https://cran.r-project.org/web/packages/quantmod/quantmod.pdf)
Data
Use the getSybols function to download the price and volume data for the companies you are interested in. The default data source that quantmod uses is Yahoo Finance, so head to their website to make sure you use the right ticker symbols. In our example we will generate charts for Uranium Participation Corporation, Cameco, and Denison Mines. The screenshot below shows how we check Yahoo Finance for the correct ticker symbol (for our example we want the Toronto Stock Exchange symbols).

Running getSymbols(“U.TO”) will place the data in your environment (see screenshot below; we are using RStudio).

Creating a Chart
Quickly Produce a Chart
We will use the chartSeries function to make our charts. Here is a description of the function from the R documentation (run ?chartSeries after loading the quantmod package to view the documentation for this function):
“Charting tool to create standard financial charts given a time series like object. Serves as the base function for future technical analysis additions. Possible chart styles include candles, matches (1 pixel candles), bars, and lines. Chart may have white or black background.”
Running chartSeries(U.TO) will quickly produce a candlestick chart of Uranium Participation Corporation. The chart, by default, will include volume.

One of the great features of the chartSeries function is that it allows you to chart subsets of the data. For example, running chartSeries(U.TO, subset = ‘last 3 months’) adjusts the above chart such that only the last three months are shown.

Technical Analysis
There are a number of functions in quantmod which allow you to add technical analysis indicators to your chart. Here are a few examples:
- addSMA to add simple moving averages
- addEMA to add exponential moving averages
- addBBands to add Bollinger bands
- addMACD to add moving average convergence divergence
Let’s add some technicals to our U.TO chart:

Putting it all Together
Suppose you want to write a simple script that generates up-to-date price charts of some stocks you are following (including your favorite technical indicators). As our following example shows, this is a very simple task when you use the quantmod package.
Let’s say you want to generate charts for the past three months of U.TO, CCO.TO, and DML.TO. You want your U chart to have Bollinger bands, your CCO chart to have MACD, and your DML chart to have 20, 50, and 200 day simple moving averages.
Using the following script, you can simply generate the charts every day with only a few clicks!



