---
title: "Data Visualization: Stock valuation Brent Oil"
author: "Rubén F. Bustillo"
output:
flexdashboard::flex_dashboard:
orientation: columns
source_code: embed
vertical_layout: fill
theme: cerulean
---
```{r setup, include=FALSE}
# PACKAGES / LIBRARIES:
library(flexdashboard)
library(tidyverse)
library(highcharter)
library(quantmod)
library(lubridate)
# For info about main differences between Brent Crude and WTI:
# https://www.investopedia.com/ask/answers/052615/what-difference-between-brent-crude-and-west-texas-intermediate.asp
```
Crude Oil
========================================================================
Column
------------------------------------------------------------------
### Brent Crude
```{r}
crude <- getSymbols("BZ=F", auto.assign = FALSE)
crude <- crude %>%
na.omit()
crude.SMA.5 <- SMA(Cl(crude), n = 5)
crude.SMA.10 <- SMA(Cl(crude), n = 10)
crude.RSI.14 <- RSI(Cl(crude)) # RSI: indicador de fortaleza relativa a 15 periodos
crude.RSI.SellLevel <- xts(rep(70, NROW(crude)), index(crude))
crude.RSI.BuyLevel <- xts(rep(30, NROW(crude)), index(crude))
highchart(type = "stock") %>%
hc_yAxis_multiples(
create_yaxis(3, height = c(2, 1, 1))
) %>%
hc_add_series(crude.SMA.5, yAxis = 0, name = "Moving Av.: 5 periods", color = "grey") %>%
hc_add_series(crude.SMA.10, yAxis = 0, name = "Moving Av.: 10 periods" , color = "lightskyblue") %>%
hc_add_series(crude$`BZ=F.Volume`, color = "lightgrey", yAxis = 1, name = "Volume", type = "column") %>%
hc_add_series(crude.RSI.14, yAxis = 2, name = "Osciallator", color = "blue") %>%
hc_title (text = "Brent Crude. Stock Valuation") %>%
hc_add_series(crude,
id = "crude",
color = "red",
name = "Crude Oil") %>%
hc_add_series(crude.RSI.SellLevel, color = "limegreen",
yAxis = 2, name = "Sell") %>%
hc_add_series(crude.RSI.BuyLevel, color = "limegreen",
yAxis = 2, name = "Buy") %>%
hc_add_theme(hc_theme_elementary()) %>%
hc_credits(enabled = TRUE, text = "quantmod.com",
href = "https://www.quantmod.com/")
```
Column
------------------------------------------------------------------
### Petróleo WTI (West Texas Intermediate)
```{r}
crude <- getSymbols("CL=F", auto.assign = FALSE)
crude <- crude %>%
na.omit()
crude.SMA.5 <- SMA(Cl(crude), n = 5)
crude.SMA.10 <- SMA(Cl(crude), n = 10)
crude.RSI.14 <- RSI(Cl(crude)) # RSI: indicador de fortaleza relativa a 15 periodos
crude.RSI.SellLevel <- xts(rep(70, NROW(crude)), index(crude))
crude.RSI.BuyLevel <- xts(rep(30, NROW(crude)), index(crude))
highchart(type = "stock") %>%
hc_yAxis_multiples(
create_yaxis(3, height = c(2, 1, 1))
) %>%
hc_add_series(crude.SMA.5, yAxis = 0, name = "Moving Av.: 5 periods", color = "grey") %>%
hc_add_series(crude.SMA.10, yAxis = 0, name = "Moving Av.: 10 periods" , color = "lightskyblue") %>%
hc_add_series(crude$`CL=F.Volume`, color = "lightgrey", yAxis = 1, name = "Volume", type = "column") %>%
hc_add_series(crude.RSI.14, yAxis = 2, name = "Osciallator", color = "blue") %>%
hc_title (text = "West Texas Intermediate (WTI). Stock Valuation") %>%
hc_add_series(crude,
id = "crude",
color = "red",
name = "Crude Oil") %>%
hc_add_series(crude.RSI.SellLevel, color = "limegreen",
yAxis = 2, name = "Sell") %>%
hc_add_series(crude.RSI.BuyLevel, color = "limegreen",
yAxis = 2, name = "Buy") %>%
hc_add_theme(hc_theme_elementary()) %>%
hc_credits(enabled = TRUE, text = "quantmod.com",
href = "https://www.quantmod.com/")
```