Stock Price

## Column

McDonald’s Corporation (MCD)

Gartner, Inc. (IT)

NYSE - NYSE Delayed Price. Currency in USD

Cigna Corporation (CI)

NYSE - NYSE Delayed Price. Currency in USD

3M Company (MMM)

NYSE - NYSE Delayed Price. Currency in USD

## Column

Bollinger Bands

Summary

## Column

Summary of Financial Metrics

Recommendations

The four stocks that I selected are McDonald’s, Gartner, Cigna, and 3M, which cover Food, Financial, IT business and Manufacturing industry and their current price are at a comparable range.

  1. By looking at the one year stock price trending, McDonald’s is showing downward trend while the other three shows upward trend.

  2. According to technical analysis, to assess whether the stock price will continue to grow, we usually look at moving average line and see if short-term moving average line cross above the long-term moving average line. In stock price chart, light green line, purple line and dark green line are presenting the moving average of 5 days, 10 days and 50 days. Within these four stocks, Gartner, Cigna, and 3M appear the light green line (SMA 5) is crossing above the purple ine (SMA 10) and dark green line (SMA 50), which indicates high likelihood on upward trend.

  3. Another method is to levarage bollinger bands to identify volatility or risk of the investment. All four stocks are showing wider bollinger bands than before. Cigna shows the widest range of bollinger band with upward trend, following by 3M and Gartner.Gartner shows the least volatility while McDonald’s shows the largest volatility.

  4. By summarizing the financial metrics for these four stocks, Gartner shows it is the most profitable company in the future compared to other stocks as it has the highest earning per shares estimation in next year, but it might be overvalued as it’s P/E ratio is also high. 3M yield the highest dividend and McDonald’s has the largest market size.

  5. Overall, I will recommend to buy Gartner. The reason is that the stock price is showing upward trend with low historical volatility and high expectations on future profit growth by investors.

---
title: "ANLY 512: Lab1 - Dashboard Laboratory"
author: "Yanqi Ma"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source: embed
---

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

Stock Price
============================================


## Column {.tabset data-width=550}
-----------------------------------------------------------------------



### McDonald's Corporation (MCD)

```{r mcd,include=TRUE}
mcd <- pdfetch_YAHOO("MCD", fields = c("open", "high", "low", "close"), from = as.Date("2018-11-06"),interval = "1d")
colnames(mcd)=c("Open","High","Low","Close")

m <- tail(mcd, n = 365)
m <- cbind(m, SMA(m[,4], n=5))
m <- cbind(m, SMA(m[,4], n=10))
m <- cbind(m, SMA(m[,4], n=50))

colnames(m)[5:7] <- c('SMA5','SMA10',"SMA50")

#plot
dygraph(m,
        ylab = "Stock Price ($)",
        group = "stockprices") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector(dateWindow = c("2018-11-06", "2019-11-06"))
```

### Gartner, Inc. (IT)
NYSE - NYSE Delayed Price. Currency in USD

```{r IT,include=TRUE}
it <- pdfetch_YAHOO("IT", fields = c("open", "high", "low", "close"), from = as.Date("2018-11-06"),interval = "1d")
colnames(it)=c("Open","High","Low","Close")

m <- tail(it, n = 365)
m <- cbind(m, SMA(m[,4], n=5))
m <- cbind(m, SMA(m[,4], n=10))
m <- cbind(m, SMA(m[,4], n=50))

colnames(m)[5:7] <- c('SMA5','SMA10',"SMA50")

#plot
dygraph(m,
        ylab = "Stock Price ($)",
        group = "stockprices") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector(dateWindow = c("2018-11-06", "2019-11-06"))
```

### Cigna Corporation (CI)
NYSE - NYSE Delayed Price. Currency in USD

```{r ci,include=TRUE}
ci <- pdfetch_YAHOO("ci", fields = c("open", "high", "low", "close"), from = as.Date("2018-11-06"),interval = "1d")
colnames(ci)=c("Open","High","Low","Close")

m <- tail(ci, n = 365)
m <- cbind(m, SMA(m[,4], n=5))
m <- cbind(m, SMA(m[,4], n=10))
m <- cbind(m, SMA(m[,4], n=50))

colnames(m)[5:7] <- c('SMA5','SMA10',"SMA50")

#plot
dygraph(m,
        ylab = "Stock Price ($)",
        group = "stockprices") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector(dateWindow = c("2018-11-06", "2019-11-06"))
```

