R Markdown

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:

library(flexdashboard)
## Warning: package 'flexdashboard' was built under R version 3.3.3
library(quantmod)
## Warning: package 'quantmod' was built under R version 3.3.3
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.3.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.3.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.3.3
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(dygraphs)
## Warning: package 'dygraphs' was built under R version 3.3.3
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.3.3
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(RColorBrewer)
library(plotly)
## Warning: package 'plotly' was built under R version 3.3.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Including Plots

You can also embed plots, for example:

# The three companies are Apple Inc., Alphabet Inc., Facebook Inc.
tickers <- c("AAPL","GOOGL","FB")
getSymbols(tickers)
## '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: There have been significant changes to Yahoo Finance data.
## Please see the Warning section of '?getSymbols.yahoo' for details.
## 
## This message is shown once per session and may be disabled by setting
## options("getSymbols.yahoo.warning"=FALSE).
## [1] "AAPL"  "GOOGL" "FB"
# The trendline obtained from closing prices of these three companies will help understand the financial health in the last four years. 
# Of these three companies, Facebook is the best performing over the past 4 years while Apple saw its first bump in the stock market during first quarter of 2016. It happened because of decrease in Iphone sales during that time. Google is steadily growing over the years. 
closing_price <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))
window <- c("2014-01-01", "2018-01-01")
dygraph(closing_price, main="Value", group="Stock") %>%
  dyRebase(value=100) %>%
  dyAxis("y", label="Closing_Price(USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(3, "Set1")) %>%
  dyRangeSelector(dateWindow = window)
# Resistance of the stocks 
# This plots helps us understand the point at which the upward movement of stocks prices is impeded.

AAPL <- data.frame(Date=index(AAPL),coredata(AAPL))
AAPL %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~AAPL.Open, close = ~AAPL.Close,
          high = ~AAPL.High, low = ~AAPL.Low) %>%
  layout(title = "AAPL STOCK RESISTANCE PLOT")
GOOGL <- data.frame(Date=index(GOOGL),coredata(GOOGL))
GOOGL %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~GOOGL.Open, close = ~GOOGL.Close,
          high = ~GOOGL.High, low = ~GOOGL.Low) %>%
  layout(title = "GOOGLE STOCK RESISTANCE PLOT")
FB <- data.frame(Date=index(FB),coredata(FB))
FB %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~FB.Open, close = ~FB.Close,
          high = ~FB.High, low = ~FB.Low) %>%
  layout(title = "FACEBOOK STOCK RESISTANCE PLOT")
# In all these three companies the resistance to stocks is almost negligible since these tech companies are market leaders in their domain.

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.