# 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"

Tech and Communication- IBM, AAPL, RTX, NFLX, ANET, SMCI Other: GE, KO, BA Retail and Consumer Cyclical: LULU, GPS, SBUX, WMT, AMZN, BBY, COST ETFS: QQQ, XLE, PRGSX, VOOG, SPY

###Biggest Winner - Boeing (BA) +24.76%

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
dfBA <- data.frame(Date = index(BA), coredata(BA))
dfBA <- tail(dfBA, 60)  # Fix typo in tail() function

# Custom colors
i <- list(line = list(color = 'green'))
d <- list(line = list(color = 'red'))


(BAPLOT <- dfBA %>%
  plot_ly(x = ~Date, type = "candlestick",
          open = ~BA.Open, close = ~BA.Close,
          high = ~BA.High, low = ~BA.Low,
          increasing = i, decreasing = d) |> 
  layout(title = list(text = "The Bills - BA Price Behavior Over Project", font = list(color = "white")),
         xaxis = list(title = "Date", color = "white"),
         yaxis = list(title = "Price (USD)", color = "white"),
         margin = list(l = 50, r = 50, t = 50, b = 50),
         plot_bgcolor = "black",  # Set background color to black
         paper_bgcolor = "black",  # Set paper background color to black
       
         annotations = list(
           list(x = as.Date("2023-09-18"), y = max(dfBA$BA.High), xref = "x", yref = "y",
                text = "Start of Project", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white"))
         )
  ))

More information on Boeing will go here


library(plotly)

dfUAL <- data.frame(Date = index(UAL), coredata(UAL))
dfUAL <- tail(dfUAL, 60)  # Fix typo in tail() function

# Custom colors
i <- list(line = list(color = 'green'))
d <- list(line = list(color = 'red'))


(UALPLOT <- dfUAL %>%
  plot_ly(x = ~Date, type = "candlestick",
          open = ~UAL.Open, close = ~UAL.Close,
          high = ~UAL.High, low = ~UAL.Low,
          increasing = i, decreasing = d) |> 
  layout(title = list(text = "The Bills - UAL Price Behavior Over Project", font = list(color = "white")),
         xaxis = list(title = "Date", color = "white"),
         yaxis = list(title = "Price (USD)", color = "white"),
         margin = list(l = 50, r = 50, t = 50, b = 50),
         plot_bgcolor = "black",  # Set background color to black
         paper_bgcolor = "black",  # Set paper background color to black
         annotations = list(
           list(x = as.Date("2023-09-18"), y = max(dfUAL$UAL.High), xref = "x", yref = "y",
                text = "Start", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white")),
           list(x = as.Date("2023-09-21"), y = max(dfUAL$UAL.High), xref = "x", yref = "y",
                text = "Buy", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white")),
           list(x = as.Date("2023-11-14"), y = max(dfUAL$UAL.High), xref = "x", yref = "y",
                text = "Sell", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white"))
         )
  ))
library(plotly)

dfSPY <- data.frame(Date = index(SPY), coredata(SPY))
dfSPY <- tail(dfSPY, 60)  # Fix typo in tail() function

# Custom colors
i <- list(line = list(color = 'green'))
d <- list(line = list(color = 'red'))


(SPYPLOT <- dfSPY %>%
  plot_ly(x = ~Date, type = "candlestick",
          open = ~SPY.Open, close = ~SPY.Close,
          high = ~SPY.High, low = ~SPY.Low,
          increasing = i, decreasing = d) |> 
  layout(title = list(text = "The Bills - SPY Price Behavior Over Project", font = list(color = "white")),
         xaxis = list(title = "Date", color = "white"),
         yaxis = list(title = "Price (USD)", color = "white"),
         margin = list(l = 50, r = 50, t = 50, b = 50),
         plot_bgcolor = "black",  # Set SPYckground color to black
         paper_bgcolor = "black",  # Set paper SPYckground color to black
       
         annotations = list(
           list(x = as.Date("2023-09-18"), y = max(dfSPY$SPY.High), xref = "x", yref = "y",
                text = "Start of Project", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white"))
         )
  ))
library(plotly)

dfXLE <- data.frame(Date = index(XLE), coredata(XLE))
dfXLE <- tail(dfXLE, 60)  # Fix typo in tail() function

# Custom colors
i <- list(line = list(color = 'green'))
d <- list(line = list(color = 'red'))


(XLEPLOT <- dfXLE %>%
  plot_ly(x = ~Date, type = "candlestick",
          open = ~XLE.Open, close = ~XLE.Close,
          high = ~XLE.High, low = ~XLE.Low,
          increasing = i, decreasing = d) |> 
  layout(title = list(text = "The Bills - XLE Price Behavior Over Project", font = list(color = "white")),
         xaxis = list(title = "Date", color = "white"),
         yaxis = list(title = "Price (USD)", color = "white"),
         margin = list(l = 50, r = 50, t = 50, b = 50),
         plot_bgcolor = "black",  # Set XLEckground color to black
         paper_bgcolor = "black",  # Set paper XLEckground color to black
       
         annotations = list(
           list(x = as.Date("2023-09-18"), y = max(dfXLE$XLE.High), xref = "x", yref = "y",
                text = "Start of Project", showarrow = TRUE, arrowhead = 4, ax = 0, ay = -40, font = list(color = "white"))
         )
  ))