proc_SP500: Preprocess SP500 data

View source: R/proc_SP500.R

proc_SP500R Documentation

Preprocess SP500 data

Description

The proc_SP500 function preprocesses the SP500 stock data by calculating monthly returns for selected sectors and generating idiosyncratic errors.

Usage

proc_SP500(SP500data, sectors)

Arguments

SP500data

A data frame containing SP500 stock data with columns including:

symbol

Stock symbol.

date

Date of the stock data.

adjusted

Adjusted closing price of the stock.

sector

Sector of the stock.

sectors

A character vector specifying the sectors to include in the analysis.

Details

  1. Calculates monthly returns for each stock in the specified sectors

  2. Estimates the number of factors via hdbinseg::get.factor.model(ic="ah")

  3. Uses POET::POET() to extract factor loadings/factors and form idiosyncratic errors

Value

A list with components:

Uhat

A matrix of idiosyncratic errors.

Khat

Estimated number of factors.

factorparthat

Estimated factor returns.

sectornames

Sector for each column of Uhat.

Examples


data("SP500")
set.seed(1234)
sectors <- c("Energy", "Financials", "Materials",
   "Real Estate", "Utilities", "Information Technology")

Uhat <- proc_SP500(SP500, sectors)$Uhat
PPPres <- thresPPP(Uhat, eps = 0, thres = list(value = 0.0020, fun = "hard"), nsample = 100)
postmean <- estimate(PPPres)
diag(postmean) <- 0 # hide color for diagonal
plot(postmean)


bspcov documentation built on July 3, 2025, 1:10 a.m.