Candlestick Charts

Column

Walmart Stock price - WMT

Target Stock price - TGT

Walgreen Stock price - WBA

PriceSmart Stock price -PSMT

Row {.tabset .tabset-fade}


Profitibility Ratio Analysis

Column

     P.E.Ratio Price.EPS.Estimate.Next.Year X52.week.High X52.week.Low
TGT   11.99901                     12.89305         90.39        60.15
WMT   54.14049                     20.08475        108.18        81.78
WBA   13.17087                     10.14306         86.31        59.07
PSMT  28.82056                     18.85886         94.45        55.53

---
title: "ANLY512 Stock Price Dashboard of Four Retail Companies"
author: "Shenxiao Li(236500),Li Li(236090)"
date: "01/26/2019"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(xts)
library(plyr)
library(quantmod)
library(dygraphs)
library(TTR)
library(DT)
library(flexdashboard)
library(shiny)
library(ggplot2)
```

Candlestick Charts {data-orientation=columns}
==========================================================================

Sidebar {.sidebar}
-----------------------------------------------------------------------

### Introduction & Stock Price Analysis 


  This dashboard includes basic financial information for four stocks: Walmart (WMT), Target (TGT), Walgreens (WBA), and PriceSmart (PSMT) in retail industry over a year from 01/01/2018 to 12/31/2018

Column {data-height=400}
-----------------------------------------------------------------------


### Walmart Stock price - WMT

```{r}
data<-getSymbols(c("TGT","WMT","WBA","PSMT"),from="2018-1-1",to="2018-12-31",auto.assign = TRUE)
what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low"))
tickers<-c("TGT","WMT","WBA","PSMT")
closePrice = do.call(merge, lapply(tickers, function(x) Cl(get(x))))
colnames(closePrice) = tickers
colnames(WMT) = c("Open", "High", "Low", "Close", "Volume.in.Million", "Adjusted")
mov.avgs<-function(stock.close){
  x<-data.frame(stock.close, SMA(stock.close, 50), SMA(stock.close, 25))
  colnames(x)<-c(names(stock.close), 'sma_50','sma_25')
  #x<-x[complete.cases(x$sma_50),]
  return(x)
}

