Row

Stocks prices of each company

Quarterly dividends paid by each company

Row

Comparison: Share Price

Comparison: Dividends Paid

Comparison: Adj. Stock Prices

---
title: "Dashboard: Comparison of risks and benefits at Apple, Microsoft and jnj for the purpose of futuristic investment"

knit: (function(inputFile, encoding) {
  rmarkdown::render(inputFile, encoding = encoding, output_dir = "/Volumes/PNY 16 GB/HU Coursework/ANLY 512/Exe Class 02_081917/Dashboarding") })

output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
runtime: shiny
---

 


```{r setup, include=FALSE}
require(knitr)
opts_knit$set(root.dir='/Volumes/PNY 16 GB/HU Coursework/ANLY 512/Exe Class 02_081917/Dashboarding')

library(flexdashboard)
library(tidyquant)
library(quantmod)
library(DT)
```



```{r global, include=FALSE}
getSymbols(c('AAPL', 'MSFT', 'GOOG', "AMZN", "JNJ"), from = '2016-09-26', src = "yahoo")
```

```{r, include=F}
head(AAPL)
head(MSFT)
head(JNJ)
```

```{r, include = F}
library(xts)
library(dygraphs)
```

Column {.sidebar data-width=650 data-padding=10}
-------------------------------------


```{r, fig.height= 2.8, echo=FALSE}
par(mfrow=c(3,1))

apl_cs <- dygraph(AAPL[,1:4], main = "Stock Prices at Open, Close; High and Low: Apple (AAPL)") %>%
  dyCandlestick() %>%
  dyRangeSelector()
apl_cs

msft_cs <- dygraph(MSFT[,1:4], main = "Stock Prices at Open, Close; High and Low: Microsoft(MSFT)") %>%
  dyCandlestick() %>%
  dyRangeSelector()
msft_cs

jnj_cs <- dygraph(JNJ[,1:4], main = "Stock Prices at Open, Close; High and Low: Johnson & Johnson (JNJ)") %>%
  dyCandlestick() %>%
  dyRangeSelector()
jnj_cs
```

Row {data-height=450}
-------------------------------------
### Stocks prices of each company
```{r, echo=FALSE}
stocks <- cbind(AAPL[,2:4], MSFT[,2:4], JNJ[,2:4])
datatable(stocks, options = list(pageLength = 25))
```

### Quarterly dividends paid by each company
```{r, include=FALSE}
apl.div <- getDividends("AAPL", from ="2007-09-26")
msft.div <- getDividends("MSFT", from = "2007-09-26")
jnj.div <- getDividends("JNJ", from = "2007-09-26")

apl.div <- rownames_to_column(as.data.frame(apl.div), var = "date")
head(apl.div)
apl.div$date <- format(as.Date(apl.div$date), "%b-%Y")


msft.div <- rownames_to_column(as.data.frame(msft.div), var = "date")
head(msft.div)
msft.div$date <- format(as.Date(msft.div$date), "%b-%Y")


jnj.div <- rownames_to_column(as.data.frame(jnj.div), var = "date")
head(jnj.div)
jnj.div$date <- format(as.Date(jnj.div$date), "%b-%Y")


df1 <- merge(apl.div, jnj.div)
df1

div.all <- merge(df1, msft.div)
div.all

rownames(div.all) <- div.all$date
head(div.all)

div.all2 <- div.all
div.all2$date <- as.Date(rownames(div.all2),format = "%m/%Y")
head(div.all2)
div.all2
div.all2 <- as.data.frame(div.all2[,-1])
div.all2
```   



```{r, echo=FALSE}
datatable(div.all2, options = list(pageLength = 25))
```


Row {.tabset .tabset-fade data-height=550}
-------------------------------------
### Comparison: Share Price 
```{r, fig.height=5, fig.width=18 ,echo=FALSE}
dygraph(stocks, main = "Apple, Microsoft and JnJ Share Prices") %>%
  dySeries(c("AAPL.Low", "AAPL.Close", "AAPL.High"), label = "AAPL") %>%
  dySeries(c("MSFT.Low", "MSFT.Close", "MSFT.High"), label = "MSFT") %>%
  dySeries(c("JNJ.Low", "JNJ.Close", "JNJ.High"), label = "JNJ")
```

### Comparison: Dividends Paid
```{r, include=FALSE}
apl.div <- getDividends("AAPL", from ="2007-09-26")
msft.div <- getDividends("MSFT", from = "2007-09-26")
jnj.div <- getDividends("JNJ", from = "2007-09-26")

all.div <- cbind(apl.div, msft.div, jnj.div)
```

```{r, echo=FALSE}
dyMultiColumn <- function(dygraph) {
 dyPlotter(dygraph = dygraph, 
            name = "MultiColumn", 
            path = system.file("plotters/multicolumn.js", package = "dygraphs"))
}

dygraph(all.div, main = "Comparison of Dividends Paid") %>%
  dyRangeSelector() %>%
  dyMultiColumn()
```


### Comparison: Adj. Stock Prices
```{r, include=FALSE}
apl.adj <- as.data.frame(AAPL)
head(apl.adj)
apl.adj<- as.data.frame(apl.adj$AAPL.Adjusted, row.names = rownames(apl.adj))
head(apl.adj)
apl.adj <- as.xts(apl.adj)
head(apl.adj)

msft.adj <- as.data.frame(MSFT)
msft.adj <- as.data.frame(msft.adj$MSFT.Adjusted, row.names = rownames(msft.adj))
msft.adj <- as.xts(msft.adj)

jnj.adj <- as.data.frame(JNJ)
jnj.adj <- as.data.frame(jnj.adj$JNJ.Adjusted, row.names = rownames(jnj.adj))
jnj.adj <- as.xts(jnj.adj)

all.adj <- cbind(apl.adj, msft.adj, jnj.adj)
head(all.adj)
```

```{r, echo=FALSE}
dygraph(all.adj, main = "Comparison of Adjusted Stock Price") %>%
  dyRangeSelector() %>%
  dyMultiColumn()
```