This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
install.packages("quantmod")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
install.packages("lubridate")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
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
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
getSymbols('AMZN', src = 'yahoo',
from = Sys.Date() - years(4), to = Sys.Date())
## [1] "AMZN"
getSymbols('TSLA', src = 'yahoo',
from = Sys.Date() - years(4), to = Sys.Date())
## [1] "TSLA"
stocks <- as.xts(data.frame(AMZN = AMZN$"AMZN.Close",
TSLA = TSLA$"TSLA.Close"))
plot(as.zoo(stocks),screens = 1,lty = c(1,3),
col = c("red","blue") ,xlab = "date",ylab = "Price")
legend("top",c("AMZN","TSLA"),
lty = c(1,3),col = c("red","blue"),cex = 0.5)