How have the stock prices of Meta, Amazon, and Alphabet (Google) evolved over the last year, and is there any noticeable correlation or pattern among them?
To address this, I will analyze the historical stock prices of Meta, Amazon, and Alphabet over the past year. My focus will be on identifying trends, patterns, and potential correlations within this time frame. Through this analysis, I want gain insights into the recent performance of these stocks, to see how they have moved individually and whether any observable correlations or patterns have emerged over the last year.
I’ll be web scraping the weekly historical data from Yahoo Finance for each of these stocks. These stocks are all similar in that they are non-dividend stocks in the tech sector. This code creates separate data tables for each stock and then adds in a row for it’s ticker symbol.
{# Load required libraries
library(rvest)
library(ggplot2)
library(lubridate)
# Define function to scrape data
scrape_data <- function(url) {
webpage <- read_html(url)
data <- html_table(html_nodes(webpage, "table"))[[1]]
return(data)
}
# Scrape data
meta <- scrape_data("https://finance.yahoo.com/quote/META/history?period1=1670470044&period2=1702006044&interval=1wk&filter=history&frequency=1wk&includeAdjustedClose=true")
google <- scrape_data("https://finance.yahoo.com/quote/GOOG/history?period1=1670452198&period2=1701988198&interval=1wk&filter=history&frequency=1wk&includeAdjustedClose=true")
amazon <- scrape_data("https://finance.yahoo.com/quote/AMZN/history?period1=1670452022&period2=1701988022&interval=1wk&filter=history&frequency=1wk&includeAdjustedClose=true")
# Add a new column to each data frame to identify the stock
meta$Stock <- "META"
google$Stock <- "GOOG"
amazon$Stock <- "AMZN"
}
Here we can compare the three stocks total trading volume over the last year. As we can see, Amazon was significantly higher which was surprising to me.
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
In this chart we can view the similarity in movements between the three stocks. Google and Amazon are obviously closely related but Meta seems differ more.
Here we can see the differences in daily high and low stock prices. Meta seems to have a lot more variance and daily swings compared to the other two.