ARGridBootstrap.jl

This package implements the grid bootstrap of Hansen (1999).

For teaching purposes, multiple versions of the “same” function are included. The differences between these versions illustrate various techniques to improve performance. See Coding for Performance.

Functions

AR

# ARGridBootstrap.ar1_originalFunction.

ar1_original(y0, a, e, rindex=T->rand(1:length(e), T))

Simulate AR1 model by sampling errors from e with replacement.

y[t] = a*y[t-1] + ϵ[t]

Arguments

  • y0: initial value for y
  • a: AR parameter
  • e: values of for error term. ϵ = e[rindex(T)]]
  • rindex function that returns random index in 1:length(e)

Returns

  • y: vector of length T = length(e)

source

# ARGridBootstrap.b_est_mldivideMethod.

b_est_mldivide(y)

Estimate AR(1) model with intercept and time trend.

y[t] = θ[0] + θ[1]t + θ[2]y[t-1] + e[t]

Arguments

  • y: vector

Returns

  • θ: estimated coefficients
  • se: standard errors
  • e: residuals

source

# ARGridBootstrap.b_est_noxMethod.

b_est_nox(y)

Estimate AR(1) model with intercept and time trend.

y[t] = θ[0] + θ[1]t + θ[2]y[t-1] + e[t]

Arguments

  • y: vector

Returns

  • θ: estimated coefficients
  • se: standard errors
  • e: residualas

source

# ARGridBootstrap.b_est_originalMethod.

b_est_original(y)

Estimate AR(1) model with intercept and time trend

y[t] = θ[0] + θ[1]t + θ[2]y[t-1] + e[t]

Arguments

  • y: vector

Returns

  • θ: estimated coefficients
  • se: standard errors
  • e: residuals

source

# ARGridBootstrap.b_est_strideMethod.

b_est_stride(y)

Estimate AR(1) model with intercept and time trend.

y[t] = θ[0] + θ[1]t + θ[2]y[t-1] + e[t]

Arguments

  • y: vector

Returns

  • θ: estimated coefficients
  • se: standard errors
  • e: residualas

source

# ARGridBootstrap.invsymMethod.

fast inverse function for statically sized 3x3 StrideArray

source

# ARGridBootstrap.onetoMethod.

oneto(Val(N)) Creates at a compile time the tuple (1, 2, …, N)

source

# ARGridBootstrap.simulate_estimate_arpMethod.

simulate_estimate_arp(y0, a, e, ar::Val{P}, rindex=T->rand(1:length(e),T))

Simulates and estimates an AR(P) model. y is simulated as

y[t] = a*y[t-1] + ϵ[t]

and the estimate of θ from

y[t] = θ[1] + θ[2]t + θ[3] y[t-1] + … + θ[P] y[t-P] + u[t]

is computed.

Arguments

  • y0 initial value of y
  • a AR(1) parameter
  • e error terms to sample from ϵ[t] = e[rindex(1)]
  • ar::Val{P} order of autoregressive model to estimate
  • rindex function that returns random index in 1:length(e)

Returns

  • θ estimated coefficients
  • se standard errors

source

# ARGridBootstrap.simulate_estimate_arp_lvMethod.

simulate_estimate_arp_lv(y0, a, e, ar::Val{P}, rindex=T->rand(1:length(e),T))

Simulates and estimates an AR(P) model. Uses LoopVectorization.jl to produce fast code.

y is simulated as

y[t] = a*y[t-1] + ϵ[t]

and the estimate of θ from

y[t] = θ[1] + θ[2]t + θ[3] y[t-1] + … + θ[P] y[t-P] + u[t]

is computed.

Arguments

  • y0 initial value of y
  • a AR(1) parameter
  • e error terms to sample from ϵ[t] = e[rindex(1)]
  • ar::Val{P} order of autoregressive model to estimate
  • rindex function that returns random index in 1:length(e)

Returns

  • θ estimated coefficients
  • se standard errors

source

Grid Bootstrap

# ARGridBootstrap.argridbootstrap_gpuMethod.

argridbootstrap_gpu(e; αgrid = 0.84:(0.22/20):1.06,
                      nboot=199, RealType = Float32)

Computes grid bootstrap estimates for an AR(1) model.

For each α ∈ grid, repeatedly simulate data with parameter α and then compute an estimate.

Arguments

  • e vector error terms that will be resampled with replacement to generate bootstrap sample
  • grid grid of parameter values. For each value, nboot datasets will be simulated and estimates computed.
  • nboot
  • RealType type of numbers for GPU computation. On many GPUs, Float32 will have better performance than Float64.

Returns

  • ba hatα - α for each grid value and simulated dataset
  • t t-stat for each grid value and simulated dataset

source

# ARGridBootstrap.argridkernel!Method.

argridkernel!(ba,bootq, bootse, ar::Val{P}, e, ei, αgrid)

GPU kernel for simulation and estimation of AR(P) model.

Arguments (modified on return)

  • ba: nboot × ngrid array. Will be filled with bootstrap estimates of α grid values of true α
  • bootq: nboot × ngrid array. Will be filled with bootstrap estimates of α
  • bootse: nboot × ngrid array. Will be filled with standard errors of α for each bootstrap repetition

Arguments (not modified)

  • ar::Val{P} : autoregressive order for estimation. Simulated model will always be AR(1) with 0 intercept and time trend, but estimation will use an AR(P) model with intercept and time trend. Only the AR(1) parameter estimate is included in ba, bootq, and bootse.
  • e : error terms to draw with replacement
  • ei : nboot × ngrid × length(e) array of indices of e to use to generate bootstrap sample1
  • αgrid : length ngrid values of AR(1) parameter to perform bootstrap on.

Returns nothing, but modifies in place ba, bootq, and bootse

source

# ARGridBootstrap.gridbootstrapFunction.

gridbootstrap(estimator, simulator,
              grid::AbstractVector,
              nboot=199)

Computes grid bootstrap estimates a single parameter model.

For each α ∈ grid, repeatedly simulate data with parameter α and then compute an estimate.

Arguments

  • estimator function of output of simulator that returns a 2-tuple containing an estimate of α and its standard error.
  • simulator function that given α simulates data that can be used to estimate α
  • grid grid of parameter values. For each value, nboot datasets will be simulated and estimates computed.
  • nboot

Returns

  • ba hatα - α for each grid value and simulated dataset
  • t t-stat for each grid value and simulated dataset

source

# ARGridBootstrap.gridbootstrap_threadedFunction.

gridbootstrap_threaded(estimator, simulator,
                grid::AbstractVector,
                nboot=199, rng=rngarray(nthreads())

Computes grid bootstrap estimates a single parameter model.

Multithreaded version.

For each α ∈ grid, repeatedly simulate data with parameter α and then compute an estimate.

Arguments

  • estimator function of output of simulator that returns a 2-tuple containing an estimate of α and its standard error.
  • simulator function that given α and rng, simulates data that can be used to estimate α
  • grid grid of parameter values. For each value, nboot datasets will be simulated and estimates computed.
  • nboot number of bootstrap simulations per grid point

Returns

  • ba hatα - α for each grid value and simulated dataset
  • t t-stat for each grid value and simulated dataset

source

# ARGridBootstrap.rngarrayMethod.

rngarray(n)

Create n rng states that will not overlap for 10^20 steps.

Note: this will be unneeded in Julia 1.3 when thread-safe RNG is included.

source