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.
We need the
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")) ...