Technical analysis with quantmod

[Please note that this article is for studying R programming purpose only, NOT for advices of investment]

May 18, 2016

http://www.investopedia.com/articles/investing/051816/what-most-fundamentally-sound-fang-stock.asp.

If you’re not familiar with FANG, it is an acronym for Facebook, Inc. (FB), Amazon.com, Inc. (AMZN), Netflix, Inc. (NFLX) and Alphabet Inc. (GOOGL). Over the past year they have returned 30.86%, 42.99%, -22.77% and 21.12%, respectively.

Bollinger Band - Volatility

Basically, this little tool tells us whether the market is quiet or whether the market is LOUD! When the market is quiet, the bands contract and when the market is LOUD, the bands expand.

Developed by technical analyst John Bollinger in the 1980s, Bollinger Bands identify the degree of real-time volatility for a currency pair.

One thing you should know about Bollinger Bands is that price tends to return to the middle of the bands. That is the whole idea behind the Bollinger bounce.

Simple Moving Average - Trend

Moving average crossovers are a common way traders can use Moving Averages. A crossover occurs when a faster Moving Average (i.e. a shorter period Moving Average) crosses either above a slower Moving Average (i.e. a longer period Moving Average) which is considered a bullish crossover or below which is considered a bearish crossover.

Simple Moving Average is a method of time series smoothing and is actually a very basic forecasting technique.

Relative Strength Index - Momentum

RSI is considered overbought when above 70 and oversold when below 30.

              100
RSI = 100 - --------
             1 + RS

RS = Average Gain / Average Loss

Developed J. Welles Wilder, the Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. RSI oscillates between zero and 100. Traditionally, and according to Wilder, RSI is considered overbought when above 70 and oversold when below 30. Signals can also be generated by looking for divergences, failure swings and centerline crossovers. RSI can also be used to identify the general trend.

library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
##Chart a stock with MA(50), Bollinger, Volume and RSI
getSymbols("AMZN")
##     As of 0.4-0, 'getSymbols' uses env=parent.frame() and
##  auto.assign=TRUE by default.
## 
##  This  behavior  will be  phased out in 0.5-0  when the call  will
##  default to use auto.assign=FALSE. getOption("getSymbols.env") and 
##  getOptions("getSymbols.auto.assign") are now checked for alternate defaults
## 
##  This message is shown once per session and may be disabled by setting 
##  options("getSymbols.warning4.0"=FALSE). See ?getSymbols for more details.
## [1] "AMZN"
chartSeries(AMZN, subset='2016-05-18::2017-01-30',theme=chartTheme('white',up.col='green',dn.col='red'),TA=c(addBBands(n=20,sd=2,),addSMA(n=50,col="blue"),addSMA(n=10,col="black"),addRSI(n=14)))

chartSeries(AMZN, subset='2016-11-01::2017-01-30',theme=chartTheme('white',up.col='green',dn.col='red'),TA=c(addBBands(n=20,sd=2,),addSMA(n=26,col="blue"),addSMA(n=12,col="black"),addRSI(n=14)))

# subset plotting

candleChart(AMZN,subset='2014-09::2017-02-11',theme='white', type='candles') 

#reChart(major.ticks='months',subset='last 2 months') 
reChart(subset="last 2 months")

Zoom in and Zoom out Plots

You can also zoom in and rechart plots, for example:

getSymbols("SPY", src='yahoo', from='2016-01-01', to='2017-02-11')
## [1] "SPY"
chartSeries(SPY,theme=chartTheme('white',up.col='green',dn.col='red'))

zoomChart("last 2 week") # zoom in

reChart(subset="last 2 months") # zoom out

zoomChart("last 1 months") # zoom in

zoomChart() # zoom out