Introduction

This assignment analyzes the daily stock prices and daily returns of six companies: Apple (AAPL), Microsoft (MSFT), Alphabet (GOOG), Amazon (AMZN), Taiwan Semiconductor Manufacturing Company (TSM), and NVIDIA (NVDA).

The daily stock prices are downloaded from Yahoo Finance from January 1, 2024 to the present.

1. Download Daily Stock Prices

library(quantmod)

stocks <- c("AAPL", "MSFT", "GOOG", "AMZN", "TSM", "NVDA")

getSymbols(
  stocks,
  src = "yahoo",
  from = "2024-01-01",
  to = Sys.Date()
)
## [1] "AAPL" "MSFT" "GOOG" "AMZN" "TSM"  "NVDA"

2. Compute Daily Returns

Daily returns are calculated using adjusted closing prices.

returns <- do.call(
  merge,
  lapply(
    stocks,
    function(x) dailyReturn(Ad(get(x)))
  )
)

colnames(returns) <- stocks

3. First Few Daily Returns

The first few daily returns for all six stocks are shown below.

head(returns)
##                    AAPL          MSFT         GOOG         AMZN          TSM
## 2024-01-02  0.000000000  0.0000000000  0.000000000  0.000000000  0.000000000
## 2024-01-03 -0.007487460 -0.0007279818  0.005732316 -0.009737821 -0.013395024
## 2024-01-04 -0.012700208 -0.0071775520 -0.016528936 -0.026267892 -0.010382474
## 2024-01-05 -0.004013055 -0.0005164916 -0.004708702  0.004634420  0.004842050
## 2024-01-08  0.024174834  0.0188715579  0.022854624  0.026576704  0.026403085
## 2024-01-09 -0.002263204  0.0029358119  0.014445555  0.015224607 -0.003423392
##                    NVDA
## 2024-01-02  0.000000000
## 2024-01-03 -0.012435606
## 2024-01-04  0.009018417
## 2024-01-05  0.022896816
## 2024-01-08  0.064280954
## 2024-01-09  0.016975047