Stocks

Data - yahoo

Info

source dataset .html .RData
yahoo stocks 2024-10-29 2024-09-18

LAST_COMPILE

LAST_COMPILE
2024-11-05

Last

date Nobs
2024-09-17 12

symbol

symbol Symbol Nobs
AAPL Apple 11032
AMD Advanced Micro Devices, Inc. 11220
AMZN Amazon 6880
GOOG Alphabet 5054
INTC Intel Corporation 11220
KO The Coca-Cola Company 11272
META Meta 3102
MSFT Microsoft 9706
NVDA NVIDIA Corporation 6455
PEP PepsiCo, Inc. 11272
TSLA Tesla 3579
TSM Taiwan Semiconductor Manufacturing Company Limited 6778

Magnificent Seven: Nvidia, Meta, Tesla, Amazon, Alphabet, Microsoft, Apple

1990-

Linear

Code
plot_linear <- stocks %>%
  filter(symbol %in% c("META", "TSLA", "NVDA", "AMZN", "GOOG", "MSFT", "AAPL")) %>%
  filter(date >= as.Date("1990-01-01")) %>%
  left_join(symbol, by = "symbol") %>%
  group_by(symbol) %>%
  arrange(date) %>%
  mutate(close = 100*close/close[1]) %>%
  ggplot() + geom_line(aes(x = date, y = close, color = Symbol)) +
  theme_minimal() + xlab("") + ylab("") +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 1000000, 20000)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y"))

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = 10^seq(2, 100, 1))

plot_log

Bind

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear scale"), plot_log + ggtitle("Log scale"), common.legend = T)

2010-

Linear

Code
plot_linear <- stocks %>%
  filter(symbol %in% c("META", "TSLA", "NVDA", "AMZN", "GOOG", "MSFT", "AAPL")) %>%
  filter(date >= as.Date("2010-01-01")) %>%
  left_join(symbol, by = "symbol") %>%
  group_by(symbol) %>%
  arrange(date) %>%
  mutate(close = 100*close/close[1]) %>%
  ggplot() + geom_line(aes(x = date, y = close, color = Symbol)) +
  theme_minimal() + xlab("") + ylab("") +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.7),
        axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1)) +
  scale_y_continuous(breaks = seq(0, 1000000, 5000),
                     labels = dollar_format(pre = "", acc = 1)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1940, 2100, 1), "-01-01")),
               labels = date_format("%Y"))

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(10^seq(1, 100, 1), 10^seq(1, 100, 1)*2, 10^seq(1, 100, 1)*5),
                     labels = dollar_format(pre = "", acc = 1))

plot_log

Bind

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear scale"),
                  plot_log + ggtitle("Log scale"),
                  common.legend = T)

2014-

Linear

Code
plot_linear <- stocks %>%
  filter(symbol %in% c("META", "TSLA", "NVDA", "AMZN", "GOOG", "MSFT", "AAPL")) %>%
  filter(date >= as.Date("2014-01-01")) %>%
  left_join(symbol, by = "symbol") %>%
  group_by(symbol) %>%
  arrange(date) %>%
  mutate(close = 100*close/close[1]) %>%
  ggplot() + geom_line(aes(x = date, y = close, color = Symbol)) +
  theme_minimal() + xlab("") + ylab("") +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.7),
        axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1)) +
  scale_y_continuous(breaks = seq(0, 1000000, 5000),
                     labels = dollar_format(pre = "", acc = 1)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1940, 2100, 1), "-01-01")),
               labels = date_format("%Y"))

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(10^seq(1, 100, 1), 10^seq(1, 100, 1)*2, 10^seq(1, 100, 1)*5),
                     labels = dollar_format(pre = "", acc = 1))

plot_log

Bind

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear scale"),
                  plot_log + ggtitle("Log scale"),
                  common.legend = T)