# this line specifies options for default options for all R Chunks
knitr::opts_chunk$set(echo=T,
highlight=T)
# suppress scientific notation
options(scipen=100,
getSymbols.warning4.0 = FALSE)
# install helper package (pacman), if needed
if (!require("pacman")) install.packages("pacman", repos = "http://lib.stat.cmu.edu/R/CRAN/")
## Loading required package: pacman
# install and load required packages
# pacman should be first package in parentheses and then list others
pacman::p_load(pacman, tidyverse, gridExtra, magrittr, lubridate,
knitr, kableExtra, tidyquant, highcharter, dygraphs,
htmlwidgets)
# verify packages (comment out in finished documents)
p_loaded()
## [1] "htmlwidgets" "dygraphs" "highcharter"
## [4] "tidyquant" "quantmod" "TTR"
## [7] "PerformanceAnalytics" "xts" "zoo"
## [10] "kableExtra" "knitr" "magrittr"
## [13] "gridExtra" "lubridate" "forcats"
## [16] "stringr" "dplyr" "purrr"
## [19] "readr" "tidyr" "tibble"
## [22] "ggplot2" "tidyverse" "pacman"
(dystreaming <- dygraph(streaming_stocks, main="Streaming Company Stock Trends") |>
dySeries("NFLX.adj", label="NFLX", color= "blue") |>
dySeries("PARA.adj", label="PARA", color = "pink") |>
dyAxis("y", label = "Adjusted Close", drawGrid = FALSE) |>
dyAxis("x", label = "Date", drawGrid = FALSE) |>
dyEvent("2020-03-14", label = "COVID-19 Start", labelLoc = "bottom") |>
dyRangeSelector())
This is information about the graph
library(dygraphs)
library(dplyr)
library(zoo)
StreamingStocks <- cbind(AMC[,2:4], PARA[,2:4],NFLX[,2:4],IMAX[,2:4])
(dygraph(StreamingStocks, main = "Share Prices") |>
dySeries(c("AMC.Low", "AMC.Close",
"AMC.High"), label = "AMC") |>
dySeries(c("PARA.Low", "PARA.Close",
"PARA.High"), label = "PARA") |>
dySeries(c("NFLX.Low", "NFLX.Close",
"NFLX.High"), label = "NFLX") |>
dySeries(c("IMAX.Low", "IMAX.Close",
"IMAX.High"), label = "IMAX") |>
dyRangeSelector())
library(quantmod)
library(dygraphs)
NFLX1 <- NFLX
NFLX1 <- tail(NFLX, n=30)
nflxcandlestick <- dygraph(OHLC(NFLX))
dyCandlestick(nflxcandlestick)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
dfNFLX <- data.frame(Date = index(NFLX), coredata(NFLX))
dfNFLX <- tail(dfNFLX, 30) # Fix typo in tail() function
# Custom colors
i <- list(line = list(color = 'green'))
d <- list(line = list(color = 'red'))
(nflxPLOT <- dfNFLX %>%
plot_ly(x = ~Date, type = "candlestick",
open = ~NFLX.Open, close = ~NFLX.Close,
high = ~NFLX.High, low = ~NFLX.Low,
increasing = i, decreasing = d) %>%
layout(title = "NFLX Price Behavior",
xaxis = list(title = "Date"),
yaxis = list(title = "Price (USD)"),
margin = list(l = 40, r = 40, t = 40, b = 40),
shapes = list(
list(x0 = as.Date("2023-10-01"), x1 = as.Date("2023-10-15"), y0 = 0, y1 = 1, xref = "x", yref = "paper",
line = list(color = "black", width = 1, dash = "dashdot"))
),
annotations = list(
list(x = as.Date("2023-10-14"), y = max(dfNFLX$NFLX.High), xref = "x", yref = "y",
text = "EVENT - FILL IN LATER", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40)
)
))
dfPARA <- data.frame(Date = index(PARA), coredata(PARA))
dfPARA <- tail(dfPARA, 30)
(paraPLOT <- dfPARA %>%
plot_ly(x = ~Date, type = "candlestick",
open = ~PARA.Open, close = ~PARA.Close,
high = ~PARA.High, low = ~PARA.Low,
increasing = i, decreasing = d) %>%
layout(title = "PARA Price Behavior",
xaxis = list(title = "Date"),
yaxis = list(title = "Price (USD)"),
margin = list(l = 40, r = 40, t = 40, b = 40),
shapes = list(
list(x0 = as.Date("2023-10-01"), x1 = as.Date("2023-10-15"), y0 = 0, y1 = 1, xref = "x", yref = "paper",
line = list(color = "black", width = 1, dash = "dashdot"))
),
annotations = list(
list(x = as.Date("2023-10-14"), y = max(dfPARA$PARA.High), xref = "x", yref = "y",
text = "EVENT - FILL IN LATER", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40)
)
))
dfIMAX <- data.frame(Date = index(IMAX), coredata(IMAX))
dfIMAX <- tail(dfIMAX, 30
)
(IMAXPLOT <- dfIMAX %>%
plot_ly(x = ~Date, type = "candlestick",
open = ~IMAX.Open, close = ~IMAX.Close,
high = ~IMAX.High, low = ~IMAX.Low,
increasing = i, decreasing = d) %>%
layout(title = "IMAX Price Behavior",
xaxis = list(title = "Date"),
yaxis = list(title = "Price (USD)"),
margin = list(l = 40, r = 40, t = 40, b = 40),
shapes = list(
list(x0 = as.Date("2023-10-01"), x1 = as.Date("2023-10-15"), y0 = 0, y1 = 1, xref = "x", yref = "paper",
line = list(color = "black", width = 1, dash = "dashdot"))
),
annotations = list(
list(x = as.Date("2023-10-14"), y = max(dfIMAX$IMAX.High), xref = "x", yref = "y",
text = "EVENT - FILL IN LATER", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40)
)
))
dfAMC <- data.frame(Date = index(AMC), coredata(AMC))
dfAMC <- tail(dfAMC, 30)
(AMCPLOT <- dfAMC %>%
plot_ly(x = ~Date, type = "candlestick",
open = ~AMC.Open, close = ~AMC.Close,
high = ~AMC.High, low = ~AMC.Low,
increasing = i, decreasing = d) %>%
layout(title = "AMC Price Behavior",
xaxis = list(title = "Date"),
yaxis = list(title = "Price (USD)"),
margin = list(l = 40, r = 40, t = 40, b = 40),
shapes = list(
list(x0 = as.Date("2023-10-01"), x1 = as.Date("2023-10-15"), y0 = 0, y1 = 1, xref = "x", yref = "paper",
line = list(color = "black", width = 1, dash = "dashdot"))
),
annotations = list(
list(x = as.Date("2023-10-14"), y = max(dfAMC$AMC.High), xref = "x", yref = "y",
text = "EVENT - FILL IN LATER", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40)
)
))
(GRID_ALL <- hw_grid(paraPLOT, nflxPLOT, AMCPLOT, IMAXPLOT, ncol = 2))
nflx_fts <- hchart(NFLX$NFLX.Adjusted, name="NFLX Adj.", color="blue") |>
hc_add_series(NFLX$NFLX.High, name="NFLX Hi." , color="darkblue") |>
hc_add_series(NFLX$NFLX.Low, name="NFLX Lo." , color="lightblue")
(nflx_chart <- hchart(NFLX$NFLX.Adjusted, name="NFLX Adj.", color="blue") |>
hc_add_series(NFLX$NFLX.High, name="NFLX Hi." , color="darkblue") |>
hc_add_series(NFLX$NFLX.Low, name="NFLX Lo." , color="lightblue") |>
hc_title(text = "Netflix (NFLX) Stock Price Chart") |>
hc_subtitle(text = "Adjusted, High, and Low Prices") |>
hc_xAxis(title = list(text = "Date")) |>
hc_yAxis(title = list(text = "Stock Price")) |>
hc_tooltip(crosshairs = TRUE, shared = TRUE, valueDecimals = 2) |>
hc_plotOptions(series = list(marker = list(enabled = TRUE, symbol = "circle", radius = 3))))