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.
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.
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.
library(xts)
library(pdfetch)
library(DT)
library(lubridate)
library(dygraphs)
library(quantmod)
library(dplyr)
library(knitr)
library(broom)
library(ggplot2)
library(tidyr)
library(plyr)
library(plotly)
library(PerformanceAnalytics)
library(stocks)
library(zoo)
what_metrics <- yahooQF(c("Price/Sales",
"Earnings/Share",
"P/E Ratio",
"Price/EPS Estimate Next Year",
"PEG Ratio",
"Dividend Yield",
"Market Capitalization"))
what_metrics[[1]]
[1] "epsTrailingTwelveMonths" "trailingPE"
[3] "forwardPE" "trailingAnnualDividendYield"
[5] "marketCap"
[[2]]
[1] "Earnings/Share" "P/E Ratio"
[3] "Price/EPS Estimate Next Year" "Dividend Yield"
[5] "Market Capitalization"
attr(,"class")
[1] "quoteFormat"
tickers <- c( "JPM", "CVS", "TSLA", "AMZN")
metrics <- getQuote(paste(tickers, sep=",", collapse=";"), what=what_metrics)
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)
DT::datatable(metrics)start <- as.Date("2022-01-01")
end <- as.Date("2022-12-31")
getSymbols(tickers, src = "yahoo", from = start, to = end)[1] "JPM" "CVS" "TSLA" "AMZN"
stocks = as.xts(data.frame(A = JPM[, "JPM.Adjusted"],
B = CVS[, "CVS.Adjusted"], C = TSLA[, "TSLA.Adjusted"],
E = AMZN[,"AMZN.Adjusted"]))names(stocks) <- c("JPM", "CVS", "TSLA","AMZN")
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~12/2022",
subtitle = "Among JP Morgan, CVS, Tesla, Amazon",
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}
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~12/2022",
subtitle = "Among JPM, CVS, Tesla, Amazon",
caption = " Source: Yahoo Finance",
color = "Stock",
x = "Date",
y = "End of day Adjusted Price ($)") +
scale_color_manual(values = c("Red", "Green", "DarkBlue","Orange"))
stocks_series2The 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, overall, Tesla had the highest stock closing price in 2022, having a peak rate in April however plummeting in December, below JP Morgan’s rate. CVS had the most stable closing price throughout 2022. Amazon and JP Morgan have had similar fluctuations closely competing with each other throughout 2022.
tickers <- c("JPM", "CVS", "TSLA", "AMZN")
ClosingPrices <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateWindow<-c("2022-01-01", "2022-12-31")
dygraph(ClosingPrices, main="Stock Closing Price", group="Stock", width='auto') %>%
dyAxis("y", label="Closing Price ($) ") %>%
dyOptions( colors = RColorBrewer::brewer.pal(4, "Set1")) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
highlightSeriesOpts = list(strokeWidth = 4)) %>%
dyRangeSelector(dateWindow=dateWindow)Here is the comparison of their Monthly return in one combined plot. This chart shows all stocks monthly return in one chart, so it is easier for use to find which one has better return. 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. Compared to 3 other companies, Tesla has the highest fluctuations throughout 2022, with the least monthly return by the end of the year. CVS has a more relatively stable data in 2022.
m.rt.JPM <- monthlyReturn(JPM)
m.rt.CVS <- monthlyReturn(CVS)
m.rt.TSLA <- monthlyReturn(TSLA)
m.rt.AMZN <- monthlyReturn(AMZN)
mg.return <- merge.xts(m.rt.JPM,m.rt.CVS, m.rt.TSLA, m.rt.AMZN)
colnames(mg.return) <- c('JP Morgan Chase & Co','CVS','Tesla','Amazon')
dateWindow<-c("2022-01-01", "2022-12-31")
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(dateWindow=dateWindow)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 (JPM, CVS, Tesla, and Amazon) performance from Jan 1, 2022 to Sept 31, 2022, we can see:
P-E Ratio - JPM has the highest P-E Ratio (12.09), which means that investors are expecting higher earnings growth in the future, then followed by Tesla (3.61), CVS (3.14) and Amazon (-0.27).
EPS - According to EPS, Tesla has the highest one with 52.40 , which indicates how much money a company makes for each share of its stock, followed by CVS (23.28) and JPM (10.66).
Dividend Yield - Based on dividend yield, Amazon has the highest (38.58%), followed by Tesla (34.58%), JPM (9.57%) and CVS (8.04%), which indicates though Amazon 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, CVS is the highest, followed by JPM. Overall, from the key indicators, Tesla is a better company to invest in among others, then JPM, CVS and Amazon.
Based on the above analysis and as a conservative investor, Tesla is a good company to invest in as it’s steadily trending up, and JPM is also good too as it’s stable and its Dividend yield is relatively high. CVS is also not bad, but may be a little risky. Amazon is not recommended to invest in.
---
title: "ANLY Lab 1"
author: "RS"
date: "2023-03-28"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
source_code: embed
html_document:
df_print: paged
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# **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(xts)
library(pdfetch)
library(DT)
library(lubridate)
library(dygraphs)
library(quantmod)
library(dplyr)
library(knitr)
library(broom)
library(ggplot2)
library(tidyr)
library(plyr)
library(plotly)
library(PerformanceAnalytics)
library(stocks)
library(zoo)
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", "CVS", "TSLA", "AMZN")
metrics <- getQuote(paste(tickers, sep=",", collapse=";"), what=what_metrics)
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)
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-12-31")
getSymbols(tickers, src = "yahoo", from = start, to = end)
stocks = as.xts(data.frame(A = JPM[, "JPM.Adjusted"],
B = CVS[, "CVS.Adjusted"], C = TSLA[, "TSLA.Adjusted"],
E = AMZN[,"AMZN.Adjusted"]))
```
```{r}
names(stocks) <- c("JPM", "CVS", "TSLA","AMZN")
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~12/2022",
subtitle = "Among JP Morgan, CVS, Tesla, Amazon",
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~12/2022",
subtitle = "Among JPM, CVS, Tesla, Amazon",
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 Closing Price**
Row
----------------------------------
### **Analysis**
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, overall, Tesla had the highest stock closing price in 2022, having a peak rate in April however plummeting in December, below JP Morgan's rate. CVS had the most stable closing price throughout 2022. Amazon and JP Morgan have had similar fluctuations closely competing with each other throughout 2022.
## Column {data-height=1200 .tabset .tabset-fade}
### Stock Closing Price {data-width=1200}
```{r}
tickers <- c("JPM", "CVS", "TSLA", "AMZN")
ClosingPrices <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateWindow<-c("2022-01-01", "2022-12-31")
dygraph(ClosingPrices, main="Stock Closing Price", group="Stock", width='auto') %>%
dyAxis("y", label="Closing Price ($) ") %>%
dyOptions( colors = RColorBrewer::brewer.pal(4, "Set1")) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
highlightSeriesOpts = list(strokeWidth = 4)) %>%
dyRangeSelector(dateWindow=dateWindow)
```
# **Monthly Return Comparison**
Row
----------------------------------
### **Analysis**
Here is the comparison of their Monthly return in one combined plot. This chart shows all stocks monthly return in one chart, so it is easier for use to find which one has better return. 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. Compared to 3 other companies, Tesla has the highest fluctuations throughout 2022, with the least monthly return by the end of the year. CVS has a more relatively stable data in 2022.
## Column {data-height=900 overflow=auto .tabset .tabset-fade}
### Monthly Return Comparison {data-width=1500 overflow=auto}
```{r}
m.rt.JPM <- monthlyReturn(JPM)
m.rt.CVS <- monthlyReturn(CVS)
m.rt.TSLA <- monthlyReturn(TSLA)
m.rt.AMZN <- monthlyReturn(AMZN)
mg.return <- merge.xts(m.rt.JPM,m.rt.CVS, m.rt.TSLA, m.rt.AMZN)
colnames(mg.return) <- c('JP Morgan Chase & Co','CVS','Tesla','Amazon')
dateWindow<-c("2022-01-01", "2022-12-31")
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(dateWindow=dateWindow)
```
# **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 (JPM, CVS, Tesla, and Amazon) performance from Jan 1, 2022 to Sept 31, 2022, we can see:
+ `r kableExtra::text_spec("**P-E Ratio**", color = "#5c5c5c")` - JPM has the highest P-E Ratio (12.09), which means that investors are expecting higher earnings growth in the future, then followed by Tesla (3.61), CVS (3.14) and Amazon (-0.27).
+ `r kableExtra::text_spec("**EPS**", color = "#5c5c5c")` - According to EPS, Tesla has the highest one with 52.40 , which indicates how much money a company makes for each share of its stock, followed by CVS (23.28) and JPM (10.66).
+ `r kableExtra::text_spec("**Dividend Yield**", color = "#5c5c5c")` - Based on dividend yield, Amazon has the highest (38.58%), followed by Tesla (34.58%), JPM (9.57%) and CVS (8.04%), which indicates though Amazon 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, CVS is the highest, followed by JPM. Overall, from the key indicators, Tesla is a better company to invest in among others, then JPM, CVS and Amazon.
### **Trends Analysis**
Based on the above analysis and as a conservative investor, Tesla is a good company to invest in as it's steadily trending up, and JPM is also good too as it's stable and its Dividend yield is relatively high. CVS is also not bad, but may be a little risky. Amazon is not recommended to invest in.