Historical Stock Prices

##Row

Bank of America

J P Morgan Chase

Capital One


Wells Fargo

## row

Volumes

Table

 [1] "stock.prices"        "stock.prices.google" "stock.prices.japan" 
 [4] "financials"          "key.ratios"          "dividends"          
 [7] "splits"              "economic.data"       "exchange.rates"     
[10] "metal.prices"        "quandl"              "quandl.datatable"   
[13] "alphavantager"       "rblpapi"            
---
title: "Lab1 - Dashboarding"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dygraphs)
library(tidyverse)
library(tidyquant)
library(xts)
library(pdfetch)
library(knitr)

```

# Historical Stock Prices {data-icon="fa-list"}

##Row {.tabset}
-------------------------------------------
### Bank of America {data-width=150}

```{r}

invisible(getSymbols("BAC", src = "yahoo", from = "2018-10-01", to = "2019-01-01"))
#BOFA <- tq_get("BAC", get="stock.prices",from = "2018-10-01", to = "2019-01-01")
BOFA <- BAC[,-5]

dygraph(BOFA, main = "Bank of America Stats") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Historical Prices") %>%
  dyHighlight(highlightCircleSize = 2,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) 

```


### J P Morgan Chase {data-width=150}

```{r}

invisible(getSymbols("JPM", src = "yahoo", from = "2018-10-01", to = "2019-01-01"))
#JPMC <- tq_get("JPM", get="stock.prices",from = "2018-10-01", to = "2019-01-01")
JPMC <- JPM[,-5]

dygraph(JPMC, main = "JP Morgan Chase Bank Stats") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Historical Prices") %>%
  dyHighlight(highlightCircleSize = 2,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) 

```

### Capital One

```{r}
invisible(getSymbols("COF", src = "yahoo", from = "2018-10-01", to = "2019-01-01"))
#Capital1 <- tq_get("COF", get="stock.prices",from = "2018-10-01", to = "2019-01-01")
Capital1 <- COF[,-5]

dygraph(Capital1, main = "Capital One Stats") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Historical Prices") %>%
  dyHighlight(highlightCircleSize = 2,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) 

```


----------------------------------------------------------------
### Wells Fargo


```{r}

invisible(getSymbols("WFC", src = "yahoo", from = "2018-10-01", to = "2019-01-01"))
#WF<- tq_get("WFC", get="stock.prices",from = "2018-10-01", to = "2019-01-01")
WF <- WFC[,-5]

dygraph(WF, main = "Wells Fargo Stats") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Historical Prices") %>%
  dyHighlight(highlightCircleSize = 2,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) 
```


## row {data-height=350}
--------------------------------------------------
### Volumes
```{r}
#Volumes for each COMPANY
ticker <- c("BAC","JPM","COF", "WFC")

financialData <- pdfetch_YAHOO(ticker, fields = c("open", "high", "low", "close","volume","adjclose"), from = as.Date("2013-12-01"), to = as.Date("2017-09-01"),interval = "1mo")

Volume.Big4 <- cbind(financialData$BAC.volume,financialData$JPM.volume, financialData$COF.volume, financialData$WFC.volume)

colnames(Volume.Big4) <-c("BAC","JPM","COF", " WFC")

dygraph(Volume.Big4, main="Volumes") %>%
    dyAxis("y", label="Volume") %>%
  dyOptions(stepPlot = TRUE) %>%
  #dyOptions(axisLineWidth = 2.0,  colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightSeriesBackgroundAlpha = 1,
              highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyRangeSelector()

```

### Table
```{r}
what_metrics <- yahooQF(c("Price/Sales", 
                          "P/E Ratio"
                          ,"Previous Close","52-week Low", "52-week High",
                          "Market Capitalization"))

metrics <- getQuote(paste(ticker, sep="", collapse=";"), what=what_metrics)
view(metrics)

#Add tickers as the first column and remove the first column which had date stamps
metrics <- data.frame(Symbol=ticker, metrics[,2:length(metrics)]) 

#Change colnames
colnames(metrics) <- c("Symbol", "P.E.Ratio", "Previous Close", "52Week Low", "52Week High", "Mrket Cap")

#install.packages("DT")
#library(DT)
DT::datatable(metrics)

tq_get_options()


```