Instruction

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, goverment, 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 neccessary 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)
  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.

Methods Help

Getting data

There are lots of places we can get financial data to support these decision. The simplest would be to go to for instance to the Yahoo Finance (https://finance.yahoo.com/) for data on the Hershey Company (HSY) the URL would be: (https://finance.yahoo.com/quote/HSY/history?p=HSY) and collect historical price data, and other financial and company information.

Stock Valuation Analysis

Summary

From the EPS & P/E ratio charts,JPM has the best valuation here. EPS is the second best and P/E ratio is the lowest, means the stock of this company is the most profitable one among these 4 companies. Same goes for MSFT, second best P/E ratio and not bad EPS. MSFT is also the company with the biggest market capitalization. We can see AMZN gives the best EPS but due to its high stock price, AMZN has the worst P/E ratio, 79. TSLA is not making profit right now, so it presents a negative EPS and no P/E ratio. From the stock valuation standpoint, we will prefer JPM and MSFT to the rest 2 companies. However, our question is to get some short term gain. Stock valuation method has very little impact on the short term, so we need to dig a little deeper to see how we want to make a choice here.

Stock Closing Price

Row

Summary

The closing price represents the most up-to-date valuation of a security until trading commences again on the next trading day. As we can see from the Straw Broom Charts that ‘JPMorgan Chase & Co’ and ‘Microsoft Corporation’ have the most stable and pretty similar stock closing price thourghout the years from 2014 to 2019. ‘Tesla’ has higher closing stock price compare to ‘JPMorgan Chase & Co’ and ‘Microsoft Corporation’. Closing price for ‘Amazon’ is the highest amongst all 4 companies which started increasing since 2016 and almost reached $2000 in late 2018 then down to $1300 in January 2019 lately the price began raising again.

Monthly Return

Row

Summary

Monthly Return is the period returns re-scaled to a period of 1 month. This allows investors to compare returns of different assets that they have owned for different lengths of time. Monthly Return = Closing Price on Last Day of Month / Closing Price on Last Day of Previous Month. Compare to 3 other companies, Tesla has the highest fluctuation in the recent 5 years. Microsoft Corporation and JPMorgan Chase & Co are the more stable which is similar to what we found when looking at Closing Price. Tesla almost reached the lowest price since 2014, so for investigation on short term gain, we might choose Tesla.

Reference

https://www.investopedia.com/terms/p/price-earningsratio.asp https://www.investopedia.com/terms/e/eps.asp https://www.investopedia.com/terms/m/marketcapitalization.asp https://www.investopedia.com/terms/c/closingprice.asp https://ycharts.com/glossary/terms/monthly_return

---
title: "Dashboard Lab"
author: "Yiheng Hu and Ziqiao Xu"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: [ "menu" ]
    source: embed
    vertical_layout: fill
---

Instruction
===================================== 
Row {data-height=320}
-------------------------------------

### **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, goverment, 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 neccessary to support day-to-day decision making and support operations.

Row {data-height=680}
-------------------------------------
### **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)
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.

### **Methods Help**
##### *Getting data*
There are lots of places we can get financial data to support these decision. The simplest would be to go to for instance to the Yahoo Finance (https://finance.yahoo.com/) for data on the Hershey Company (HSY) the URL would be: (https://finance.yahoo.com/quote/HSY/history?p=HSY) and collect historical price data, and other financial and company information.

```{r, echo = TRUE, include = FALSE, message = FALSE}
library(xts) # create Candlestick Charts using the dyCandlestick function
library(pdfetch)
library(DT)
library(lubridate)
library(dygraphs)
library(quantmod) 
library(dplyr)
library(knitr)
library(ggplot2)
library(tidyr)
library(plyr)
library(PerformanceAnalytics)
library(stocks)
what_metrics <- yahooQF(c("Price/Sales",
                          "Earnings/Share",
                          "P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "PEG Ratio",
                          "Dividend Yield",
                          "Market Capitalization"))

what_metrics
tickers <- c( "JPM", "MSFT", "TSLA", "AMZN")
# Not all the metrics are returned by Yahoo.
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)
class(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)]) 
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)
DT::datatable(metrics)
```


Stock Valuation Analysis
===================================== 
+ `r kableExtra::text_spec("**Earning Share**", color = "#5c5c5c")` - Earnings per share (EPS) is calculated as a company's profit divided by the outstanding shares of its common stock.
+ `r kableExtra::text_spec("**P-E Ratio**", color = "#5c5c5c")` - The price-to-earnings ratio (P/E ratio) is the ratio for valuing a company that measures its current share price relative to its per-share earnings.
+ `r kableExtra::text_spec("**Market Capitalization**", color = "#5c5c5c")` - Market capitalization refers to the total dollar market value of a company's outstanding shares.
+ `r kableExtra::text_spec("**Closing Price**", color = "#5c5c5c")` - The closing price is the final price at which a security is traded on a given trading day.


### **Summary**  
From the EPS & P/E ratio charts,JPM has the best valuation here. EPS is the second best and P/E ratio is the lowest, means the stock of this company is the most profitable one among these 4 companies. Same goes for MSFT, second best P/E ratio and not bad EPS. MSFT is also the company with the biggest market capitalization. We can see AMZN gives the best EPS but due to its high stock price, AMZN has the worst P/E ratio, 79. TSLA is not making profit right now, so it presents a negative EPS and no P/E ratio. From the stock valuation standpoint, we will prefer JPM and MSFT to the rest 2 companies. However, our question is to get some short term gain. Stock valuation method has very little impact on the short term, so we need to dig a little deeper to see how we want to make a choice here.


```{r}
metrics<-data.frame(na.fill(metrics,0))
ggplot(metrics,aes(x=Symbol,y=Earnings.Share,fill=Symbol))+
  geom_col()+
  labs(x="Company name",y="Earnings/Share")
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.Capitalization,fill=Symbol))+
  geom_col()+
  coord_polar("y",start=0)
```



```{r, echo=FALSE,include = FALSE, message=FALSE}
getSymbols("MSFT",from="2014-06-01",to="2019-06-1")
MSFT_log_returns<-MSFT%>%Ad()%>%dailyReturn(type='log')

getSymbols("TSLA",from="2014-06-01",to="2019-06-1")
TSLA_log_returns<-TSLA%>%Ad()%>%dailyReturn(type='log')

getSymbols("JPM",from="2014-06-01",to="2019-06-1")
JPM_log_returns<-JPM%>%Ad()%>%dailyReturn(type='log')

getSymbols("AMZN",from="2014-06-01",to="2019-06-1")
AMZN_log_returns<-AMZN%>%Ad()%>%dailyReturn(type='log')
```


Stock Closing Price
===================================== 
Row {data-height=800}
-------------------------------------
```{r}
tickers <- c("JPM", "MSFT", "TSLA", "AMZN")
ClosingPrices <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))

dateWindow<-c("2014-06-01", "2019-06-01")

dygraph(ClosingPrices, main="Stock Closing Price", group="Stock") %>%
    dyAxis("y", label="Closing Price ($) ") %>%
  dyOptions( colors = RColorBrewer::brewer.pal(4, "Set1")) %>%
  dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
              highlightSeriesOpts = list(strokeWidth = 3)) %>%
  dyRangeSelector(height = 35, dateWindow=dateWindow)
```


### **Summary**  
The closing price represents the most up-to-date valuation of a security until trading commences again on the next trading day. As we can see from the Straw Broom Charts that 'JPMorgan Chase & Co' and 'Microsoft Corporation' have the most stable and pretty similar stock closing price thourghout the years from 2014 to 2019. 'Tesla' has higher closing stock price compare to 'JPMorgan Chase & Co' and 'Microsoft Corporation'. Closing price for 'Amazon' is the highest amongst all 4 companies which started increasing since 2016 and almost reached $2000 in late 2018 then down to $1300 in January 2019 lately the price began raising again. 



Monthly Return
===================================== 
Row {data-height=850}
-------------------------------------

###Now we are looking at the monthly return for those four companies in the recent 5 years since monthly return is related to the closing price:

```{r}
m.rt.TSLA <- monthlyReturn(TSLA)
m.rt.JPM <- monthlyReturn(JPM)
m.rt.AMZN <- monthlyReturn(AMZN)
m.rt.MSFT <- monthlyReturn(MSFT)

mg.return <- merge.xts(m.rt.TSLA,m.rt.JPM, m.rt.AMZN, m.rt.MSFT)
colnames(mg.return) <- c('Tesla','JPMorgan Chase & Co','Amazon','Microsoft Corporation')

dateWindow<-c("2014-06-01", "2019-06-01")

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)
```

### **Summary** 
Monthly Return is the period returns re-scaled to a period of 1 month. This allows investors to compare returns of different assets that they have owned for different lengths of time. Monthly Return = Closing Price on Last Day of Month / Closing Price on Last Day of Previous Month. Compare to 3 other companies, Tesla has the highest fluctuation in the recent 5 years. Microsoft Corporation and JPMorgan Chase & Co are the more stable which is similar to what we found when looking at Closing Price. Tesla almost reached the lowest price since 2014, so for investigation on short term gain, we might choose Tesla.


Reference
===================================== 
https://www.investopedia.com/terms/p/price-earningsratio.asp
https://www.investopedia.com/terms/e/eps.asp
https://www.investopedia.com/terms/m/marketcapitalization.asp
https://www.investopedia.com/terms/c/closingprice.asp
https://ycharts.com/glossary/terms/monthly_return