Financials(KPI)

OHLC

The open-high-low-close chart will illustrate movements in price of financial instrument over a period of time. In this kernel we will be exercising dates from “2010-01-01” to “2020-06-16”.

Column

Google

Tesla

Wells Fargo

Amazon

30day OHLC

The 30 day open-high-low-close chart will illustrate movements in price of financial instrument over a period of 30 days time.

Column

Google

Tesla

Wells Fargo

Amazon

Daily Returns

Column

Google

Tesla

Wells Fargo

Amazon

Frequency(Daily Returns)

Column

Google

Tesla

Wells Fargo

Amazon

Price Chart

Column

Price Chart for all the picked stocks together for last one year period i.e from “2019-06-17” to = “2020-06-17”.

Monthly Returns

Column

Google

Tesla

Wells Fargo

Amazon

---
title: "Investments Dash"
author: "Kowshik Kumar B"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: [ "menu" ]
    source: embed
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dygraphs)
library(pdfetch)
library(ggplot2)
library(timeSeries)
library(gridExtra)
library(scales)
library(Quandl)
library(quantmod)
library(zoo)
library(fBasics)
library(evir)
library(TH.data)
library(shiny)
library(tidyverse)
library(tidyquant)
library(timetk)
```


# Conclusion {.sidebar}

* This Dashboard performs different visualizations for data analysis to optimize investments for short term returns of four different stocks selected at random.

* The four stocks choosen randomly for demonstration are Google, Tesla, Wells Fargo and Amazon.

* This period of Stocks vs Economy is trending. However, these visualizations are just for experimental understanding the financial markets at the moment.

* Out of the selected stocks for analysis, most of the stocks like Google, Tesla and Amazon are running at high times at the moment except for the Wells Fargo.

* From analysis, we can clearly visualize all the stocks are running with high volatility at the current moment.

* From the frequency of daily returns, we can clearly interpret that the selected stocks for analysis are having less room for variation across the mean while Wells Fargo returns having more room for variation across the mean.

* Hence, Wells Fargo would be a good investment out of all the selected stocks which would bring short term returns while the price being optimal. However, the markets are at high risk at the moment as the economic activity is low (Source: Purchasing managers index) while the markets are at all high high which makes no-sense.


# Financials(KPI)

```{r}
what_metrics <- yahooQF(c("Price/Sales","P/E Ratio","Price/EPS Estimate Next Year","PEG Ratio","Dividend Yield", "Market Capitalization"))
tickers <- c("AMZN", "GOOG", "TSLA","MSFT","WFC","AAPL","FB","NVDA","CSCO","NFLX","INTC","ADBE","TXN","T","VZ","QCOM","XLNX","MXIM","GILD","CTXS","FISV","LULU","NTAP","ORLY","PEP","ZM","UAL","WMT","COST","PFE","HTZ","PYPL","WBA","CHTR","BA","EXC","MDLZ","XOM","ISRG","HD","DIS","DAL","HPQ","XRX","DELL","ORCL","IBM","WDAY","F","KO","PG","GE","DADA","NET","KC","DAO","YY","ENPH","HRB","CLR","CPRI","FIZZ","TNDM","APNHY","SPOT","CHGG","SE","SFTBY","VVV","NVS","CLDR","PZZA","SNAP","INSP","W","KGFHY","SDGR","ERI","NOK","CCL","MRO","IQ","VIAC","SQ","BYND","MGM","NKLA","CMCSA","MU","JPM","INO","UBER","KR","INFY","BMY","MRNA","TWTR","UA","NKE","LOW")
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")

