Introduction

Row

Overview

Due to the inherent growth in the electronic production and storage of information, there is often a feeling of “information overload” or inundation when facing the process of quantitative decision making. As an analyst your job will often be to conduct analyses or create tools to support quantitative decision making.

A principle tool used in industry, government, non-profits, and academic fields to compensate for the information overload is the information dashboard. Functionally, a dashboard is meant to provide a user with a central resource to present in a clear and concise manner all the information necessary to support day-to-day decision making and support operations.

Row

Objective

The objective of this laboratory is to plan, design, and create an information dashboard to support quantitative decision making. To accomplish this task, you will have to complete a number of steps:

1.Delineate the necessary decision (I will do that below). 2.Identify what information will be relevant to decision making. 3.Find and collect the data necessary to create your visualization plan. 4.Organize and summarize the collected data. 5.Design and create the best visualizations to present that information. 6.Finally organize the layout of those visualizations in a way that conforms to the theory of dashboarding. 7.Write a summary about what decisions you made based on the visualizations that you developed.

The Decision & Rules

You make investments for an organization; your objective is to purchase securities/commodities for the key objective of maximizing profits. You want to make an investment in securities/commodities to make some short-term gains. You are considering investing in one of any four companies, for example: Twitter (TWTR), Microsoft (MSFT), or Apple (AAPL) (don’t use these). Choose 4 companies or commodities and determine which one of the four will produce the most short-term gains. Use your imagination.

Overview

Row

Financial Indicators/Metrics

  • P-E Ratio - It is the ratio of a company’s share price to the company’s earnings per share. This ratio is used for valuing companies and to find out whether they are overvalued or undervalued.
  • EPS - It is the portion of a company’s profit that is allocated to every individual share of the stock and helps in understanding the financial strength of a company
  • Dividend Yield Ratio - is a financial ratio that shows how much a company pays out in dividends each year relative to its stock price.
  • Market Cap - the total value of a company’s shares.

Key Indicator Analysis

Column

Overall Daily Trend

[1] "CMCSA" "COF"   "LULU"  "MRNA" 

Facet Chart

Stock Valuation Analysis

Stocke Values

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

Monthly Return

Individual Stock Analysis - Candlestick Chart

Column

CMCSA

COF

LULU

MRNA

View in All

Conclusion

Row

Key Indicators Analysis

By analyzing key indicators such as “P/E Ratio”, “Price/EPS Estimate Next Year”, “Dividend Yield” and “Market Capitalization” to compare four different companies’s (CVS, UnitedHealth Group, Walgreens, and Cigna) performance from Jan 1, 2022 to Sept 31, 2022, we can see:

  • P-E Ratio - LULU has the highest P-E Ratio (36.24), which means that investors are expecting higher earnings growth in the future, then followed by CMCSA (10.03), COF (4.39) and MRNA (4.01).

  • EPS - According to EPS, LULU is also the highest one with 27.34, which indicates how much money a company makes for each share of its stock, followed by MRNA (15.78), CMCSA (8.18) and COF (5.77).

  • Dividend Yield - Based on dividend yield, CMCSA has the highest (3.34%), followed by COF (2.46%), LULU (0) and MRNA(0), which indicates though CMCSA is not advantageous in P-E Ratio nor EPS, its high Dividend yield is good for investors to gain dividends.

  • Market Cap - From the market capitalization perspective, CMCSA is the highest, followed by MRNA, LULU and COF. For seeking long-term divined and stable gain CMCSA is a better choice, for the short term gain, LULU is better since it’s PE raito and EPS are higher, since the market belibe it’s generating more profit per share.

---
title: "ANLY 512 - Lab 1"
author: "Gefei Yang"
date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source: embed
    html_document:
    df_print: paged
    pdf_document: default
---

# Table of Contents {.sidebar}

* Introduction
  
* Overview                          
  
* Companys Stocks Performances Detail

* Conclusion

# **Introduction**

