Lab 1 Insturctions

Column

Lab 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.

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
  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. Organize the layout of those visualizations in a way that conforms to the theory of dashbaording.

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.

Choose 4 companies or commodities and determine which one of the four will produce the most short term gains.

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.

Alternatively, and more professionally, there are tons of packages that allow you to access data from R. See here quick examples. This is not a complete list but will get you started.

Conclusions

Lab Summary

I choose the following four companies from the consumer goods industry for a comparison of key indicators and stock performances:

  • Unilever

  • Nestle

  • P&G

  • Johnson & Johnson

The Best Company to Invest in Short-Term

Overall, in short term,Johnson & Johnson would be the best company to invest.

  • Its 50 day (135) and 200 day (134) moving averages are both lower than its last closing price (144).
  • It has the highest percentage of monthly return (0.4) with an upwarding trend. However, it’s monthly return is the most unstable stock, meaning that there is a chance to gain.
  • Compared to other companies, it has the biggest market cap with the highest daily volumn.

Key Indicators

Summary

Summary

We are looking at some key indicators on the four companies.

The indicators are Price/Earnings ratio, Price/EPS estimate for next year, dividend yield, market capitalization of the company, 50 day moving average, 200 day Moving average and average daily volume traded for the stock.

The first few indicators are to spot check the outlook and health of the company (Price/Earnings ratio, Price/EPS estimate for next year, dividend yield, market capitalization), while the last few are for checking the short-term profitability out of trading the stock (0 day moving average, 200 day Moving average and average daily volume)

Based on the short-term indicators, my choice is to buy & hold Johnson & Johnson, with a view of creating some short-term gains.

Symbol P-E Ratio Price EPS Estimate Next Year Div Yield Market Cap X.50.day.MA X.200.day.MA Avg.Daily Volumn
UL UL 22.12109 22.90984 0.03050817 135388684288 59.4120 60.81878 850743
NSRGY NSRGY 39.65969 NA 0.02250166 304444112896 104.8694 105.92180 417329
PG PG 78.48734 23.71128 0.02335009 309257371648 122.3246 118.39043 6547737
JNJ JNJ 27.31070 15.75248 0.02577320 381562716160 135.8517 133.75670 7247418

Stock Analysis 1

## Column

[1] "UL"
[1] "NSRGY"
[1] "PG"
[1] "JNJ"

The first graph shows the change in closing stock price for the four companies, from December 18, 2014 through December 18, 2019. The second graph shows the volume of shares traded each day, and the upper/lower range of the stock price as it moves this year (2019).

Unilever

Nestle

P&G

Johnson & Johnson

Stock Analysis 2

column

It’s not to hard to find that all companies tend to have a higher stock price year over year. Among these stocks, Johnson & Johnson has the highest stock price and seems to continue the upward trend. So It’s a good chance to gain in short term.

column

Compared to other stocks, Johnson & Johnson has the highest percentage of monthly return (0.4) with an upwarding trend.

---
title: "ANLY 512 Lab 1"
author: "Qin Zhu"
date: "12/18/2019"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
#install.packages("PerformanceAnalytics")
#install.packages("dygraphs")
#install.packages("data.table")
#install.packages("formattable")
#install.packages("tidyr")
library(flexdashboard)
library(dplyr)
library(PerformanceAnalytics)
library(dygraphs)
library(data.table)
library(formattable)
library(tidyr)
library(quantmod)
```

# Lab 1 Insturctions

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

### Lab 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.

### 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
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. Organize the layout of those visualizations in a way that conforms to the theory of dashbaording.

### 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. 

Choose 4 companies or commodities and determine which one of the four will produce the most short term gains.

### 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.

Alternatively, and more professionally, there are tons of packages that allow you to access data from R. See here quick examples. This is not a complete list but will get you started.

## Conclusions

### Lab Summary
I choose the following four companies from the consumer goods industry for a comparison of key indicators and stock performances: 

* Unilever

* Nestle

* P&G

* Johnson & Johnson


### The Best Company to Invest in Short-Term
Overall, in short term,Johnson & Johnson would be the best company to invest.

* Its 50 day (135) and 200 day (134) moving averages are both lower than its last closing price (144). 
* It has the highest percentage of monthly return (0.4) with an upwarding trend. However, it's monthly return is the most unstable stock, meaning that there is a chance to gain. 
* Compared to other companies, it has the biggest market cap with the highest daily volumn. 



# Key Indicators

## Summary

### Summary
We are looking at some key indicators on the four companies.

The indicators are Price/Earnings ratio, Price/EPS estimate for next year, dividend yield, market capitalization of the company, 50 day moving average, 200 day Moving average and average daily volume traded for the stock.

The first few indicators are to spot check the outlook and health of the company (Price/Earnings ratio, Price/EPS estimate for next year, dividend yield, market capitalization), while the last few are for checking the short-term profitability out of trading the stock (0 day moving average, 200 day Moving average and average daily volume)

Based on the short-term indicators, my choice is to buy & hold Johnson & Johnson, with a view of creating some short-term gains.

```{r}
what_metrics <- yahooQF(c("P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "Dividend Yield",
                          "Market Capitalization",
                          "50-day Moving Average",
                          "200-day Moving Average",
                          "Average Daily Volume"))

