— title: “Quantmod” author: “cms” date: “February 11, 2019” output: html_document —
library(tidyverse)
## -- Attaching packages -- tidyverse 1.3.0 --
## <U+221A> ggplot2 3.3.2 <U+221A> purrr 0.3.4
## <U+221A> tibble 3.0.3 <U+221A> dplyr 1.0.1
## <U+221A> tidyr 1.1.1 <U+221A> stringr 1.4.0
## <U+221A> readr 1.3.1 <U+221A> forcats 0.5.0
## -- Conflicts ----- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
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
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(PerformanceAnalytics)
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
library(RColorBrewer)
library(tseries)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(Quandl)
Quandl.api_key("zrcB2Ejv9UmvhPCUsy2_")
msft<-getSymbols("MSFT", auto.assign = F)
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be 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 details.
#Line Graph
chartSeries(msft,
type="line",
subset="2008",
theme = chartTheme("black"))
#Bar
chartSeries(msft,
type="bar",
subset="2008",
theme = chartTheme("black"))
#Candlestick
chartSeries(msft,
type="candlestick",
subset="2008",
theme = chartTheme("white"))
#Bollinger Bands
chartSeries(msft,
type="auto",
subset="2007-05-10::2010-05-10",
theme = chartTheme("white"))
chartSeries(msft,
subset = "2007",
TA="addBBands(n=20, sd=2)",
theme=chartTheme("white"))
#RSI
chartSeries(msft,
type = "line",
subset = "2007",
TA=c(addBBands(n=20, sd=2),addRSI()),
theme=chartTheme("white"))
#MACD
chartSeries(msft,
type = "line",
subset = "2007",
TA=c(addBBands(n=20, sd=2),addRSI(),addEMA(n=30),addMACD()),
theme=chartTheme("white"))