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.Tauchen
— FunctionTauchen(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 coefficientN::Int
: number of gridpointssigma::Float64
: long-run variancemue::Float64
: mean of the AR(1) process
Returns
grid_vec::Vector
: state vector grid of dimensionN
P::Array{Float64, 2}
: transition matrix of dimensionN x N
bounds::Vector
: bin bounds of dimensionN + 1
#, transtype::Symbol = :importance)
BASEforHANK.Tools.distrSummaries
— FunctiondistrSummaries(
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 incomeq::Real
: Price of illiquid assetsx_a_star::AbstractArray
: Optimal consumption policy with capital adjustmentx_n_star::AbstractArray
: Optimal consumption policy without capital adjustmentn_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 dimensiondistr_k::AbstractArray
: Distribution summary over the second dimensiondistr_h::AbstractArray
: Distribution summary over the third dimensionTOP10Wshare::Float64
: Top 10% wealth shareTOP10Ishare::Float64
: Top 10% gross income shareTOP10Inetshare::Float64
: Top 10% net income shareginiwealth::Float64
: Gini coefficient for wealthginiconsumption::Float64
: Gini coefficient for consumptionsdlogy::Float64
: Standard deviation of log labor earnings
BASEforHANK.Tools.myinterpolate3
— Functionmyinterpolate3(
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 typeOneAsset
,TwoAsset
, orCompleteMarkets
.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
, andxgrd3
are sorted.
BASEforHANK.Tools.CustomBrent
— FunctionCustomBrent(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 atz
, 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 is1e-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
andb
have the same sign, indicating no root exists in the specified interval.