Disclaimer: In this assignment, I have utilised Claude 4 Sonet in various aspects, including clarifying the expectations of the questions, facilitating my understanding of the addressed concepts, roxygen2-style document generation for helper functions, code debugging, and proof-reading.
Exercise 1 - Financial Data a. Stylized Facts Analysis i. Data Crawling & Prepocessing 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 if (!file.exists("Data/price_dt.rds")) { # Download Data stock_ls <- c("COST", "WMT", "KO", "PEP") price_dt <- tq_get(stock_ls, get = "stock.prices", from = "2000-01-01", # to = as.character(Sys.Date() - 1) to = "2025-08-09" ) # Save model data saveRDS(price_dt, file = "Data/price_dt.rds") } else { # Access saved stock data price_dt <- readRDS("Data/price_dt.rds") } # Prepare return data return_all_dt <- prep_return_dt(price_dt) # Extract different frequencies daily_returns <- return_all_dtweekly monthly_returns <- return_all_dt$monthly head(daily_returns) 1 2 3 4 5 6 7 8 9 ## # A tibble: 6 × 9 ## symbol date adjusted ret grossret logret sqret absret volume ## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> ## 1 COST 2000-01-04 28.1 -0.0548 0.945 -0.0563 0.00317 0.0563 5722800 ## 2 COST 2000-01-05 28.6 0.0171 1.02 0.0169 0.000287 0.0169 7726400 ## 3 COST 2000-01-06 29.2 0.0201 1.02 0.0199 0.000396 0.0199 7221400 ## 4 COST 2000-01-07 31.1 0.0662 1.07 0.0641 0.00411 0.0641 5164800 ## 5 COST 2000-01-10 31.8 0.0208 1.02 0.0206 0.000425 0.0206 4454000 ## 6 COST 2000-01-11 30.6 -0.0355 0.964 -0.0362 0.00131 0.0362 2955000 1 2 3 4 # Calculate 5% quantile daily_q5_dt <- quantile(daily_returns |> pull(ret), probs = 0.05) weekly_q5_dt <- quantile(weekly_returns |> pull(ret), probs = 0.05) monthly_q5_dt <- quantile(monthly_returns |> pull(ret), probs = 0.05) Compute summary statistics
...