closePriceWithMA<-lapply(closePrice, mov.avgs)
WalmartCandleStick = cbind(WMT[,-6], closePriceWithMA$WMT$sma_50, closePriceWithMA$WMT$sma_25)
colnames(WalmartCandleStick)[6] = "sma_50"
colnames(WalmartCandleStick)[7] = "sma_25"
WalmartCandleStick<-data.frame(WalmartCandleStick)
dygraph(WalmartCandleStick, main = "Walmart") %>% 
  dyUnzoom() %>%
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= c(RColorBrewer::brewer.pal(5, "Set2"), "red", "green")) %>%
  dyHighlight(highlightCircleSize = 2, highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyRangeSelector(height = 20) %>% 
  dyLegend(show = "onmouseover")
```


### Target Stock price - TGT

```{r}
data<-getSymbols(c("TGT","WMT","WBA","PSMT"),from="2018-1-1",to="2018-12-31",auto.assign = TRUE)
what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low"))
tickers<-c("TGT","WMT","WBA","PSMT")
closePrice = do.call(merge, lapply(tickers, function(x) Cl(get(x))))
colnames(closePrice) = tickers
colnames(TGT) = c("Open", "High", "Low", "Close", "Volume.in.Million", "Adjusted")
mov.avgs<-function(stock.close){
  x<-data.frame(stock.close, SMA(stock.close, 50), SMA(stock.close, 25))
  colnames(x)<-c(names(stock.close), 'sma_50','sma_25')
  #x<-x[complete.cases(x$sma_50),]
  return(x)
}

closePriceWithMA<-lapply(closePrice, mov.avgs)
TargetCandleStick = cbind(TGT[,-6], closePriceWithMA$TGT$sma_50, closePriceWithMA$TGT$sma_25)
colnames(TargetCandleStick)[6] = "sma_50"
colnames(TargetCandleStick)[7] = "sma_25"
TargetCandleStick<-data.frame(TargetCandleStick)
dygraph(TargetCandleStick, main = "Target") %>% 
  dyUnzoom() %>%
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= c(RColorBrewer::brewer.pal(5, "Set2"), "red", "green")) %>%
  dyHighlight(highlightCircleSize = 2, highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyRangeSelector(height = 20) %>% 
  dyLegend(show = "onmouseover")

```

### Walgreen Stock price - WBA
```{r}
data<-getSymbols(c("TGT","WMT","WBA","PSMT"),from="2018-1-1",to="2018-12-31",auto.assign = TRUE)
what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low"))
tickers<-c("TGT","WMT","WBA","PSMT")
closePrice = do.call(merge, lapply(tickers, function(x) Cl(get(x))))
colnames(closePrice) = tickers
colnames(WBA) = c("Open", "High", "Low", "Close", "Volume.in.Million", "Adjusted")
mov.avgs<-function(stock.close){
  x<-data.frame(stock.close, SMA(stock.close, 50), SMA(stock.close, 25))
  colnames(x)<-c(names(stock.close), 'sma_50','sma_25')
  #x<-x[complete.cases(x$sma_50),]
  return(x)
}

closePriceWithMA<-lapply(closePrice, mov.avgs)
WalgreenCandleStick = cbind(WBA[,-6], closePriceWithMA$WBA$sma_50, closePriceWithMA$WBA$sma_25)
colnames(WalgreenCandleStick)[6] = "sma_50"
colnames(WalgreenCandleStick)[7] = "sma_25"
WalgreenCandleStick<-data.frame(WalgreenCandleStick)
dygraph(WalgreenCandleStick, main = "Walgreen") %>% 
  dyUnzoom() %>%
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= c(RColorBrewer::brewer.pal(5, "Set2"), "red", "green")) %>%
  dyHighlight(highlightCircleSize = 2, highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyRangeSelector(height = 20) %>% 
  dyLegend(show = "onmouseover")

```

### PriceSmart Stock price -PSMT 
```{r}
data<-getSymbols(c("TGT","WMT","WBA","PSMT"),from="2018-1-1",to="2018-12-31",auto.assign = TRUE)
what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low"))
tickers<-c("TGT","WMT","WBA","PSMT")
closePrice = do.call(merge, lapply(tickers, function(x) Cl(get(x))))
colnames(closePrice) = tickers
colnames(PSMT) = c("Open", "High", "Low", "Close", "Volume.in.Million", "Adjusted")
mov.avgs<-function(stock.close){
  x<-data.frame(stock.close, SMA(stock.close, 50), SMA(stock.close, 25))
  colnames(x)<-c(names(stock.close), 'sma_50','sma_25')
  #x<-x[complete.cases(x$sma_50),]
  return(x)
}

closePriceWithMA<-lapply(closePrice, mov.avgs)
PriceSmartCandleStick = cbind(PSMT[,-6], closePriceWithMA$PSMT$sma_50, closePriceWithMA$PSMT$sma_25)
colnames(PriceSmartCandleStick)[6] = "sma_50"
colnames(PriceSmartCandleStick)[7] = "sma_25"
PriceSmartCandleStick<-data.frame(PriceSmartCandleStick)
dygraph(PriceSmartCandleStick, main = "PriceSmart") %>% 
  dyUnzoom() %>%
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= c(RColorBrewer::brewer.pal(5, "Set2"), "red", "green")) %>%
  dyHighlight(highlightCircleSize = 2, highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyRangeSelector(height = 20) %>% 
  dyLegend(show = "onmouseover")

```

Row {.tabset .tabset-fade}

-----------------------------------------------------------------------

Profitibility Ratio Analysis {data-orientation=columns}
==========================================================================

Sidebar {.sidebar}
-----------------------------------------------------------------------

### Profitibility Ratio Analysis


  We use P/E Ratio","Price/EPS Estimate Next Year","52-week High"and "52-week Low to measure the profitibility for each company. 
  
  
  
Column {data-height=600}
-----------------------------------------------------------------------

```{r}
what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low"))
tickers<-c("TGT","WMT","WBA","PSMT")
metrics <- getQuote(paste(tickers, sep="", collapse=";"),what=yahooQF(c("P/E Ratio","Price/EPS Estimate Next Year","52-week High","52-week Low")))
metrics<-data.frame(metrics[-1])
metrics1<-cbind(metrics,c("TGT","WMT","WBA","PSMT"))
colnames(metrics1) = c("PE.Ratio", "Price.EPS.Estimate.Next.Year", "High", "Low","Name")
metrics1$PE.Ratio = round(metrics1$PE.Ratio, digits = 2)
head(metrics)



barplot(metrics1$Price.EPS.Estimate.Next.Year, names.arg=c("TGT","WMT","WBA","PSMT"), ylab="Price.EPS.Estimate.Next.Year & PE.Ratio",ylim=c(0,55))
par(new=TRUE)
plot(metrics1$PE.Ratio,ylim=c(0,55),axes=FALSE,xlab="Stock",ylab="")


plot(metrics1$High~metrics1$Name,ylab="52 Week High & Low", ylim=c(40,110), xlab="Stock",type="o", col="red", names.arg=c("TGT","WMT","WBA","PSMT"))
par(new=TRUE)
plot(metrics1$Low~metrics1$Name,type="o",col="green",ylim=c(40,110),axes=FALSE,xlab="",ylab="")

```