### 3M Company (MMM)
NYSE - NYSE Delayed Price. Currency in USD

```{r 3m,include=TRUE}
mmm <- pdfetch_YAHOO("MMM", fields = c("open", "high", "low", "close"), from = as.Date("2018-11-06"),interval = "1d")
colnames(mmm)=c("Open","High","Low","Close")

m <- tail(mmm, n = 365)
m <- cbind(m, SMA(m[,4], n=5))
m <- cbind(m, SMA(m[,4], n=10))
m <- cbind(m, SMA(m[,4], n=50))

colnames(m)[5:7] <- c('SMA5','SMA10',"SMA50")


#plot
dygraph(m,
        ylab = "Stock Price ($)",
        group = "stockprices") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector(dateWindow = c("2018-11-06", "2019-11-06"))
```

## Column {data-width=450}
----------------------------------------------

### Bollinger Bands

```{r bbands,eval=TRUE}
micm <- c("MCD", "IT", "CI", "MMM") %>%
    tq_get(get = "stock.prices", from = "2018-11-06", to = "2019-11-06")
end <- as_date("2019-11-06")
start<-end-weeks(52)
micm %>%
    ggplot(aes(x = date, y = close, 
               open = open, high = high, low = low, close = close, 
               group = symbol)) +
    geom_barchart() +
    geom_bbands(ma_fun = SMA, sd = 2, n = 20, linetype = 5) +
    labs(title = "Bollinger Bands on Four Selected Stocks", 
         y = "Closing Price", x = "") + 
    coord_x_date(xlim = c(start, end)) +
    facet_wrap(~ symbol, ncol = 2, scales = "free_y") + 
    theme_tq()
```


Summary
============================================

## Intro Text{.sidebar}
-------------------------------------------
Objectives:

This dashboard is to help on making the short-term investment decision and maximizing return. To provide insight on the selected stocks, we included 1 year candlestick stock price tracking with moving average supporting lines, bollinger bands chart, and financial metrics that would help on picking the stock. 



## Column {.tabset data-height=650}
--------------------------------------------------



### Summary of Financial Metrics

```{r load summary data,include=TRUE}
library(quantmod)
library(plyr)
what_metrics <- yahooQF(c("Price/Sales", 
                          "P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "PEG Ratio",
                          "Dividend Yield", 
                          "Market Capitalization"))

tickers <- c("MCD", "IT", "CI", "MMM")
# Not all the metrics are returned by Yahoo.
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)

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

#Change colnames
colnames(metrics) <- c("Symbol", "P-E Ratio", "Price EPS Estimate Next Year", "Div Yield", "Market Cap")

#Persist this to the csv file
#write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
datatable(metrics)
```

### Recommendations
The four stocks that I selected are McDonald's, Gartner, Cigna, and 3M, which cover Food, Financial, IT business and Manufacturing industry and their current price are at a comparable range.

1. By looking at the one year stock price trending, McDonald's is showing downward trend while the other three shows upward trend.

2. According to technical analysis, to assess whether the stock price will continue to grow, we usually look at moving average line and see if short-term moving average line cross above the long-term moving average line. In stock price chart, light green line, purple line and dark green line are presenting the moving average of 5 days, 10 days and 50 days. Within these four stocks, Gartner, Cigna, and 3M appear the light green line (SMA 5) is crossing above the purple ine (SMA 10) and dark green line (SMA 50), which indicates high likelihood on upward trend.

3. Another method is to levarage bollinger bands to identify volatility or risk of the investment. All four stocks are showing wider bollinger bands than before. Cigna shows the widest range of bollinger band with upward trend, following by 3M and Gartner.Gartner shows the least volatility while McDonald's shows the largest volatility.

4. By summarizing the financial metrics for these four stocks, Gartner shows it is the most profitable company in the future compared to other stocks as it has the highest earning per shares estimation in next year, but it might be overvalued as it's P/E ratio is also high. 3M yield the highest dividend and McDonald's has the largest market size.

5. Overall, I will recommend to buy Gartner. The reason is that the stock price is showing upward trend with low historical volatility and high expectations on future profit growth by investors.