library(flexdashboard)
 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.
 library(dygraphs)
 library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
 library(RColorBrewer)
 library(plotly)
## Loading required package: ggplot2
## 
## 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

Closing Price comparison. We have taken random three firms for Yahoo finance.

tickers<-c("INFY","TCS","BLMT")
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] "INFY" "TCS"  "BLMT"
closePrice<-do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateWindow<-c("2015-01-01", "2018-01-01")
dygraph(closePrice, main="Value", group="Stock") %>%
  dyRebase(value=100) %>%
  dyAxis("y", label="Close Price(USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(3, "Set1")) %>%
  dyRangeSelector(dateWindow = dateWindow)
closePrice<-do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateWindow<-c("2015-01-01", "2018-01-01")
dygraph(closePrice, main="Value", group="Stock") %>%
  dyRebase(percent = TRUE) %>%
  dyAxis("y", label="Close Price(USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(3, "Set1")) %>%
  dyRangeSelector(dateWindow = dateWindow)

This graph helps us in giving information about the trend of the company for last three years. This is usualy done when the day traders are in action. This helps in short sell and going long.

closePrice<-do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateWindow<-c("2015-01-01", "2018-01-01")
dygraph(closePrice, main="Value", group="Stock") %>%
  dyRebase(percent = TRUE) %>%
  dyAxis("y", label="Close Price(USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(3, "Set1")) %>%
  dyRangeSelector(dateWindow = dateWindow)

These ratio helps us to understand how the stocks are doing. The return on single dollar investment. It helps us understand the resistance of the stock.

plot(INFY$INFY.Close)

plot(TCS$TCS.Close)

plot(BLMT$BLMT.Close)

## If you see the Close for three companies you can see that BLMT has done much better in the long term as compared to Infy and TCS.

Below graphs helps us to understand the resistance on the stocks. Which helps the investors in giving an idea and how much risk he can take on this particular stock

INFYD <- data.frame(Date=index(INFY),coredata(INFY))

INFYD %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~INFY.Open, close = ~INFY.Close,
          high = ~INFY.High, low = ~INFY.Low) %>%
  layout(title = "INFY High Low Close Graph")
TCSD <- data.frame(Date=index(TCS),coredata(TCS))

TCSD %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~TCS.Open, close = ~TCS.Close,
          high = ~TCS.High, low = ~TCS.Low) %>%
  layout(title = "TCS High Low Close Graph")
BLMTD <- data.frame(Date=index(BLMT),coredata(BLMT))

BLMTD %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~BLMT.Open, close = ~BLMT.Close,
          high = ~BLMT.High, low = ~BLMT.Low) %>%
  layout(title = "BLMT High Low Close Graph")