A cry for help with boot()

Hello,

I'm currently working on a paper, and for one section of it need I BCa confidence intervals.
My goal is to do exactly what is done in this article (from page 793: "Comparison of the Hedging Performance Across Subperiods.

Basically, I have two time-series each divided into two subperiods. The first time-series is the ln daily change of an unhedged position for time t [z] and t+1 . The second is the ln daily change of a hedged position for time t [y] and t+1 [w].

I want to investigate the change in hedging efficiency between the two periods through this formula:
stat = [1 - ( var(w) / var(x) ) ] - [1 - ( var(y) / var(z) ) ]

What I need is to get 10 000 of stat through a bootstrap, and create BCas.

I have managed to get my 10 000 numbers with the following code:

# Unhedged t
BootstrapVAR_UHt <- function(X=UHt){
  x.boot <- sample(X, size = length(X), replace = T)
  var(x.boot)
}

# Unhedged t+1
BootstrapVAR_UHt1 <- function(X=UHt1){
  x.boot <- sample(X, size = length(X), replace = T)
  var(x.boot)
}

# Hedged t
BootstrapVAR_Ht <- function(X=Ht){
  x.boot <- sample(X, size = length(X), replace = T)
  var(x.boot)
}

# Hedged t+1
BootstrapVAR_Ht1 <- function(X=Ht1){
  x.boot <- sample(X, size = length(X), replace = T)
  var(x.boot)
}

N    <- 5000
stat <- numeric(N)

for (i in 1:N){
  Boot.UHt  = BootstrapVAR_UHt   (X=UHt)
  Boot.UHt1 = BootstrapVAR_UHt1  (X=UHt1)
  Boot.Ht   = BootstrapVAR_Ht    (X=Ht)
  Boot.Ht1  = BootstrapVAR_Ht1   (X=Ht1)
  
  stat[i] = (1 - (Boot.Ht1 / Boot.UHt1) ) - (1 - (Boot.Ht  / Boot.UHt) )
}

However, in order to use boot.ci() to get my confidence interval, I guess I first have to achieve the above through the boot() function, as this saves the results in the correct way for boot.ci().

I have almost broken both my computer and my mind trying to achieve the above through boot(), but I fall short.

This is my first time using both this site and R, so please comment if I'm missing any vital information in the post (and be kind).

Thanks for reading!

EDIT:
The variables are defined like this, where "STATA" is my spreadsheet and "S4B_58" is unhedged and "HS4B_58" is hedged. Rows 2412:2833 is t while rows 2836:3066 is t+1.

UHt  <- as.numeric(na.omit(STATA[["S4B_58"]]  [c(2412:2833)] ))
UHt1 <- as.numeric(na.omit(STATA[["S4B_58"]]  [c(2836:3066)] ))
Ht   <- as.numeric(na.omit(STATA[["HS4B_58"]] [c(2412:2833)] ))
Ht1  <- as.numeric(na.omit(STATA[["HS4B_58"]] [c(2836:3066)] ))

Hi @Groggen,

Since this question isn't related to the IDE itself, I'm going to move it into the general category (feel free to recategorize as you see fit).

Might you be able to turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff (which, in this case, would probably mean having some dummy data to play with).

Right now the best way to install reprex is:

# install.packages("devtools")
devtools::install_github("tidyverse/reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

For pointers specific to the community site, check out the reprex FAQ, linked to below.