#Persist this to the csv file
#write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
DT::datatable(metrics)
```

# OHLC

The open-high-low-close chart will illustrate movements in price of financial instrument over a period of time. In this kernel we will be exercising dates from "2010-01-01" to "2020-06-16".

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

```{r include=FALSE}
getSymbols("AMZN",from="2010-01-01",to="2020-06-17")
getSymbols("GOOG",from="2010-01-01",to="2020-06-17")
getSymbols("TSLA",from="2010-01-01",to="2020-06-17")
getSymbols("MSFT",from="2010-01-01",to="2020-06-17")
getSymbols("WFC",from="2010-01-01",to="2020-06-17")
getSymbols("AAPL",from="2010-01-01",to="2020-06-17")
getSymbols("FB",from="2010-01-01",to="2020-06-17")
```

### Google
```{r}
GOOG_ohlc<-dygraph(OHLC(GOOG))
dyCandlestick(GOOG_ohlc)
```

### Tesla
```{r}
TSLA_ohlc<-dygraph(OHLC(TSLA))
dyCandlestick(TSLA_ohlc)
```

### Wells Fargo
```{r}
WFC_ohlc<-dygraph(OHLC(WFC))
dyCandlestick(WFC_ohlc)
```

### Amazon
```{r}
AMZN_ohlc<-dygraph(OHLC(AMZN))
dyCandlestick(AMZN_ohlc)
```

# 30day OHLC

The 30 day open-high-low-close chart will illustrate movements in price of financial instrument over a period of 30 days time.

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

### Google
```{r}
GOOG_last30 <- tail(GOOG, n=30)
dyCandlestick(dygraph(OHLC(GOOG_last30)))
```

### Tesla
```{r}
TSLA_last30 <- tail(TSLA, n=30)
dyCandlestick(dygraph(OHLC(TSLA_last30)))
```

### Wells Fargo
```{r}
WFC_last30 <- tail(WFC, n=30)
dyCandlestick(dygraph(OHLC(WFC_last30)))
```

### Amazon
```{r}
AMZN_last30 <- tail(AMZN, n=30)
dyCandlestick(dygraph(OHLC(AMZN_last30)))
```


# Daily Returns


Column {.tabset}
-----------------------------------------------------------------------
```{r include=FALSE}
GOOG_last1yr <- tq_get("GOOG",from = '2019-06-17',to = "2020-06-17",get = "stock.prices") 
TSLA_last1yr <- tq_get("TSLA",from = '2019-06-17',to = "2020-06-17",get = "stock.prices") 
WFC_last1yr <- tq_get("WFC",from = '2019-06-17',to = "2020-06-17",get = "stock.prices") 
AMZN_last1yr <- tq_get("AMZN",from = '2019-06-17',to = "2020-06-17",get = "stock.prices") 
GOOG_daily_returns<-tq_transmute(GOOG_last1yr,select = adjusted, mutate_fun = periodReturn,period="daily",col_rename ="GOOG_returns")
TSLA_daily_returns<-tq_transmute(TSLA_last1yr,select = adjusted, mutate_fun = periodReturn,period="daily",col_rename ="TSLA_returns")
WFC_daily_returns<-tq_transmute(WFC_last1yr,select = adjusted, mutate_fun = periodReturn,period="daily",col_rename ="WFC_returns")
AMZN_daily_returns<-tq_transmute(AMZN_last1yr,select = adjusted, mutate_fun = periodReturn,period="daily",col_rename ="AMZN_returns")
```

### Google

```{r}
 ggplot(GOOG_daily_returns,aes(x = date, y = GOOG_returns)) +
  geom_line() +
  theme_classic() +
  labs(x = "Date", y = "Daily returns") +
  ggtitle("Daily Returns for Netflix") +
  scale_x_date(date_breaks = "years", date_labels = "%Y") +
  scale_y_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent)
```

### Tesla

```{r}
 ggplot(TSLA_daily_returns,aes(x = date, y = TSLA_returns)) +
  geom_line() +
  theme_classic() +
  labs(x = "Date", y = "Daily returns") +
  ggtitle("Daily Returns for Netflix") +
  scale_x_date(date_breaks = "years", date_labels = "%Y") +
  scale_y_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent)
```

### Wells Fargo

```{r}
 ggplot(WFC_daily_returns,aes(x = date, y = WFC_returns)) +
  geom_line() +
  theme_classic() +
  labs(x = "Date", y = "Daily returns") +
  ggtitle("Daily Returns for Netflix") +
  scale_x_date(date_breaks = "years", date_labels = "%Y") +
  scale_y_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent)
```

### Amazon

```{r}
 ggplot(AMZN_daily_returns,aes(x = date, y = AMZN_returns)) +
  geom_line() +
  theme_classic() +
  labs(x = "Date", y = "Daily returns") +
  ggtitle("Daily Returns for Netflix") +
  scale_x_date(date_breaks = "years", date_labels = "%Y") +
  scale_y_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent)
