#stock data
getSymbols(c("XOM","BP","SLB"), from = "2015-01-01", to="2020-10-24")
## '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.
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## [1] "XOM" "BP" "SLB"
chartSeries(XOM,
type = "bar",
show.grid = TRUE,
name = "XOM",
time.scale = NULL,
log.scale = FALSE,
TA = c(addVo(),addBBands(),addEMA()), # indicators on the chart
TAsep=';',
line.type = "l",
bar.type = "ohlc",
theme = chartTheme("white"),
layout = NA,
major.ticks='auto', minor.ticks=TRUE,
yrange=NULL,
plot=TRUE)
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").

chartSeries(BP,
type = "bar",
show.grid = TRUE,
name = "BP",
time.scale = NULL,
log.scale = FALSE,
TA = c(addVo(),addBBands(),addEMA()), # indicators on the chart
TAsep=';',
line.type = "l",
bar.type = "ohlc",
theme = chartTheme("white"),
layout = NA,
major.ticks='auto', minor.ticks=TRUE,
yrange=NULL,
plot=TRUE)
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").

chartSeries(SLB,
type = "bar",
show.grid = TRUE,
name = "SLB",
time.scale = NULL,
log.scale = FALSE,
TA = c(addVo(),addEMA()), # indicators on the chart
TAsep=';',
line.type = "l",
bar.type = "ohlc",
theme = chartTheme("white"),
layout = NA,
major.ticks='auto', minor.ticks=TRUE,
yrange=NULL,
plot=TRUE)
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").

stockmarketdata <- cbind(XOM$XOM.Close, BP$BP.Close,SLB$SLB.Close)
#normalize data
stockmarketdata$XOM <- stockmarketdata[,1] / 92.83
stockmarketdata$BP <- stockmarketdata[,2] / 38.12
stockmarketdata$SLB <- stockmarketdata[ ,3] / 85.67
#Isolate normalized data
marketdata <- stockmarketdata[,4:6]
#format before making ggplot chart
market.df <- data.frame(Date=index(marketdata), marketdata)
market.df.eco <- market.df
colnames(market.df.eco) <- c("Date", "XOM", "BP","SLB")
market.df.eco.mlt <- melt(market.df.eco, id = "Date")
dim(market.df.eco.mlt)
## [1] 4392 3
ggplot(market.df.eco.mlt, aes(x=Date, y=value, colour = variable, group = variable)) +
geom_line() +
labs(title="Performance Comparison_Energy stocks", y= "Index 2015=1", x = "",
color="Companies", title.vjust=1) +
theme_economist() +
scale_color_economist() +
theme(legend.position = c(0,1),
legend.justification=c(0,1),
legend.direction="horizontal",
plot.title = element_text(vjust=1),
legend.title=element_text(vjust=1),
legend.title.align=0)

#stock data
getSymbols(c("XOM","BP","SLB"), from = "2020-01-01", to="2020-10-24")
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## Warning: 'indexClass<-' is deprecated.
## Use 'tclass<-' instead.
## See help("Deprecated") and help("xts-deprecated").
## [1] "XOM" "BP" "SLB"
stockmarketdata <- cbind(XOM$XOM.Close, BP$BP.Close,SLB$SLB.Close)
#normalize data
stockmarketdata$XOM <- stockmarketdata[,1] / 70.90
stockmarketdata$BP <- stockmarketdata[,2] / 38.14
stockmarketdata$SLB <- stockmarketdata[ ,3] / 40.17
#Isolate normalized data
marketdata_2020 <- stockmarketdata[,4:6]
#format before making ggplot chart
market.df <- data.frame(Date=index(marketdata_2020), marketdata_2020)
market.df.eco <- market.df
colnames(market.df.eco) <- c("Date", "XOM", "BP","SLB")
market_2020 <- tail(market.df.eco, n=206)
market_2020a <- melt(market_2020, id = "Date")
dim(market_2020a)
## [1] 618 3
ggplot(market_2020a, aes(x=Date, y=value, colour = variable, group = variable)) +
geom_line() +
labs(title="2020 Performance Comparison ",
subtitle = "\nExxon Mobil\nBritish Petroleum\nSchlumberger",
y= "Index 2020=1", x = "",
color="Companies", title.vjust=1) +
theme_economist() +
scale_color_economist() +
theme(legend.position = c(1,1),
legend.justification=c(1,1),
legend.direction="horizontal",
plot.title = element_text(vjust=1),
legend.title=element_text(vjust=1),
legend.title.align=0)
