0

with_progress({

# Initialize the progress bar
pb <- progressor(along = unique(pct_women_exec$ticker))

# Precompute unique tickers
unique_tickers <- unique(pct_women_exec$ticker)

# Use lapply to fit models for each ticker
fitted_models <- lapply(unique_tickers, function(ticker) {

    # Subset the data and external regressors for the current ticker
    y <- pct_women_exec[pct_women_exec$ticker == ticker, "ret.RF"]
    X1 <- data.frame(Mkt.RF = pct_women_exec[pct_women_exec$ticker == 
                     ticker, "Mkt.RF"])
    X2 <- data.frame(event_dummy = pct_women_exec[pct_women_exec$ticker 
                      == ticker, "event_dummy"])
    X2 <- as.matrix(X2)
    X3 <- data.frame(SMB = pct_women_exec[pct_women_exec$ticker == 
                     ticker, "SMB"])
    X4 <- data.frame(HML = pct_women_exec[pct_women_exec$ticker == 
                     ticker, "HML"])
    X5 <- data.frame(RWW = pct_women_exec[pct_women_exec$ticker == 
                     ticker, "RMW"])
    X6 <- data.frame(CMA = pct_women_exec[pct_women_exec$ticker == 
                     ticker, "CMA"])
    X <- cbind(as.matrix(X1), X2, as.matrix(X3), as.matrix(X4), 
               as.matrix(X5), as.matrix(X6))
 
    # Define the specifications
    spec <- ugarchspec(variance.model = list(model = "sGARCH", 
              external.regressors=X2), 
              mean.model = list(armaOrder= c(0, 0), 
              include.mean = TRUE, external.regressors=X))

    # Fitting the model (remember solver is here)                     
    fit <- ugarchfit(data=y, spec=spec)
    
    #Extracting residuals
    resid <- residuals(fit)
    sigma_sd <- sd(sigma(fit))
    
    # Check the output
    convergence(fit)
    coef(fit)

    # Update the progress bar
    pb()

    # Return the fitted model
    return(fit)

})  

})

There are no problems with multicollinearity here. I checked. Why would this loop not converge to a solution? If I run it just with Mkt.RF as the regressor alone, it runs without issues. I am reluctant to run with the "hybrid" solver option, as it has given me slightly different results everytime and quite significantly changed some coefficients.

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28

0 Answers0