Page 1

Row

Twitter

Microsoft

Apple

Row

Adjusted Closing Price - 3 Years

Adjusted Closing Price - 1 Year

Adjusted Closing Price - 6 Months

Adjusted Closing Price - 1 Month

---
title: "512 Lab1 Dashboard"
anthor: Xiaopeng Ruan / Tianyi Ma
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: menu
    source_code: embed
---

# Intro text {.sidebar}

##Stock Analysis
This dashboard analyses stocks of Twitter, Microsoft and Apple for Future Investment Purpose.After considering the Candlestick charts and Adjusted Closing Prices for these 3 stocks, we have observed good performance and strong growth in the TWTR stock recently. Therefore, we believe an investment in Twitter could make maximum short term profits for the our organization.

# Page 1

```{r setup, include=FALSE}
library(flexdashboard)
library(pdfetch)
library(dygraphs)
library(xts)
identifiers <- c("TWTR", "MSFT", "AAPL")
```

Row {data-height=650}
-----------------------------------------------------------------------

### Twitter 

```{r}
oneMonthTWTR <- pdfetch_YAHOO("TWTR", fields = c("open", "high", "low", "close"), from = as.Date("2017-08-01"),interval = "1d")
colnames(oneMonthTWTR)=c("Open","High","Low","Close")
data(oneMonthTWTR)
m <- tail(oneMonthTWTR, n = 24)
dygraph(m) %>%
dyCandlestick()
```

### Microsoft

```{r}
oneMonthMSFT <- pdfetch_YAHOO("MSFT", fields = c("open", "high", "low", "close"), from = as.Date("2017-08-01"),interval = "1d")
colnames(oneMonthMSFT)=c("Open","High","Low","Close")
data(oneMonthMSFT)
m <- tail(oneMonthMSFT, n = 24)
dygraph(m) %>%
dyCandlestick()
```

### Apple

```{r}
oneMonthAAPL <- pdfetch_YAHOO("AAPL", fields = c("open", "high", "low", "close"), from = as.Date("2017-08-01"),interval = "1d")
colnames(oneMonthAAPL)=c("Open","High","Low","Close")
data(oneMonthAAPL)
m <- tail(oneMonthAAPL, n = 24)
dygraph(m) %>%
dyCandlestick()
```


Row {.tabset}
-----------------------------------------------------------------------

### Adjusted Closing Price - 3 Years

```{r}
financialData <- pdfetch_YAHOO(identifiers, fields = c("open", "high", "low", "close","volume","adjclose"), from = as.Date("2015-07-01"), to = as.Date("2018-07-01"),interval = "1mo")

fiveYAdjClose <- cbind(financialData$TWTR.volume,financialData$MSFT.volume, financialData$AAPL.volume)
colnames(fiveYAdjClose) <-c("TWTR","MSFT","AAPL")
#plot
dygraph(fiveYAdjClose) %>%
dyOptions(strokeWidth = 2,colors = RColorBrewer::brewer.pal(3, "Dark2"))%>%
dyHighlight(highlightCircleSize = 3, 
              highlightSeriesBackgroundAlpha = 0.2,
              hideOnMouseOut = TRUE)%>%
dyLegend(width = 400)
```


### Adjusted Closing Price - 1 Year

```{r}
financialData <- pdfetch_YAHOO(identifiers, fields = c("open", "high", "low", "close","volume","adjclose"), from = as.Date("2016-07-01"), to = as.Date("2018-07-01"),interval = "1mo")

fiveYAdjClose <- cbind(financialData$TWTR.volume,financialData$MSFT.volume, financialData$AAPL.volume)
colnames(fiveYAdjClose) <-c("TWTR","MSFT","AAPL")
#plot
dygraph(fiveYAdjClose) %>%
dyOptions(strokeWidth = 2,colors = RColorBrewer::brewer.pal(3, "Dark2"))%>%
dyHighlight(highlightCircleSize = 3, 
              highlightSeriesBackgroundAlpha = 0.2,
              hideOnMouseOut = TRUE)%>%
dyLegend(width = 400)
```

### Adjusted Closing Price - 6 Months

```{r}
financialData6m <- pdfetch_YAHOO(identifiers, fields = c("open", "high", "low", "close","volume","adjclose"), from = as.Date("2018-01-01"), to = as.Date("2018-07-01"),interval = "1d")
sixMonthAdjClose <- cbind(financialData6m$TWTR.volume,financialData6m$MSFT.volume, financialData6m$AAPL.volume)
colnames(sixMonthAdjClose) <-c("TWTR","MSFT","AAPL")
#plot
dygraph(sixMonthAdjClose) %>%
dyOptions(strokeWidth = 2,colors = RColorBrewer::brewer.pal(3, "Dark2"))%>%
dyHighlight(highlightCircleSize = 3, 
              highlightSeriesBackgroundAlpha = 0.2,
              hideOnMouseOut = TRUE)%>%
dyLegend(width = 400)
```


### Adjusted Closing Price - 1 Month

```{r}
financialData1m <- pdfetch_YAHOO(identifiers, fields = c("open", "high", "low", "close","volume","adjclose"), from = as.Date("2018-06-01"),interval = "1d")
oneMonthAdjClose <- cbind(financialData1m$TWTR.volume,financialData1m$MSFT.volume, financialData1m$AAPL.volume)
colnames(oneMonthAdjClose) <-c("TWTR","MSFT","AAPL")
#plot
dygraph(oneMonthAdjClose) %>%
dyOptions(strokeWidth = 2,colors = RColorBrewer::brewer.pal(3, "Dark2"))%>%
dyHighlight(highlightCircleSize = 3, 
              highlightSeriesBackgroundAlpha = 0.3,
              hideOnMouseOut = TRUE)%>%
dyLegend(width = 400)
```