diff --git a/src/markets/search_and_matching_credit.jl b/src/markets/search_and_matching_credit.jl index 69dcf32..011a14a 100644 --- a/src/markets/search_and_matching_credit.jl +++ b/src/markets/search_and_matching_credit.jl @@ -18,11 +18,14 @@ function search_and_matching_credit(firms::AbstractFirms, model) E_k, zeta, zeta_LTV = model.bank.E_k, model.prop.zeta, model.prop.zeta_LTV DL_i = zeros(size(DL_d_i)) + sum_DL_i = sum(DL_i) I_FG = findall(DL_d_i .> 0) shuffle!(I_FG) s_L_e_i = sum(L_e_i) for i in I_FG - DL_i[i] = max(0.0, min(DL_d_i[i], zeta_LTV * K_e_i[i] - L_e_i[i], E_k / zeta - s_L_e_i - sum(DL_i))) + DL_i_p = DL_i[i] + DL_i[i] = max(0.0, min(DL_d_i[i], zeta_LTV * K_e_i[i] - L_e_i[i], E_k / zeta - s_L_e_i - sum_DL_i)) + sum_DL_i += (DL_i[i] - DL_i_p) end return DL_i end diff --git a/test/deterministic/make_model_deterministic.jl b/test/deterministic/make_model_deterministic.jl index 5b03dd7..e7ea272 100644 --- a/test/deterministic/make_model_deterministic.jl +++ b/test/deterministic/make_model_deterministic.jl @@ -7,20 +7,18 @@ import Random: shuffle!, rand, randn import StatsBase: wsample using Distributions -function allinds(s::DynamicSampler) - return sort!(reduce(vcat, s.level_buckets)) +function allinds(sp::DynamicSampler) + inds = collect(Iterators.Flatten((Iterators.map(x -> x[1], b) for b in sp.level_buckets))) + return sort!(inds) end function randn() return 0.0 end -function rand(s::DynamicSampler) - idx = minimum(minimum.(s.level_buckets; init=typemax(Int))) - weight = s.weights[idx] - level = ceil(Int, log2(weight)) - s.info.level_min + 1 - idx_in_level = findfirst(x -> x == idx, s.level_buckets[level]) - return idx +function rand(sp::DynamicSampler) + inds = collect(Iterators.Flatten((Iterators.map(x -> x[1], b) for b in sp.level_buckets))) + return minimum(inds) end function rand(n::UnitRange) return 1