tickers <- c("UL", "NSRGY", "PG","JNJ")
# 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", "X.50.day.MA", "X.200.day.MA", "Avg.Daily Volumn")

formattable(metrics)
```

# Stock Analysis 1


## Column {.tabset}
-----------------------------------------------------------------------

```{r, echo=FALSE, message=FALSE}
getSymbols("UL",from="2014-12-18",to="2019-12-18")
UL_log_returns<-UL%>%Ad()%>%dailyReturn(type='log')

getSymbols("NSRGY",from="2014-12-18",to="2019-12-18")
NSRGY_log_returns<-NSRGY%>%Ad()%>%dailyReturn(type='log')

getSymbols("PG",from="2014-12-18",to="2019-12-18")
PG_log_returns<-PG%>%Ad()%>%dailyReturn(type='log')

getSymbols("JNJ",from="2014-12-18",to="2019-12-18")
JNJ_log_returns<-JNJ%>%Ad()%>%dailyReturn(type='log')
```

The first graph shows the change in closing stock price for the four companies, from December 18, 2014 through December 18, 2019. The second graph shows the volume of shares traded each day, and the upper/lower range of the stock price as it moves this year (2019). 

### Unilever 
```{r}

UL%>%Ad()%>%chartSeries(theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
UL%>%chartSeries(TA='addBBands()',subset='2019', 
                  up.col = "Blue", dn.col = "Orange",
                  theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)

```

### Nestle
```{r}
NSRGY%>%Ad()%>%chartSeries(theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
NSRGY%>%chartSeries(TA='addBBands()',subset='2019', 
                  up.col = "Blue", dn.col = "Orange",
                  theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE) 
```

### P&G

```{r}
PG%>%Ad()%>%chartSeries(theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
PG%>%chartSeries(TA='addBBands()',subset='2019', 
                  up.col = "Blue", dn.col = "Orange",
                  theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
```

### Johnson & Johnson

```{r}
JNJ%>%Ad()%>%chartSeries(theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
JNJ%>%chartSeries(TA='addBBands();addVo();addMACD()',subset='2019', 
                  up.col = "Blue", dn.col = "Orange",
                  theme = chartTheme("white"),
                  color.vol = TRUE, multi.col = FALSE)
```

# Stock Analysis 2

## column
It's not to hard to find that all companies tend to have a higher stock price year over year. Among these stocks, Johnson & Johnson has the highest stock price and seems to continue the upward trend. So It's a good chance to gain in short term. 

```{r}
tickers_1 <- c("UL", "NSRGY", "PG", "JNJ")
ClosingPrices <- do.call(merge, lapply(tickers_1, function(x) Cl(get(x))))

dateperiod<-c("2014-12-18", "2014-12-18")


dygraph(ClosingPrices, main="Closing Price in USD", group="Stock") %>%
  dyAxis("y", label="Closing Price(USD)") %>%
  dyOptions( colors = RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
              highlightSeriesOpts = list(strokeWidth = 4)) %>%
  dyRangeSelector(height = 30)
```

## column

Compared to other stocks, Johnson & Johnson has the highest percentage of monthly return (0.4) with an upwarding trend. 

```{r}
m.rt.UL <- monthlyReturn(UL)
m.rt.NSRGY <- monthlyReturn(NSRGY)
m.rt.PG <- monthlyReturn(PG)
m.rt.JNJ <- monthlyReturn(JNJ)

mg.return <- merge.xts(m.rt.UL,m.rt.NSRGY, m.rt.PG, m.rt.JNJ)
colnames(mg.return) <- c('UL','NSRGY','PG','JNJ')


dygraph(mg.return, main = "Monthly Return") %>%
  dyAxis("y", label = "Return") %>%
  dyOptions(colors = RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
              highlightSeriesOpts = list(strokeWidth = 4)) %>%
  dyRangeSelector(height = 30)
```