Creating stock charts

Given R's powerful analysis and graphical capabilities, it is no surprise that R is very popular in the world of finance. In this recipe, we will learn how to plot data from the stock market using some special libraries.

Getting ready

We need the tseries and quantmod packages to run the following recipes. Let's install and load these two packages:

install.packages("quantmod")
install.packages("tseries")
library(quantmod)
library(tseries)

How to do it...

Let's first see an example using the tseries library function, get.hist.quotes(). We will compare the stock prices of three technology companies:

aapl<-get.hist.quote(instrument = "aapl", quote = c("Cl", "Vol")) goog <- get.hist.quote(instrument = "goog", quote = c("Cl", "Vol")) ...

Get R: Data Analysis and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.