---
title: "ANLY 512 Lab 1 2023 Spring "
author: "Sun,Shengxi"
date: "March 28, 2023"
output:
flexdashboard::flex_dashboard:
source_code: embed
social: menu
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
#library(ggplot2)
#library(dplyr)
library(quantmod)
library(dygraphs)
```
# Lab 1 Overview
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=320}
-------------------------------------
### **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.
Row {data-height=320}
-------------------------------------
### **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.
Row {data-height=320}
-------------------------------------
### **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.
# Key indicator Analysis
Row {data-height=320}
------------------------------
### FOUR Key Indicator Use for Analysis {.sidebar}
*P/E Ratio : It is the ratio for measures company's current share price relative to its per-share earnings. P/E Ratio is below 20 indicate it provide good investment opportunity.
*Price/EPS Estimate Next Year : EPS growth rate is a measure of profitability, <= 25% indicate good investment opportunity.
*Dividend Yield : it is the amount of money a company pays shareholders for owning a share of its stock divided by its current stock price. Between 2% - 5% indicate good.
*Market Capitalization :refers to the total value of all a company's shares of stock.
Row {data-height=600}
------------------------------
### Main Object
In this lab I would like to use 4 financial indicator to compare the goodness of investment between 4 companies, they are:
*IBM: International Business Machines Corporation
*MSFT: Microsoft Corporation
*ORCL: Oracle Corporation
*SAP:System Analysis Program Development
Row {data-height=320}
------------------------------
### Company stock Comparison
```{r}
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("IBM", "MSFT", "ORCL", "SAP")
# 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")
#write this to the csv file
write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
DT::datatable(metrics)
```
Row {data-height=320}
------------------------------
### Conclusion
Based on 4 indicators in this chart, among these 4 companies, MSFT have the largest Market Cap and it's Prive EPS Estimate next yeatr is larger than 25. I think MSFT has the best investment opportunity.
# Individual Stock Analysis
## Conclusion {.sidebar}
*Summary Conclusion
After compared the 4 candlestick graphs, Microsoft Corporation has the highest daily stock close price among all 4 stock companies. Combined with the information we get from the previous page, I believe Microsoft corporation is the best investment opportunities in all 4 companies.
## Candlestick {.tabset data-width=700}
### IBM
```{r}
getSymbols("IBM", src = "yahoo", from="2022-10-28")
IBMc <- IBM
dygraph(IBMc[, -5], main = "IBM") %>%
dyCandlestick() %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4, highlightSeriesOpts = list(strokeWidth = 5), highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 60)
```
### MSFT
```{r}
getSymbols("MSFT", src = "yahoo", from="2022-10-28")
MSFTc <- MSFT
dygraph(MSFTc[, -5], main = "Microsoft") %>%
dyCandlestick() %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4, highlightSeriesOpts = list(strokeWidth = 5), highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 60)
```
### ORCL
```{r}
getSymbols("ORCL", src = "yahoo", from="2022-10-28")
ORCLc <- ORCL
dygraph(ORCLc[, -5], main = "Oracle") %>%
dyCandlestick() %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4, highlightSeriesOpts = list(strokeWidth = 5), highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 60)
```
### SAP
```{r}
getSymbols("SAP", src = "yahoo", from="2022-10-28")
SAPc <- SAP
dygraph(SAPc[, -5], main = "SAP") %>%
dyCandlestick() %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4, highlightSeriesOpts = list(strokeWidth = 5), highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 60)
```