Daily Close Price

Annual Returns

Monthly stock prices

Montly Traded Quantity

---
title: 'ANLY 512: Data Visualization'
subtitle: "Dashboard Laboratory"
author: "Shyam Kumar Voleti ,  Nikhil Dandapanthula"
date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
#Load the packages
library(Quandl)
library(dygraphs)
library(quantmod)
library(quantmod)
library(tidyverse)
library(ggplot2)
library(plyr)

## API KEY 

Quandl.api_key("H57zuvJ79nvbf1Z9_R7j")

## Download the data Set
TWTR <-  Quandl("WIKI/TWTR", start_date = "2015-06-01", collapse="daily",type="raw")
MSFT <-  Quandl("WIKI/MSFT", start_date = "2015-06-01", collapse="daily",type="raw")
AAPL <-  Quandl("WIKI/AAPL", start_date = "2015-06-01", collapse="daily",type="raw")

## Add  "Stock" coloumn 
TWTR<-cbind(TWTR,Stock="")
MSFT<-cbind(MSFT,Stock="")
AAPL<-cbind(AAPL,Stock="")


## Paste the stock name

TWTR$Stock<-paste(TWTR$Stock,"TWTR",sep="")
MSFT$Stock<-paste(MSFT$Stock,"MSFT",sep="")
AAPL$Stock<-paste(AAPL$Stock,"AAPL",sep="")

## Consolidate under one dataset

Master_Data <-rbind(TWTR,MSFT,AAPL)

## Convert the dates into character
Master_Data$Date<-as.character(Master_Data$Date)

## Split the date/create a list for the same

list<-strsplit(Master_Data$Date,"-")

## Convert the list into dataframe
library(plyr)
Master_Date1<-ldply(list)
colnames(Master_Date1)<-c("Year","Month","Day")

## Column bind with the main dataframe
Master_Data<-cbind(Master_Data,Master_Date1)
names(Master_Data)

## Change the scale of quantity

Master_Data$Volume<-Master_Data$Volume/1000000

## Convert the Date to as.Date()

Master_Data$Date<-as.Date(Master_Data$Date)
```



### Daily Close Price

```{r}


Master_Data<-Master_Data%>%
  tibble::as.tibble()%>%
  group_by(Stock)

Master_Data %>%
  ggplot(aes(x = Date, y = Close, color = Stock)) +
  geom_point() +
  labs( x = "",y="Close Price($)") +
  theme_bw() +
  theme(legend.position="none")
```


### Annual Returns

```{r}
library(tidyquant)
ticker <- tibble(stock = c("AAPL","TWTR","MSFT"))
stockdata <- ticker%>%
  tq_get(get = "stock.prices", from = "2015-06-01")
order.by=as.POSIXct(stockdata$date)

stck <- as.tbl(stockdata)
stck$date <- as.Date(stck$date)
stockRtrnYr <- stck %>% group_by(stock) %>% tq_transmute(mutate_fun = periodReturn, period = "yearly", col_rename = "AnnualReturns")

stockRtrnYr %>%
  ggplot(aes(x = date, y = AnnualReturns, fill = stock)) +
  geom_bar(position = "dodge", stat = "identity") +
  labs(y = "Returns", x = "", color = "") +
  theme_bw() 
```


### Monthly stock prices

```{r}
library(ggplot2) 
  ggplot(Master_Data,aes(factor(Stock),Close,color=Stock,frame=Month)) +
  geom_point(aes(size = Close, colour=Stock)) +
  ylim(0,300)+
  xlab("") +
  ylab("Close Price($)") +
  theme_bw() +
  theme(legend.position="none")
```


### Montly Traded Quantity 

```{r}
library(ggplot2)
Master_Data %>%
  ggplot(aes(x = Volume, y = Close, color = Stock,frame=Month)) +
  geom_smooth() +
  xlim(0,40)+
  labs(x = "Traded Quantity (Million)",y="Close Price($)") +
  facet_wrap(~ Stock, ncol = 3) +
  theme_bw() +
  theme(legend.position="none")
```