Row {data-height=230}
-------------------------------------
    
### **Overview** 
Due to the inherent growth in the electronic production and storage of information, there is often a feeling of “information overload” or inundation when facing the process of quantitative decision making. As an analyst your job will often be to conduct analyses or create tools to support quantitative decision making.

A principle tool used in industry, government, non-profits, and academic fields to compensate for the information overload is the information dashboard. Functionally, a dashboard is meant to provide a user with a central resource to present in a clear and concise manner all the information necessary to support day-to-day decision making and support operations.

Row
-------------------------------------
    
### **Objective** 

The objective of this laboratory is to plan, design, and create an information dashboard to support quantitative decision making. To accomplish this task, you will have to complete a number of steps:

1.Delineate the necessary decision (I will do that below).
2.Identify what information will be relevant to decision making.
3.Find and collect the data necessary to create your visualization plan.
4.Organize and summarize the collected data.
5.Design and create the best visualizations to present that information.
6.Finally organize the layout of those visualizations in a way that conforms to the theory of dashboarding.
7.Write a summary about what decisions you made based on the visualizations that you developed.

### **The Decision & Rules**

You make investments for an organization; your objective is to purchase securities/commodities for the key objective of maximizing profits. You want to make an investment in securities/commodities to make some short-term gains. You are considering investing in one of any four companies, for example: Twitter (TWTR), Microsoft (MSFT), or Apple (AAPL) (don’t use these). Choose 4 companies or commodities and determine which one of the four will produce the most short-term gains. Use your imagination.

# **Overview**

Row
-------------------------

### **Financial Indicators/Metrics**

+ `r kableExtra::text_spec("**P-E Ratio**", color = "#5c5c5c")` - It is the ratio of a company's share price to the company's earnings per share. This ratio is used for valuing companies and to find out whether they are overvalued or undervalued.
+ `r kableExtra::text_spec("**EPS**", color = "#5c5c5c")` - It is the portion of a company's profit that is allocated to every individual share of the stock and helps in understanding the financial strength of a company
+ `r kableExtra::text_spec("**Dividend Yield Ratio**", color = "#5c5c5c")` - is a financial ratio that shows how much a company pays out in dividends each year relative to its stock price.
+ `r kableExtra::text_spec("**Market Cap**", color = "#5c5c5c")` - the total value of a company's shares.

### **Key Indicator Analysis**

```{r}
library(quantmod)
library(plyr)
library(DT)
library(tidyquant)
library(dplyr)
library(highcharter)
library(viridisLite)
library(ggplot2)
library(broom)
library(xts)
library(zoo)
what_metrics <- yahooQF(c("Price/Sales",
                          "P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "PEG Ratio",
                          "Dividend Yield",
                          "Market Capitalization"))
tickers <- c("CMCSA", "COF", "LULU", "MRNA")
metrics <- getQuote(paste(tickers, sep = ",", collapse = ";"), what = what_metrics)
metrics <- data.frame(Symbol = tickers, metrics[,2:length(metrics)])
colnames(metrics) <- c("Symbol", "P-E Ratio", "Price EPS Estimate Next Year", "Div Yield", "Market Cap")
DT::datatable(metrics)


```

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

### Overall Daily Trend {data-width=500}

```{r}
start <- as.Date("2022-01-01") 
end <- as.Date("2022-09-30")

getSymbols(tickers, src = "yahoo", from = start, to = end)
stocks = as.xts(data.frame(A = CMCSA[, "CMCSA.Adjusted"], 
B = COF[, "COF.Adjusted"], C = LULU[, "LULU.Adjusted"], 
E = MRNA[,"MRNA.Adjusted"]))
```


