Stock Price

Row


Watch the Moving Averages

As the goal is to maximize short-term investment, it would be helpful to understand the short-term performance within 2 months, whether the stock is trending up or down. From the 4 charts, Tesla has the most steep up trends for the short term. As a bigger part of price shown as blue, meaning the price went down after open, it is recommended to sell when the market opens after holding the stock for short-term.

Row

Facebook

TESLA

Row

P&G

General Motor

Key Ratios

Row


Summary

Price to Cash Flow ratio compares the company’s market value to its cash flow. A high P/CF ratio tells us that the company’s stock is higher than the cash flow it is able to generate. Price to Earning Ratio(P/E) on the other hand, tells investors how in general other investors think about the value of the stock. It gives directional information of the market but it can also be the market is overvaluing the stock. Together with the ability of generating cash flow, we think, Tesla doesn’t have a high P/E ratio but the cashflow ratio is way lower. GM is trending down on P/E ratio, P&G is trending up, while cash flow doesn’t match, facebook is showing stable for the recent 2 years.

Row

Facebook

Tesla

Row

P&G

GM

Earnings Per Share

Row


Summary

Earning per share reflects the portion of a company’s profit allocated to each share of common stock. Together valued with Net income, we are able to assess the profitbility with the efficiency. From the chart, it it seen, tech company in general returns earning per share with a smaller amount of income. Therefore they are better at utilizing their resourses and generate more growth in short term.

Row

Facebook

Tesla

Row

P&G

GM

---
title: "Lab1 Dashboard"
author: "Yijia He 223346"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---
# Intro text {.sidebar data-width=320}

## Context
This lab looks into the financial performance of 4 companies - **P&G(PG), GM(GM), Tesla(TSLA), Facebook(FB)**, each representing CPG, traditional automotive manufacturer, high-tech automotive manufacturer, internet. The goal is to identify the which one of the four will produce the most short term gains. 


## Executive Summary
Among the 4 stocks, **invest in Tesla in the short term**. The most important reason is **it's showing up a clear growth trend for the recent period**. And upon the company's earning per share and net income, it demonstrates a good utilization of resources the shows some promises to continuous growth. **However, as the company's price to cash flow ratio is way lower than its P/E ratio, the stock price can be at risk once anything happened to its cashflow**. It is recommended close monitor should be placed on in case any immediate action needed. Once sales is neede, upon historical data, since the price usually went down after opening, it is recommended to sell when the market is opened.


```{r, include=FALSE}
# library and data loading
knitr::opts_chunk$set(cache = TRUE)

# load required library
library(flexdashboard)
library(highcharter)
library(viridisLite)
library(ggplot2)
library(tidyquant)
library(rJava)
library(XLConnect)
library(DT)

# obtaining financial data from R
#data1 = tq_get("NFLX",get = "stock.prices")
#sp_500 = tq_index("SP500") %>%
#  tq_get(get = "stock.prices")

# financial data calculation
#tq_transmute_fun_options()
```

Stock Price
=======================================================================

```{r setup, include=FALSE}

# obtaining stock price using tidyquant
FB <- tq_get("FB"); FB <- FB[FB$date >= "2017-10-01",]
TSLA <- tq_get("TSLA"); TSLA <- TSLA[TSLA$date >= "2017-10-01",]
GM <- tq_get("GM"); GM <- GM[GM$date >= "2017-10-01",]
PG <- tq_get("PG"); PG <- PG[PG$date >= "2017-10-01",]
```

Row {data-height=120}
-----------------------------------------------------------------------
***
### Watch the Moving Averages
As the goal is to maximize short-term investment, it would be helpful to understand the short-term performance within 2 months, whether the stock is trending up or down. From the 4 charts, **Tesla has the most steep up trends for the short term**. As a bigger part of price shown as blue, meaning the price went down after open, it is recommended to **sell when the market opens** after holding the stock for short-term.


Row {data-height=400}
-----------------------------------------------------------------------
### Facebook
```{r}
FB %>%
    ggplot(aes(x = date, y = close)) +
    geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
    geom_ma(color = "darkgreen") +
    coord_x_date(xlim = c(today() - weeks(8), today()),
                 ylim = c(100, 250)) +
    labs(x = 'Date', y = 'Stock Price')
```

### TESLA
```{r}
TSLA %>%
    ggplot(aes(x = date, y = close)) +
    geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
    geom_ma(color = "darkgreen") +
    coord_x_date(xlim = c(today() - weeks(8), today()),
                 ylim = c(240, 400)) +
    labs(x = 'Date', y = 'Stock Price')
```

Row {data-height=400}
-----------------------------------------------------------------------
### P&G 
```{r}
PG %>%
    ggplot(aes(x = date, y = close)) +
    geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
    geom_ma(color = "darkgreen") + 
    coord_x_date(xlim = c(today() - weeks(8), today()),
                 ylim = c(70, 100)) +
    labs(x = 'Date', y = 'Stock Price')
```

### General Motor
```{r}
GM %>%
    ggplot(aes(x = date, y = close)) +
    geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
    geom_ma(color = "darkgreen") +
    coord_x_date(xlim = c(today() - weeks(8), today()),
                 ylim = c(30, 50)) +
    labs(x = 'Date', y = 'Stock Price')
```


Key Ratios
=======================================================================
```{r, include=FALSE}

# obtaining key ratios using tidyquant
fb_key_ratios <- tq_get("FB", get = "key.ratios")
tsla_key_ratios <- tq_get("TSLA", get = "key.ratios")
gm_key_ratios <- tq_get("GM", get = "key.ratios")
pg_key_ratios <- tq_get("PG", get = "key.ratios")
```

