Stock analysis is a method for investors and traders to make buying and selling decisions by studying and evaluating past and current financial data. In this dashboard, I’m going to use quantitative analysis to analyze 4 stocks (“WMT”, “TGT”, “DG”,“DLTR”) in the discount stores industry.
The objective of this laboratory is to plan, design, and create an information dashboard to support quantitative decision making. To accomplish this task, I did the following steps:
1.Understand the definition of financial statistics.
2.Identify what information/metrics will be relevant to evaluate if a
company is worth investing.
3.Scrape data from Yahoo Finance to create my visualization plan.
4.Organize and transform 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 I made based on the
visualizations that I developed.
Choose 4 companies (Walmart, Target, Dollar General and Dollar Tree) and determine which one of the four will produce the most short-term gains.
Author: Bingqing Li
Date: 2022-10-23
---
title: "Dashboard | Stock Analysis for Discount Stores"
output:
flexdashboard::flex_dashboard:
social: menu
source: embed
vertical_layout: fill
---
```{r setup, include=FALSE, source_code = TRUE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
```
**Outline** {data-orientation=rows}
=====================================
Row
-------------------------------------
### **Introduction**
Stock analysis is a method for investors and traders to make buying and selling decisions by studying and evaluating past and current financial data. In this dashboard, I'm going to use quantitative analysis to analyze 4 stocks ("WMT", "TGT", "DG","DLTR") in the discount stores industry.
### **Objective**
The objective of this laboratory is to plan, design, and create an information dashboard to support quantitative decision making. To accomplish this task, I did the following steps:
1.Understand the definition of financial statistics.
2.Identify what information/metrics will be relevant to evaluate if a company is worth investing.
3.Scrape data from Yahoo Finance to create my visualization plan.
4.Organize and transform 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 I made based on the visualizations that I developed.
### **The Decision & Rules**
Choose 4 companies (Walmart, Target, Dollar General and Dollar Tree) and determine which one of the four will produce the most short-term gains.
Row {data-height=25}
-------------------------------------
Author: Bingqing Li
Date: `r Sys.Date()`
**Over Time Analysis**
=====================================
Column {data-width=800, .tabset}
-----------------------------------------------------------------------
### Overall
```{r}
library(dygraphs)
library(xts)
library(tidyr)
stockprice_df <- read.csv('4Retailers_StockPrice.csv')
valmrs_df <- read.csv('4Retailers_ValuationMeasures.csv')
stockprice_df$ref.date <- as.Date(stockprice_df$ref.date, format='%Y-%m-%d')
sp_wider <- stockprice_df %>%
select(c( 'ref.date', 'ticker', 'price.adjusted')) %>%
pivot_wider(names_from = ticker, values_from = price.adjusted)
dygraph(xts(sp_wider[, -1], order.by=sp_wider$ref.date) ) %>%
dyAxis("y", label="Adjusted Price($)") %>%
dyOptions(axisLineWidth = 2.0, colors = c("#145DA0", "#FFAEBC", "#FFA384", "#21B6A8" )) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 1.0,
highlightSeriesOpts = list(strokeWidth = 3)) %>%
dyAxis("x", drawGrid = FALSE)
```
### Walmart
```{r}
wmt_sp <- stockprice_df %>% filter(ticker == 'WMT') %>% select(c( 'ref.date', 'price.open', 'price.high', 'price.low', 'price.close'))
# dygraph accepts only time series data
dygraph(xts(wmt_sp[,-1], order.by=wmt_sp[,1])) %>%
dyAxis("y", label = "Stock Price ($)") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector()
```
### Target
```{r}
tgt_sp <- stockprice_df %>% filter(ticker == 'TGT') %>% select(c( 'ref.date', 'price.open', 'price.high', 'price.low', 'price.close'))
# dygraph accepts only time series data
dygraph(xts(tgt_sp[,-1], order.by=tgt_sp[,1])) %>%
dyAxis("y", label = "Stock Price ($)") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector()
```
### Dollar General
```{r}
dg_sp <- stockprice_df %>% filter(ticker == 'DG') %>% select(c( 'ref.date', 'price.open', 'price.high', 'price.low', 'price.close'))
# dygraph accepts only time series data
dygraph(xts(dg_sp[,-1], order.by=dg_sp[,1])) %>%
dyAxis("y", label = "Stock Price ($)") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector()
```
### Dollar Tree
```{r}
dltr_sp <- stockprice_df %>% filter(ticker == 'DLTR') %>% select(c( 'ref.date', 'price.open', 'price.high', 'price.low', 'price.close'))
# dygraph accepts only time series data
dygraph(xts(dltr_sp[,-1], order.by=dltr_sp[,1])) %>%
dyAxis("y", label = "Stock Price ($)") %>%
dyCandlestick() %>%
dyLegend(width = 400) %>%
dyRangeSelector()
```
Column {.tabset}
-----------------------------------------------------------------------
### Takeaway
#### Stocks of discount stores slump around mid May when discount retailers provided its first-quarter earnings, and Wall Street didn't like what it saw.
* The sharp declines were sparked by a warning from retailers that they have been facing higher costs and slowing sales, both of which have been eating into their profit margins.
* Target's stock price fell by almost -30% in May, and the crash in its share price in the prior month was driven by the company's significant Q1 2022 earnings miss.
#### DG and Dollar Tree are the only 2 retailers that had a higher stock price than a year ago.
#### Target's Market Cap continued to drop over the last 12 months while that of DG and Dollar Tree is steady over the months and shows a slightly increase.
### Market Capitalization Over Time
```{r}
mkt_cap <- valmrs_df %>% filter(Metric == 'Market Cap (intraday)') %>% select(-Metric)
mkt_cap$Date <- as.Date(mkt_cap$Date, format='%Y-%m-%d')
# ticker has to be in columns for dygraph
mkt_cap_wider <- mkt_cap %>%
pivot_wider(names_from = Ticker, values_from = Values)
dygraph(xts(mkt_cap_wider[, -1], order.by=mkt_cap_wider$Date) ) %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Set2"),drawPoints = TRUE, pointSize = 2) %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Mkt Cap ($B)") %>%
dyHighlight(highlightSeriesOpts = list(strokeWidth = 3))
```
### Enterprise Value/EBITDA Over Time
```{r}
library(tidyr)
ev_ebitda <- valmrs_df %>% filter(Metric == 'Enterprise Value/EBITDA') %>% select(-Metric)
ev_ebitda$Date <- as.Date(ev_ebitda$Date, format='%Y-%m-%d')
ev_ebitda_wider <- ev_ebitda %>%
pivot_wider(names_from = Ticker, values_from = Values)
dygraph(xts(ev_ebitda_wider[, -1], order.by=mkt_cap_wider$Date) ) %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Set2"),drawPoints = TRUE, pointSize = 2) %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Mkt Cap ($B)") %>%
dyHighlight(highlightSeriesOpts = list(strokeWidth = 3))
```
**Fundamental Stock Analysis** {data-orientation=columns}
====================================================
## {.sidebar}
**Insights**
* P/E: A high P/E ratio could mean that a company's stock is overvalued, or that investors are expecting high growth rates in the future. Dollar General has a relatively stable P/E ratio over time. Target has the lowest P/E ratio among its peers.
* PEG: Dollar Tree's PEG is a little bit under 1, which indicates it's a good investment because it's undervalued. DG has a fairly valued PEG ratio (under 2).
* current ratio: A current ratio that is lower than the industry average may indicate a higher risk of distress or default. Similarly, if a company has a very high current ratio compared with its peer group, it indicates that management may not be using its assets efficiently. DG's current ratio = 1, which indicates a pretty good use of their assets.
* DG also has the highest Profile Margin and ROE.
* In summary, **DG** has a good financial performance in every important metrics. So I'll pick DG as my stock for short-term investment.
Column
-------------------------
### **Financial Metrics Definition**
+ `r kableExtra::text_spec("**P/E Ratio**", color = "#5c5c5c")`: The price-to-earnings ratio is the ratio for valuing a company that measures its current share price relative to its earnings per share (EPS). The P/E ratio helps one determine whether a stock is overvalued or undervalued.
+ `r kableExtra::text_spec("**PEG**", color = "#5c5c5c")`: The PEG ratio is used to determine a stock's value while also factoring in the company's expected earnings growth, and it is thought to provide a more complete picture than the more standard P/E ratio.
+ `r kableExtra::text_spec("**Current Ratio**", color = "#5c5c5c")`: The current ratio is a liquidity ratio that measures a company’s ability to pay short-term obligations or those due within one year.
+ `r kableExtra::text_spec("**Profit Margin**", color = "#5c5c5c")`: Profit margin is one of the commonly used profitability ratios to gauge the degree to which a company or a business activity makes money. It represents what percentage of sales has turned into profits.
+ `r kableExtra::text_spec("**ROE**", color = "#5c5c5c")`: Return on Equity measures a corporation's profitability. It reveals how efficient a company is at generating profits.
Column {.tabset}
-------------------------------------
### P/E
```{r}
pe <- valmrs_df %>% filter(Metric == 'Trailing P/E') %>% select(-Metric)
pe$Date <- as.Date(pe$Date, format='%Y-%m-%d')
# ticker has to be in columns for dygraph
pe_wider <- pe %>%
pivot_wider(names_from = Ticker, values_from = Values)
dygraph(xts(pe_wider[, -1], order.by=pe_wider$Date) ) %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Set2"),drawPoints = TRUE, pointSize = 2) %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Mkt Cap ($B)") %>%
dyHighlight(highlightSeriesOpts = list(strokeWidth = 3))
```
### PEG
```{r}
peg <- valmrs_df %>% filter(Metric == 'PEG Ratio (5 yr expected)') %>% select(-Metric)
peg$Date <- as.Date(peg$Date, format='%Y-%m-%d')
# ticker has to be in columns for dygraph
peg_wider <- peg %>%
pivot_wider(names_from = Ticker, values_from = Values)
dygraph(xts(peg_wider[, -1], order.by=peg_wider$Date) ) %>%
dyOptions(colors = RColorBrewer::brewer.pal(4, "Set2"),drawPoints = TRUE, pointSize = 2) %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Mkt Cap ($B)") %>%
dyHighlight(highlightSeriesOpts = list(strokeWidth = 3))
```
### Current Ratio
```{r}
library(ggplot2)
library(dplyr)
library(tidyr)
metrics_df <- read.csv('4Retailers_OtherStats.csv')
metrics_df <- metrics_df %>%
mutate(Ticker = ordered(Ticker))
cr <- metrics_df %>% filter(Metric == 'Current Ratio (mrq)') %>% select(-Metric)
cr$Value <- as.numeric(cr$Value)
ggplot(cr,aes(x=Ticker,y=Value,fill=Ticker))+
geom_bar(stat = "identity")+
labs(x="Company name",y="Current Ratio (mrq)")+
scale_fill_manual(name = "Company",
labels = c("DG","DLTR","TGT","WMT"),
values = c("#145DA0", "#FFAEBC", "#FFA384", "#21B6A8")) +
theme_bw()
```
### Profit Margin
```{r}
pm <- metrics_df %>% filter(Metric == 'Profit Margin') %>% select(-Metric)
pm$Value <- as.numeric(gsub('%','',pm$Value))
ggplot(pm,aes(x=Ticker,y=Value,fill=Ticker))+
geom_bar(stat = "identity")+
labs(x="Company name",y="Profit Margin")+
scale_fill_manual(name = "Company",
labels = c("DG","DLTR","TGT","WMT"),
values = c("#145DA0", "#FFAEBC", "#FFA384", "#21B6A8")) +
theme_bw()
```
### Return on Equity
```{r}
roe <- metrics_df %>% filter(Metric == 'Return on Equity (ttm)') %>% select(-Metric)
roe$Value <- as.numeric(gsub('%','',roe$Value))
ggplot(roe,aes(x=Ticker,y=Value,fill=Ticker))+
geom_bar(stat = "identity")+
labs(x="Company name",y="Return on Equity (ttm)")+
scale_fill_manual(name = "Company",
labels = c("DG","DLTR","TGT","WMT"),
values = c("#145DA0", "#FFAEBC", "#FFA384", "#21B6A8")) +
theme_bw()
```