``` {r}
names(stocks) <- c("CMCSA", "COF", "LULU", "MRNA")
index(stocks) <- as.Date(index(stocks))

stocks_series <- tidy(stocks) %>% 
  
  ggplot(aes(x=index,y=value, color=series)) +
  labs(title = "Daily Stock Adjusted Prices Comparison from 01~09/2022",
       
       subtitle = "Among COMCAST, Capital One, Lululemon Athletica Inc, Moderna",
       caption = " Source: Yahoo Finance",
       color = "Stock",
       x = "Date",
       y = "End of day Adjusted Price ($)") +
  scale_color_manual(values = c("Red", "Green", "DarkBlue","Orange"))+
  geom_line()

stocks_series
```

### Facet Chart {data-width=500}

```{r}
stocks_series2 = tidy(stocks) %>% 
  
  ggplot(aes(x=index,y=value, color=series)) + 
  geom_line() +
  facet_grid(series~.,scales = "free") + 
  labs(title = "Daily Stock Adjusted Prices Comparison from 01~09/2022",
       
        subtitle = "Among COMCAST, Capital One, Lululemon Athletica Inc, Moderna",
       caption = " Source: Yahoo Finance",
       color = "Stock",
       x = "Date",
       y = "End of day Adjusted Price ($)") +
  scale_color_manual(values = c("Red", "Green", "DarkBlue","Orange"))
stocks_series2
```

# **Stock Valuation Analysis**

### Stocke Values{data-width=500}

```{r}
metrics<-data.frame(na.fill(metrics,0))
ggplot(metrics,aes(x=Symbol,y=Price.EPS.Estimate.Next.Year,fill=Symbol))+
 geom_col()+
 labs(x="Company name",y="EPS")
ggplot(metrics,aes(x=Symbol,y=P.E.Ratio,fill=Symbol))+
 geom_col()+
 labs(x="Company name",y="P/E Ratio")
ggplot(metrics,aes(x=Symbol,y=Market.Cap,fill=Symbol))+
 geom_col()+
 coord_polar("y",start=0)

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

### Monthly Return {data-width=500}
```{r}
library(dygraphs)

m.rt.CMCSA <- monthlyReturn(CMCSA)
m.rt.COF <- monthlyReturn(COF)
m.rt.LULU <- monthlyReturn(LULU)
m.rt.MRNA <- monthlyReturn(MRNA)

mg.return <- merge.xts(m.rt.CMCSA,m.rt.COF, m.rt.LULU,m.rt.MRNA)
colnames(mg.return) <- c('CMCSA','COF','LULU','MRNA')
dateWindow<-c("2022-01-01", "2022-09-30")
dygraph(mg.return, main = "Monthly Return") %>%
 dyAxis("y", label = "Return") %>%
 dyOptions(colors = RColorBrewer::brewer.pal(4, "Set1")) %>%
 dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
 highlightSeriesOpts = list(strokeWidth = 4)) %>%
 dyRangeSelector(height = 35, dateWindow=dateWindow)


```

# **Individual Stock Analysis - Candlestick Chart**

## Column {data-height=900 .tabset .tabset-fade}

``` {r}
# Libraries we need
library(tidyverse)
library(tidyquant)
# Configuring settings as per tidyquant tutorial
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

# The function
candleStick_plot<-function(symbol,from,to){
  tq_get(symbol,
        from = from,
        to = to,
        warnings = FALSE) %>% 
    mutate(greenRed=ifelse(open-close>0,
                           "Red",
                           "Green")) %>% 
    ggplot()+
    geom_segment(aes(x = date,
                     xend=date,
                     y =open,
                     yend =close,
                     colour=greenRed),
                 size=3)+
    theme_tq()+
    geom_segment(aes(x = date,
                     xend=date,
                     y =high,
                     yend =low,
                     colour=greenRed))+
    scale_color_manual(values=c("Forest Green","Red"))+
    ggtitle(paste0(symbol," (",from," - ",to,")"))+
    labs(y = "Price ($)",
        x = "Date") +
    theme(legend.position ="none",
          axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
          plot.title= element_text(hjust=0.5))
}