Row {data-height=160}
-----------------------------------------------------------------------
***
### Summary
**Price to Cash Flow ratio compares the company's market value to its cash flow**. A high P/CF ratio tells us that the company's stock is higher than the cash flow it is able to generate. **Price to Earning Ratio(P/E) on the other hand, tells investors how in general other investors think about the value of the stock**. It gives directional information of the market but it can also be the market is overvaluing the stock. Together with the ability of generating cash flow, we think, Tesla doesn't have a high P/E ratio but the cashflow ratio is way lower. GM is trending down on P/E ratio, P&G is trending up, while cash flow doesn't match, facebook is showing stable for the recent 2 years.


Row {data-height=400}
-----------------------------------------------------------------------
### Facebook
```{r}
fb_valueation_ratios <- fb_key_ratios %>%
    filter(section == "Valuation Ratios") %>%
    unnest() %>%
    filter(date >= '2013-01-01') %>%
    filter(category == "Price to Earnings" | category == "Price to Cash Flow")

fb_valueation_ratios %>%
    ggplot(aes(x = date, y = value, color = category)) +
    geom_line(size = 1) +
    labs(title = "5-Year Historical Valuation Ratios for Facebook", x = "Year", y = "Ratios",
         color = "") +
    theme_tq()
```

### Tesla
```{r}
tsla_valueation_ratios <- tsla_key_ratios %>%
    filter(section == "Valuation Ratios") %>%
    unnest() %>%
    filter(date >= '2013-01-01') %>%
    filter(category == "Price to Earnings" | category == "Price to Cash Flow")

tsla_valueation_ratios %>%
    ggplot(aes(x = date, y = value, color = category)) +
    geom_line(size = 1) +
    labs(title = "5-Year Historical Valuation Ratios for Tesla", x = "Year", y = "Ratios",
         color = "") +
    theme_tq()
```

Row {data-height=400}
-------------------------------------
### P&G
```{r}
pg_valueation_ratios <- pg_key_ratios %>%
    filter(section == "Valuation Ratios") %>%
    unnest() %>%
    filter(date >= '2013-01-01') %>%
    filter(category == "Price to Earnings" | category == "Price to Cash Flow")

pg_valueation_ratios %>%
    ggplot(aes(x = date, y = value, color = category)) +
    geom_line(size = 1) +
    labs(title = "5-Year Historical Valuation Ratios for P&G", x = "Year", y = "Ratios",
         color = "") +
    theme_tq()
```  

### GM
```{r}
gm_valueation_ratios <- gm_key_ratios %>%
    filter(section == "Valuation Ratios") %>%
    unnest() %>%
    filter(date >= '2013-01-01') %>%
    filter(category == "Price to Earnings" | category == "Price to Cash Flow")

gm_valueation_ratios %>%
    ggplot(aes(x = date, y = value, color = category)) +
    geom_line(size = 1) +
    labs(title = "5-Year Historical Valuation Ratios for General Motors", x = "Year", y = "Ratios",
         color = "") +
    theme_tq()
```

Earnings Per Share
=======================================================================

Row {data-height=120}
-----------------------------------------------------------------------
***
### Summary
Earning per share reflects the portion of a company's profit allocated to each share of common stock. Together valued with Net income, we are able to assess the profitbility with the efficiency. From the chart, it it seen, **tech company in general returns earning per share with a smaller amount of income. Therefore they are better at utilizing their resourses and generate more growth in short term**.


Row {data-height=400}
-----------------------------------------------------------------------
### Facebook
```{r}
fb_growth_ratios <- fb_key_ratios %>%
    filter(section == "Financials") %>%
    unnest() %>%
    filter(category == "Earnings Per Share USD" | category == 'Net Income USD Mil') %>%
    filter(date >= '2011-01-01')

fb_growth_ratios %>%
    ggplot(aes(x = date, y = value)) +
    facet_grid(category~., scale="free") +
    geom_line()  + 
    labs(title = "Efficiency in Investment Return", x = "Year", y = "USD") +
    theme_tq() +
    scale_color_tq() 
```

### Tesla
```{r}
tsla_growth_ratios <- tsla_key_ratios %>%
    filter(section == "Financials") %>%
    unnest() %>%
    filter(category == "Earnings Per Share USD" | category == 'Net Income USD Mil') %>%
    filter(date >= '2011-01-01')

tsla_growth_ratios %>%
    ggplot(aes(x = date, y = value)) +
    facet_grid(category~., scale="free") +
    geom_line()  + 
    labs(title = "Efficiency in Investment Return", x = "Year", y = "USD") +
    theme_tq() +
    scale_color_tq() 
```

Row {data-height=400}
-------------------------------------
### P&G
```{r}
pg_growth_ratios <- pg_key_ratios %>%
    filter(section == "Financials") %>%
    unnest() %>%
    filter(category == "Earnings Per Share USD" | category == 'Net Income USD Mil') %>%
    filter(date >= '2011-01-01')

pg_growth_ratios %>%
    ggplot(aes(x = date, y = value)) +
    facet_grid(category~., scale="free") +
    geom_line()  + 
    labs(title = "Efficiency in Investment Return", x = "Year", y = "USD") +
    theme_tq() +
    scale_color_tq() 
```  

### GM
```{r}
gm_growth_ratios <- gm_key_ratios %>%
    filter(section == "Financials") %>%
    unnest() %>%
    filter(category == "Earnings Per Share USD" | category == 'Net Income USD Mil') %>%
    filter(date >= '2011-01-01')

gm_growth_ratios %>%
    ggplot(aes(x = date, y = value)) +
    facet_grid(category~., scale="free") +
    geom_line()  + 
    labs(title = "Efficiency in Investment Return", x = "Year", y = "USD") +
    theme_tq() +
    scale_color_tq() 
```