```

# Frequency(Daily Returns)

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

### Google

```{r}
ggplot(GOOG_daily_returns,aes(x = GOOG_returns)) +
  geom_histogram(binwidth = 0.015) +
  theme_classic() +
  labs(x = "Daily returns") +
  ggtitle("Frequncy of Daily Returns for Google") +
  scale_x_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent) +
  annotate(geom = 'text', x = -0.30, y= 200, label = "Extremely\nnegative\nreturns") +
  annotate(geom = 'segment', x = -0.305, xend = -0.35,  y = 120, yend = 20, color = 'red', arrow = arrow()) +
  annotate(geom = 'segment', x = 0.405, xend = 0.42,  y = 120, 
           yend = 20, color = 'blue', arrow = arrow(type = "open")) +
  annotate(geom = 'text', x = 0.430, y = 200, label = "Extremely\npositive\nreturns")
```

### Tesla

```{r}
 ggplot(TSLA_daily_returns,aes(x = TSLA_returns)) +
  geom_histogram(binwidth = 0.015) +
  theme_classic() +
  labs(x = "Daily returns") +
  ggtitle("Frequncy of Daily Returns for Tesla") +
  scale_x_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent) +
  annotate(geom = 'text', x = -0.30, y= 200, label = "Extremely\nnegative\nreturns") +
  annotate(geom = 'segment', x = -0.305, xend = -0.35,  y = 120, yend = 20, color = 'red', arrow = arrow()) +
  annotate(geom = 'segment', x = 0.405, xend = 0.42,  y = 120, 
           yend = 20, color = 'blue', arrow = arrow(type = "open")) +
  annotate(geom = 'text', x = 0.430, y = 200, label = "Extremely\npositive\nreturns")
```

### Wells Fargo

```{r}
ggplot(WFC_daily_returns,aes(x = WFC_returns)) +
  geom_histogram(binwidth = 0.015) +
  theme_classic() +
  labs(x = "Daily returns") +
  ggtitle("Frequncy of Daily Returns for Wells Fargo") +
  scale_x_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent) +
  annotate(geom = 'text', x = -0.30, y= 200, label = "Extremely\nnegative\nreturns") +
  annotate(geom = 'segment', x = -0.305, xend = -0.35,  y = 120, yend = 20, color = 'red', arrow = arrow()) +
  annotate(geom = 'segment', x = 0.405, xend = 0.42,  y = 120, 
           yend = 20, color = 'blue', arrow = arrow(type = "open")) +
  annotate(geom = 'text', x = 0.430, y = 200, label = "Extremely\npositive\nreturns")
```

### Amazon

```{r}
ggplot(AMZN_daily_returns,aes(x = AMZN_returns)) +
  geom_histogram(binwidth = 0.015) +
  theme_classic() +
  labs(x = "Daily returns") +
  ggtitle("Frequncy of Daily Returns for Amazon") +
  scale_x_continuous(breaks = seq(-0.5,0.6,0.05),
                     labels = scales::percent) +
  annotate(geom = 'text', x = -0.30, y= 200, label = "Extremely\nnegative\nreturns") +
  annotate(geom = 'segment', x = -0.305, xend = -0.35,  y = 120, yend = 20, color = 'red', arrow = arrow()) +
  annotate(geom = 'segment', x = 0.405, xend = 0.42,  y = 120, 
           yend = 20, color = 'blue', arrow = arrow(type = "open")) +
  annotate(geom = 'text', x = 0.430, y = 200, label = "Extremely\npositive\nreturns")
```


# Price Chart

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

Price Chart for all the picked stocks together for last one year period i.e from "2019-06-17" to = "2020-06-17".

```{r}
stocks_picked <- tq_get(c("GOOG","TSLA","WFC","AMZN"),from = "2019-06-17",to = "2020-06-17",get = "stock.prices")
ggplot(stocks_picked,aes(x = date, y = adjusted, color = symbol)) +
  geom_line() +
  ggtitle("Price chart for all picked stocks")
```

# Monthly Returns

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

```{r include=FALSE}
GOOG_monthly_returns<-monthlyReturn(GOOG)
TSLA_monthly_returns<-monthlyReturn(TSLA)
WFC_monthly_returns<-monthlyReturn(WFC)
AMZN_monthly_returns<-monthlyReturn(AMZN)

```

### Google

```{r}
dygraph(GOOG_monthly_returns)
```

### Tesla

```{r}
dygraph(TSLA_monthly_returns)
```

### Wells Fargo

```{r}
dygraph(WFC_monthly_returns)
```

### Amazon

```{r}
dygraph(AMZN_monthly_returns)
```