Column

Apple

Microsoft

NASDAQ

Row

ROI over Past 10 years

ROI over Past 5 years

ROI over Past 3 years

ROI over Past 1 years

Row

Apple

Microsoft

NASDAQ

---
title: "ANLY 512-91 Lab 1"
author: "Gayathri Mutyala"
date: "7/2/2019"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source_code: embed
---

```{r, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

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

```{r,echo=FALSE, results = 'hide'}

today <- Sys.Date()
symbols <- c("AAPL", "MSFT", "^IXIC")
getSymbols(symbols, get = "stock.prices",from="2000-01-01")

AAPL_adj <- AAPL$AAPL.Adjusted
IXIC_adj <- IXIC$IXIC.Adjusted
MSFT_adj <- MSFT$MSFT.Adjusted

```

Column {.tabset data-width=500}
-----------------------------------------------------------------------

### Apple

```{r echo=FALSE}


#all_trend <- cbind(AAPL_adj, MSFT_adj, IXIC_adj)

AAPL_adj %>% dygraph(main="Historical Price of Apple") %>% dyRangeSelector()
```


### Microsoft

```{r echo=FALSE}

MSFT_adj %>% dygraph(main="Historical Price of Microsoft") %>% dyRangeSelector()
```

### NASDAQ

```{r echo=FALSE}
IXIC_adj %>% dygraph(main="Historical NASDAQ Index") %>% dyRangeSelector()
```


Row {.tabset data-width=500}
-----------------------------------------------------------------------

### ROI over Past 10 years

```{r echo=FALSE}
all_price <- cbind(AAPL_adj,MSFT_adj,IXIC_adj)
yr10 <- as.POSIXlt(as.Date(today))
yr10$year <- yr10$year - 10
yr10 <- as.Date(yr10)
all_price_yr10 <- all_price[which(date(all_price)>=yr10)]
roi10 <- all_price_yr10
roi10$AAPL.Adjusted <- roi10$AAPL.Adjusted / as.numeric(roi10$AAPL.Adjusted[1])
roi10$MSFT.Adjusted <- roi10$MSFT.Adjusted / as.numeric(roi10$MSFT.Adjusted[1])
roi10$IXIC.Adjusted <- roi10$IXIC.Adjusted / as.numeric(roi10$IXIC.Adjusted[1])
roi10 <- roi10*100
roi10 %>% dygraph(main="ROI Over Past 10 Years")

```

### ROI over Past 5 years

```{r echo=FALSE}

yr5 <- as.POSIXlt(as.Date(today))
yr5$year <- yr5$year - 5
yr5 <- as.Date(yr5)
all_price_yr5 <- all_price[which(date(all_price)>=yr5)]
roi5 <- all_price_yr5
roi5$AAPL.Adjusted <- roi5$AAPL.Adjusted / as.numeric(roi5$AAPL.Adjusted[1])
roi5$MSFT.Adjusted <- roi5$MSFT.Adjusted / as.numeric(roi5$MSFT.Adjusted[1])
roi5$IXIC.Adjusted <- roi5$IXIC.Adjusted / as.numeric(roi5$IXIC.Adjusted[1])
roi5 <- roi5*100
roi5 %>% dygraph(main="ROI Over Past 5 Years")

```


### ROI over Past 3 years

```{r echo=FALSE}

yr3 <- as.POSIXlt(as.Date(today))
yr3$year <- yr3$year - 3
yr3 <- as.Date(yr3)
all_price_yr3 <- all_price[which(date(all_price)>=yr3)]
roi3 <- all_price_yr3
roi3$AAPL.Adjusted <- roi3$AAPL.Adjusted / as.numeric(roi3$AAPL.Adjusted[1])
roi3$MSFT.Adjusted <- roi3$MSFT.Adjusted / as.numeric(roi3$MSFT.Adjusted[1])
roi3$IXIC.Adjusted <- roi3$IXIC.Adjusted / as.numeric(roi3$IXIC.Adjusted[1])
roi3 <- roi3*100
roi3 %>% dygraph(main="ROI Over Past 3 Years")

```

### ROI over Past 1 years

```{r echo=FALSE}

yr1 <- as.POSIXlt(as.Date(today))
yr1$year <- yr1$year - 1
yr1 <- as.Date(yr1)
all_price_yr1 <- all_price[which(date(all_price)>=yr1)]
roi1 <- all_price_yr1
roi1$AAPL.Adjusted <- roi1$AAPL.Adjusted / as.numeric(roi1$AAPL.Adjusted[1])
roi1$MSFT.Adjusted <- roi1$MSFT.Adjusted / as.numeric(roi1$MSFT.Adjusted[1])
roi1$IXIC.Adjusted <- roi1$IXIC.Adjusted / as.numeric(roi1$IXIC.Adjusted[1])
roi1 <- roi1*100
roi1 %>% dygraph(main="ROI Over Past 1 Years")

```

Row {.tabset data-width=500}
-----------------------------------------------------------------------
### Apple
```{r echo=FALSE}
AAPL[,1:4] %>% tail(30) %>% dygraph(main="APPLE: Past 30 days price") %>%
  dyCandlestick()


```

### Microsoft
```{r echo=FALSE}
MSFT[,1:4] %>% tail(30) %>% dygraph(main="Microsfot: Past 30 days price") %>%
  dyCandlestick()

```

### NASDAQ
```{r echo=FALSE}
IXIC[,1:4] %>% tail(30) %>% dygraph(main="NASDAQ: Past 30 days price") %>%
  dyCandlestick()

```