Tools

The Tools submodule provides a set of numerical subroutines such as linear and non-linear interpolation, the Tauchen algorithm to discretize a Gaussian AR-1 process, root-finders and optimizers, wrappers for the schur decomposition, etc.

Some of the functions in detail

BASEforHANK.Tools.TauchenFunction
Tauchen(rho::Float64, N::Int; sigma::Float64 = 1.0, mue::Float64 = 0.0)

Generate a discrete approximation to an AR(1) process, following Tauchen (1987).

Uses importance sampling: each bin has probability 1/N to realize.

Authored by Christian Bayer, Uni Bonn, 03.05.2010.

Arguments

  • rho::Float64: autocorrelation coefficient
  • N::Int: number of gridpoints
  • sigma::Float64: long-run variance
  • mue::Float64: mean of the AR(1) process

Returns

  • grid_vec::Vector: state vector grid of dimension N
  • P::Array{Float64, 2}: transition matrix of dimension N x N
  • bounds::Vector: bin bounds of dimension N + 1 #, transtype::Symbol = :importance)
source
BASEforHANK.Tools.distrSummariesFunction
distrSummaries(
    distr::AbstractArray,
    q::Real,
    x_a_star::AbstractArray,
    x_n_star::AbstractArray,
    n_par,
    net_income::AbstractArray,
    gross_income::AbstractArray,
    m_par;
)

Compute distributional summary statistics for income and wealth, including top-10% wealth, income, and net income shares, Gini indexes for wealth and consumption, and the standard deviation of log labor earnings.

The function calculates various metrics to summarize the distribution of wealth, consumption, and income based on the provided data. It includes Gini coefficients, shares of wealth and income for the top 10%, and the standard deviation of log labor earnings.

Arguments

  • distr::AbstractArray: Joint distribution over liquid and illiquid assets and income
  • q::Real: Price of illiquid assets
  • x_a_star::AbstractArray: Optimal consumption policy with capital adjustment
  • x_n_star::AbstractArray: Optimal consumption policy without capital adjustment
  • n_par::NumericalParameters
  • net_income::AbstractArray: Vector of (on grid-)incomes (net)
  • gross_income::AbstractArray: Vector of (on grid-)incomes (gross)
  • m_par::ModelParameters

Returns

  • distr_b::AbstractArray: Distribution summary over the first dimension
  • distr_k::AbstractArray: Distribution summary over the second dimension
  • distr_h::AbstractArray: Distribution summary over the third dimension
  • TOP10Wshare::Float64: Top 10% wealth share
  • TOP10Ishare::Float64: Top 10% gross income share
  • TOP10Inetshare::Float64: Top 10% net income share
  • giniwealth::Float64: Gini coefficient for wealth
  • giniconsumption::Float64: Gini coefficient for consumption
  • sdlogy::Float64: Standard deviation of log labor earnings
source
BASEforHANK.Tools.myinterpolate3Function
myinterpolate3(
    xgrd1::AbstractVector,
    xgrd2::AbstractVector,
    xgrd3::AbstractVector,
    ygrd::AbstractArray,
    model::AbstractModel,
    xeval1::AbstractVector,
    xeval2::AbstractVector,
    xeval3::AbstractVector

)

Trilinearly project ygrd on (xgrd1, xgrd2, xgrd3) and use it to interpolate values at (xeval1, xeval2, xeval3).

Arguments

  • xgrd1, xgrd2, xgrd3::AbstractVector: Grid points along each of the three dimensions.
  • ygrd::AbstractArray: Array of function values evaluated at the grid points defined by (xgrd1, xgrd2, xgrd3).
  • model::AbstractModel: Model object, which can be of type OneAsset, TwoAsset, or CompleteMarkets.
  • xeval1, xeval2, xeval3::AbstractVector: Points at which the interpolation is performed along each dimension.

Returns

  • An array of interpolated values at the specified evaluation points (xeval1, xeval2, xeval3).

Notes

  • It assumes that xgrd1, xgrd2, and xgrd3 are sorted.
source
BASEforHANK.Tools.CustomBrentFunction
CustomBrent(f::Function, a::Real, b::Real; tol = 1e-14)

Find the root of a function using a customized version of Brent's method. This implementation adapts Brent's method by incorporating initial guesses for value functions and distributions, based on linear interpolations from the previous two iterations.

The function is designed for cases where the root-finding process needs to account for additional parameters beyond the function's value at the endpoints.

Arguments

  • f::Function: The function for which the root is being found. It should return a tuple, where the first element (f(z)[1]) represents the function value at z, and the subsequent elements represent additional parameters used for interpolation.
  • a::Real: The lower bound of the interval where the root is located.
  • b::Real: The upper bound of the interval where the root is located.
  • tol::Real: The tolerance for convergence. The default is 1e-14.

Returns

  • b::Real: The estimated root of the function.
  • iter::Int: The number of iterations used to find the root.
  • fb::Tuple: The function value at the root, along with any interpolated parameters.

Errors

  • Throws an error if the function values at a and b have the same sign, indicating no root exists in the specified interval.
source