predict.GARCHX <- function(object, newdata, ...){
  # Extract coefficient values of omega, alpha, beta, and gamma
  omega <- object$omega
  alpha <- object$alpha
  beta <- object$beta
  gamma <- object$gamma
  p <- length(alpha)
  q <- length(beta)

  # ### First Way ###
  # Requires parameters: object, new_X, n_pred only
  eps <- object$eps
  n_pred = dim(newdata)[1]
  # Error check
  #if(dim(X)[1] != n_pred){
  #  stop("Number of rows for X must equal n_pred")
  #} # End if

  # Extract exogenous covariates that were selected by the object
  # newdata <- newdata[, object$selectedX_index]
  # newdata <- rbind(object$selectedX, as.matrix(newdata, ncol = length(object$selectedX_index)))
  newdata <- newdata[, object$covariates, drop=FALSE] # Replace 20-21 above with 22-23 because new_GARCHX no longer has selectedX_index - [AI], 4/2/26
  newdata <- rbind(object$selectedX, as.matrix(newdata, ncol = length(object$selectedX_index)))
  # ### END ###



  # Initialize h as a vector of zeros with size n_pred
  h <- rep(0, n_pred)

  # Calculate the current time by finding length of time series
  current_time <- length(eps)

  t = 1
  if(length(gamma) == 1 && is.na(gamma))
  {

    sigma2_t <- omega + alpha * eps[current_time - 1] + beta * eps[current_time - 1]

    h[1] <- max(0, omega + alpha * eps[current_time] + beta * sigma2_t)

    for(t in 2:n_pred){
      h[t] <- max(0.01, omega + sum(alpha * h[(t-1):(t-p)]) + sum(beta * h[(t-1):(t-q)]))
    } # End for
  } else 
  {
    sigma2_t <- omega + alpha * eps[current_time - 1] + beta * eps[current_time - 1] + drop(newdata[current_time-1,] %*% gamma)

    h[1] <- max(0, omega + alpha * eps[current_time] + beta * sigma2_t + drop(newdata[current_time,] %*% gamma))

    for(t in 2:n_pred)
      h[t] <- max(0.01, omega + sum(alpha * h[(t-1):(t-p)]) + sum(beta * h[(t-1):(t-q)]) + drop(newdata[current_time + t - 1, ] %*% gamma))
  } # End if


  # Return sigma^2
  return(h)
} # End predict.GARCHX
