Skip to content

Commit

Permalink
More efficient credit market loop (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Dec 23, 2024
1 parent aba00a1 commit c8c1356
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/markets/search_and_matching_credit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 6 additions & 8 deletions test/deterministic/make_model_deterministic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8c1356

Please sign in to comment.