Stock Trend

Microsoft

TWTR

Apple

Stock Closing Price


Stock Closing Prices

Interactive

Stock Volume

MSFT

TWTR

AAPL

Stock Monthly Returns

Miscrosoft

Apple

Twitter

Stock Dividens

Apple

Miscrosoft

Twitter

Twitter doesn’t apply this

---
title: "Stock Dashboard-ANLY 512 Lab"
Date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    source_code: embed
    vertical_layout: scroll
    orientation: columns
---

```{r setup, include=FALSE}
library(dygraphs)
library(quantmod)
library(flexdashboard)
library(tidyquant)
library(knitr)
library(ggplot2)
library(ggthemes)
library(ggplot2)
library(xts)

getSymbols(c("MSFT", "TWTR", "AAPL"), from = "2018-01-01", auto.assign=TRUE)
```

Stock Trend {data-orientation=columns}
=====================================     
   

### Microsoft

```{r}
dygraph(MSFT[,2:4], group = "stocks") %>% 
  dySeries(c("MSFT.Low", "MSFT.Close", "MSFT.High"), label = "MSFT")
```


### TWTR

```{r}
dygraph(TWTR[,2:4], group = "stocks") %>% 
  dySeries(c("TWTR.Low", "TWTR.Close", "TWTR.High"), label = "TWTR")
```


### Apple

```{r}
dygraph(AAPL[,2:4], group = "stocks") %>% 
  dySeries(c("AAPL.Low", "AAPL.Close", "AAPL.High"), label = "AAPL")
```


Stock Closing Price {data-orientation=columns}
=====================================     
   
-------------------------------------
```{r message = FALSE}
symbols <- c("MSFT", "TWTR", "AAPL")
data <- tq_get(symbols)

invisible(data %>% 
  select(symbol, date, close) %>% 
  spread(key = symbol, value = close))

data$day <- weekdays(as.Date(data$date,'%Y-%m-%d'))
data$weekNum <- strftime(data$date, format = "%V")
library("lubridate")
data$month <- month(as.POSIXlt(data$date, format="%Y/%m/%d"))
data$difference = data$close - data$open
```

```{r message = FALSE}
library(ggplot2)
library(xts)
```

```{r message = FALSE}
msft = data[data$symbol == "MSFT",]
twtr = data[data$symbol == "TWTR",]
aapl = data[data$symbol == "AAPL",]
```


### Stock Closing Prices

```{r}
ggplot(msft,aes(date,close)) + 
  geom_line(aes(color="msft")) +
  geom_line(data=twtr,aes(color="twtr")) +
  geom_line(data=aapl,aes(color="aapl")) +
  labs(color="Legend") +
  scale_colour_manual("", breaks = c("msft","twtr","aapl"),
                      values = c("blue", "yellow","red")) +
  ggtitle("MSFT, TWTR & AAPL") + 
  theme(plot.title = element_text(lineheight=1.7, face="bold"))
```

```{r message = FALSE}
msft_xts <- xts(msft$close,order.by=msft$date,frequency=365)
twtr_xts <- xts(twtr$close,order.by=twtr$date,frequency=365)
aapl_xts <- xts(aapl$close,order.by=aapl$date,frequency=365)

stocks <- cbind(msft_xts,twtr_xts,aapl_xts)
```


### Interactive

```{r}
library(dygraphs)
dygraph(stocks,ylab="Close", 
        main="Closing Stock Prices") %>%
  dySeries("..1",label="MSFT") %>%
  dySeries("..2",label="TWTR") %>%
  dySeries("..3",label="AAPL") %>%
  dyOptions(colors = c("blue", "yellow","red")) %>%
  dyRangeSelector()
```

```{r message = FALSE}
start <- as.Date("2018-01-01")
end <- as.Date("2018-06-30")
```


Stock Volume {data-orientation=columns}
=====================================     
   
   
### MSFT

```{r}
invisible(getSymbols("MSFT", src = "yahoo", from = start, to = end))
candleChart(MSFT, up.col = "blue", dn.col = "green", theme = "white")
```   
 
### TWTR
    
```{r}
invisible(getSymbols("TWTR", src = "yahoo", from = start, to = end))
candleChart(TWTR, up.col = "yellow", dn.col = "red", theme = "white")
```

### AAPL

```{r}
invisible(getSymbols("AAPL", src = "yahoo", from = start, to = end))
candleChart(AAPL, up.col = "purple", dn.col = "orange", theme = "white")
```

Stock Monthly Returns {data-orientation=columns}
=====================================    


### Miscrosoft
```{r message = FALSE}
ggplot(data=monthlyReturn(Cl(MSFT)),aes(Index,monthly.returns))+geom_line()
```

### Apple
```{r messgage= FALSE}
ggplot(data=monthlyReturn(Cl(AAPL)),aes(Index,monthly.returns))+geom_line()
```

### Twitter
```{r message= FALSE}
ggplot(data=monthlyReturn(Cl(TWTR)),aes(Index,monthly.returns))+geom_line()
```

Stock Dividens {data-orientation=columns}
=====================================     

### Apple  
```{r message = FALSE}
AAPL.Div <- getDividends("AAPL", from = "2000-01-01", auto.assign=FALSE)
ggplot(data=AAPL.Div,aes(Index, AAPL.Div))+geom_line()
```

### Miscrosoft
```{r message = FALSE}
MSFT.Div <- getDividends("MSFT", from = "2000-01-01",auto.assign=FALSE)
ggplot(data=MSFT.Div,aes(Index, MSFT.Div))+geom_line()
```

### Twitter
Twitter doesn't apply this