DATA607dscpresent

jim lung

04-26-2017

Quantmod package for R

Quantitative Financial Modelling & Trading Framework

The quantmod package for R is designed to assist the quantitative trader in the development, testing, and deployment of statistically based trading models.

Quantmod makes modelling easier by removing the repetitive workflow issues surrounding data management, modelling interfaces, and performance analysis.

What is Quantmod?

A rapid prototyping environment, where quant traders can quickly and cleanly explore and build trading models.

picture

picture

Getting data

It is possible with one quantmod function to load data from a variety of sources, including…

Yahoo! Finance (OHLC data) Federal Reserve Bank of St. Louis FREDR (11,000 economic series) Google Finance (OHLC data)

library(quantmod)
getSymbols("AAPL",src="yahoo") 
## [1] "AAPL"
tail(AAPL)
##            AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
## 2017-04-19    141.88    142.00   140.45     140.68    17271300
## 2017-04-20    141.22    142.92   141.16     142.44    23251100
## 2017-04-21    142.44    142.68   141.85     142.27    17245200
## 2017-04-24    143.50    143.95   143.18     143.64    17099200
## 2017-04-25    143.91    144.90   143.87     144.53    18290300
## 2017-04-26    144.47    144.60   143.38     143.68    19769400
##            AAPL.Adjusted
## 2017-04-19        140.68
## 2017-04-20        142.44
## 2017-04-21        142.27
## 2017-04-24        143.64
## 2017-04-25        144.53
## 2017-04-26        143.68

Charting with quantmod

Enter the new function chartSeries. At present this is a nice tool to visualize financial time series in a way that many practicioners are familiar with - line charts, as well as OHLC bar and candle charts. There are convenience wrappers to these different styles (lineChart,barChart, and candleChart), though chartSeries does quite a bit to automatically handle data in the most appropriate way.

getSymbols("GOOG",src="google") # from google finance
## [1] "GOOG"
getSymbols("YHOO",src="yahoo") # from yahoo finance
## [1] "YHOO"
getSymbols("AAPL",src="yahoo") 
## [1] "AAPL"
barChart(AAPL)

candleChart(AAPL,multi.col=TRUE,theme="white") 

Example

getSymbols("AAPL",src="yahoo")
## [1] "AAPL"
chartSeries(to.weekly(AAPL),up.col='white',dn.col='blue')

Technical analysis charting tools

As of version 0.3-0 one can now add technical analysis studies from package TTR to the above chart.

require(TTR) 
getSymbols("AAPL") 
## [1] "AAPL"
chartSeries(AAPL) 

addMACD() 

addBBands() 

addRSI(n = 14, maType="EMA", wilder=TRUE)

Reference

http://www.quantmod.com/examples/data/

Financial Charts in quantmod

http://www.quantmod.com/examples/charting/