```

### CMCSA {data-width=900}

``` {r}
candleStick_plot("CMCSA",from = start,to = end)
```

### COF {data-width=900}

``` {r}
candleStick_plot("COF",from = start,to = end)
```

### LULU {data-width=900}

``` {r}
candleStick_plot("LULU",from = start,to = end)
```

### MRNA {data-width=900}

``` {r}
candleStick_plot("MRNA",from = start,to = end)
```

### View in All {data-width=900}
```{r}
ALL_STOCK <- c("CMCSA", "COF", "LULU", "MRNA") %>%
    tq_get(get = "stock.prices", from = "2022-01-01", to = "2022-09-30")

n <- 20
ALL_STOCK %>%
    filter(date >= start - days(2 * n)) %>%
    ggplot(aes(x = date, y = close, group = symbol)) +
    geom_candlestick(aes(open = open, close = close, high = high, low = low)) +
    geom_bbands(aes(high = high, low = low, close = close),
                ma_fun = SMA, n = n, sd = 2, size = 0.5) +
    labs(title = "Multiple Stocks at Once!",
         subtitle = "Quickly visualize the volatility of four stocks at once",
         x = "", y = "Closing Price") +
    coord_x_date(xlim = c(start, end)) +
    facet_wrap(~ symbol, scales = "free_y")

```



# **Conclusion**

Row
-------------------------

### **Key Indicators Analysis**
By analyzing key indicators such as “P/E Ratio”, “Price/EPS Estimate Next Year”, "Dividend Yield" and “Market Capitalization” to compare four different companies’s (CVS, UnitedHealth Group, Walgreens, and Cigna) performance from Jan 1, 2022 to Sept 31, 2022, we can see:

+ `r kableExtra::text_spec("**P-E Ratio**", color = "#5c5c5c")` - LULU has the highest P-E Ratio (36.24), which means that investors are expecting higher earnings growth in the future, then followed by CMCSA (10.03), COF (4.39) and MRNA (4.01). 

+ `r kableExtra::text_spec("**EPS**", color = "#5c5c5c")` - According to EPS, LULU is also the highest one with 27.34, which indicates how much money a company makes for each share of its stock, followed by MRNA (15.78), CMCSA (8.18) and COF (5.77). 

+ `r kableExtra::text_spec("**Dividend Yield**", color = "#5c5c5c")` - Based on dividend yield, CMCSA has the highest (3.34%), followed by COF (2.46%), LULU (0) and MRNA(0), which indicates though CMCSA is not advantageous in P-E Ratio nor EPS, its high Dividend yield is good for investors to gain dividends. 

+ `r kableExtra::text_spec("**Market Cap**", color = "#5c5c5c")` - From the market capitalization perspective, CMCSA is the highest, followed by MRNA, LULU and COF. For seeking long-term divined and stable gain CMCSA is a better choice, for the short term gain, LULU is better since it's PE raito and EPS are higher, since the market belibe it's generating more profit per share. 


### **Individual Trends Analysis**

Based on Candlestick Chart for each stock, we can clearly see, CMCSA and COF are keep falling since 2022 January, the trends are most alike the whole market due the Fed increased the rate, since those two companies are telecommunication or bank, which are transitional companies.  LULU has a surge in April due to it's beating the expections in earnings, as a consumer product company, LULU seems has more tolerate to the recessions, which imply that their product is essential for the daily life.  MRNA is bio medical company which produce covid-19 vaccine, with the recovering of the pandemic, the demanding is reduced, but their revenue can still be generate by the intentional market, so the price trends doesn't appears like CMCSA and COF.  For investment idea, LULU is good for short-term investment since the PE ratio is not over high, and the EPS is high, CMCSA is a stable asset for divined gain which are better hold for long-term.  MRNA is an out-of-date stock seems is not popular anymore, unless there are hugh demanding on vaccine again.  COF has good divded rate and capital market is not super high, which mean it's possible to have a large price gain in short time, but it's heavily rely on the finance policy of US.