---
title: 'ANLY 512: Data Visualization'
author: "Kumar Rohan"
date: '`r Sys.Date()`'
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
---
```{r setup, include=FALSE}
pckgs<-c("Quandl","Sweep","tidyverse","tidyquant","ggplot", "ggthemes", "flexdashboard","forcats","stringr","magrittr")
install.packages(pckgs,repos = "http://cran.us.r-project.org")
library(magrittr)
library(plyr)
library("flexdashboard")
library("ggplot2")
library("ggthemes")
library(dplyr)
library(tidyverse)
library(tidyquant)
start <- as.Date("2018-06-01")
end <- as.Date("2018-09-30")
getSymbols(c("CSCO","DIS", "NEE", "KNX"), src = "yahoo", from = start, to = end)
#Creating an xts object which contains the price of the four companies stocks.
companystocks <- as.xts(data.frame(CSCO = CSCO[, "CSCO.Close"], DIS = DIS[, "DIS.Close"],
NEE = NEE[, "NEE.Close"], KNX = KNX[, "KNX.Close"] ))
stock_return = apply(companystocks, 1, function(x) {x / companystocks[1,]}) %>%
t %>% as.xts
head(stock_return)
start = as.Date("2016-01-01")
getSymbols(c("CSCO","DIS", "NEE", "KNX"), src = "yahoo", from = start, to = end)
what_metrics <- yahooQF(c("Price/Sales",
"P/E Ratio",
"Price/EPS Estimate Next Year",
"PEG Ratio",
"Dividend Yield",
"Market Capitalization"))
tickers <- c( "CSCO", "DIS", "NEE", "KNX")
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)
metrics <- data.frame(Symbol=tickers, metrics[,2:length(metrics)])
colnames(metrics) <- c("Symbol", "P-E Ratio", "Price EPS Estimate Next Year", "Div Yield", "Market Cap")
```
Stock Technical Analysis
=======================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
### Stock Analysis
This dashboard show four Stock Price analysis which comprise of Cisco Systems Inc. (CSCO), Walt Disney Co. (DIS), NextEra Energy Inc. (NEE), Knight-Swift Transportation Holdings Inc. and (KNX) for short trem Investment Purpose.
-First Column plot shows the stock's price trends for the past six months. Give some idea about the stock's price in the upcoming months.
-Second Column plot shows stock return comparison between the four stocks. CISCO and Disney Inc. show an upward trend in stock return. Positive slope for both stocks' return in montn of Sep. and Oct. indicate good return for the short term.
-Second Page demonstrate Plot for price/volume and 20, 50 and 200 days moving average of all the four stocks. Stocks price crossing of its moving average price indicate a trend in the price movement of stock. Cisco, DIS and NEE show an overall bullish trend.
Row {data-height=600}
-------------------------------------------------------------------------
### Stock Price trend for the past Six months
```{r}
plot(as.zoo(companystocks), screens = 1, lty = 1:3,lwd = 3, col = c("red","blue","green", "black"), xlab = "Date", ylab = "Price")
legend("right", c("CSCO","DIS", "NEE", "KNX"), lty = 1:3,lwd=3, col = c("red","blue","green","black"), cex = 0.75)
```
---------------------------------------------------------------------------------
### Stocks Return Comparison
```{r}
plot(as.zoo(stock_return), screens = 1, lty = 1:3,lwd = 3, col = c("red","blue","green", "black"),xlab = "Date", ylab = "Return")
legend("topleft", c("CSCO","DIS", "NEE", "KNX"), lty = 1:3,lwd = 3, col = c("red","blue","green","black"),cex = .75)
```
Stock Technical Analysis contd.- Moving Average
=======================================================================
Row {.tabset .tabset-fade}
--------------------------------------------------------------------------------------
### CISCO Stock Moving Average
```{r}
candleChart(CSCO, up.col = "black", dn.col = "red", theme = "white")
addSMA(n = c(20, 50, 200))
```
-------------------------------------------------------------------
### DIS Stock Moving Avg.
```{r}
candleChart(DIS, up.col = "black", dn.col = "red", theme = "white")
addSMA(n = c(20, 50, 200))
```
### NEE Stock Moving Avg.
```{r}
candleChart(NEE, up.col = "black", dn.col = "red", theme = "white")
addSMA(n = c(20, 50, 200))
```
### KNX Stock Moving Avg.
```{r}
candleChart(KNX, up.col = "black", dn.col = "red", theme = "white")
addSMA(n = c(20, 50, 200))
```
Stock Fundamental Analysis
=======================================================================
Sidebar {.sidebar}
-------------------------------------------------------------------
### Fundamental Analysis of stocks
-CISCO and DIS have high market cap and good P-E ratio. Both stocks are good for short term investment because of large market cap and bullish trend in their price.
-From Price perspective, I will go with CISCO as it has low stock price compare to Disney.
Row {data-height=700}
-----------------------------------------------------------------------
### Funamental Analysis of CISCO, DIS, NEE and KNX Stocks
```{r}
DT::datatable(metrics)
```