Chart Plotting and (Some) Technical Analysis

The “quantmod”-package allows you to plot charts of a variety of financial investments – at least all that are accessible through the getSymbols() command. After downloading data, e.g., of a stock you can easily plot its chart with chartSereies(). In the case of the oil producer OMV this looks like

setwd('...')

library('quantmod')

getSymbols('OMV.VI',from='2014-01-01')
chartSeries(OMV.VI)

Mind that you do not have to use quotations marks here, since the date for OMV.VI was already downloaded and put in a separate environment.

The plot shows a chart with so-called candlesticks and the volumes that were traded at day are shown in a separate area below the graph. If you are not content with the candlestick design you can change this by specifying the type of chart that has to be generated. For more information see “?chartSeries”.

If you are into technical analysis, you now could add some indicators. A rather simple instrument are Bollinger Bands, where mean prices of the observed product are calculated over a user-specified amount of past days. Additionally, the command generates lines representing the standard deviations from the calculated mean values times a user-specified factor. This approach tries to visualise confidence intervals in which the price is likely to be with a certain probability, given the observations of the last days. However, there is no guarantee that it will be this way… A common factor is 2 which is an approximation of the 95% probability level, meaning that in 95% of the cases, the price should be somewhere between the bands.

In the example the mean is calculated with prices from the past 14 days and 2 is the factor used to calculate the bands.

addBBands(n=14,sd=2)

You can easily add other indicators like the relative strength index. Here, using again observations for the past 14 days, the code looks like

addRSI(n=14)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s