Monday, April 27, 2015

Financial data exploratory analysis (part 3)

Adding indicators to basic charts

In my previous post I outlined quantmod library basic charting features. In this post, I am going to enrich such basic charting with additional plots specifically related to quantitative indicators. At the purpose, I am going to take advantage of Yahoo 2014 year share price.

library(quantmod)
ticker <- "YHOO"
stock <- new.env()
startDate = as.Date("2014-01-01")
endDate = as.Date("2014-12-31")
getSymbols(ticker, source="yahoo", env = stock, from = startDate, to=endDate)
## [1] "YHOO"
share <- stock[[ticker]]

Starting from the basic charting capability, I add 5-days and 10-days Exponential Moving Average (EMA).

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addEMA(5, col="red"), addEMA(10, col="blue")), TAsep=',')

Always starting from the basic charting capability, here below I add 20-days and 50-days Exponential Moving Average̢۪s (EMA).

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addEMA(20, col="pink"), addEMA(50, col="cyan")), TAsep=',')

Herein below, I add Relative Strength Index (RSI) and Bollinger Bands.

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addRSI(),addBBands()), TAsep=',')

Herein below, I add Average Directional Index (ADX) and Commodity Channel Index (CCI).

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addADX(),addCCI() ), TAsep=',')

Herein below, I add Rate Of Change (ROC) and Williams Percent Range (WPR).

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addROC(),addWPR()), TAsep=',')

Herein below, I add parabolic Stop and Reversal (SAR) and Stochastic Momentum Indicator (SMI).

chartSeries(share, type='line', theme = chartTheme("white"), TA=c(addSAR(),addSMI() ), TAsep=',')

You may wonder how you can access the values associated to each indicator, here is how.

m <- addMACD()
head(m@TA.values, n=40)
##                  macd    signal
## 2014-01-02         NA        NA
## 2014-01-03         NA        NA
## 2014-01-06         NA        NA
## 2014-01-07         NA        NA
## 2014-01-08         NA        NA
## 2014-01-09         NA        NA
## 2014-01-10         NA        NA
## 2014-01-13         NA        NA
## 2014-01-14         NA        NA
## 2014-01-15         NA        NA
## 2014-01-16         NA        NA
## 2014-01-17         NA        NA
## 2014-01-21         NA        NA
## 2014-01-22         NA        NA
## 2014-01-23         NA        NA
## 2014-01-24         NA        NA
## 2014-01-27         NA        NA
## 2014-01-28         NA        NA
## 2014-01-29         NA        NA
## 2014-01-30         NA        NA
## 2014-01-31         NA        NA
## 2014-02-03         NA        NA
## 2014-02-04         NA        NA
## 2014-02-05         NA        NA
## 2014-02-06         NA        NA
## 2014-02-07 -4.7171391        NA
## 2014-02-10 -4.1740120        NA
## 2014-02-11 -3.5420627        NA
## 2014-02-12 -3.0895738        NA
## 2014-02-13 -2.6125677        NA
## 2014-02-14 -2.2704118        NA
## 2014-02-18 -1.9594595        NA
## 2014-02-19 -1.7988565        NA
## 2014-02-20 -1.6567421 -2.868981
## 2014-02-21 -1.6321395 -2.621612
## 2014-02-24 -1.5671167 -2.410713
## 2014-02-25 -1.5324096 -2.235052
## 2014-02-26 -1.4116673 -2.070375
## 2014-02-27 -1.1210957 -1.880520
## 2014-02-28 -0.8387384 -1.672163

In my next post, I will show how quantmod can be used to build a model for experimenting trading strategies.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.