Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add welfare component #21

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/MimiFUND.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ include("components/ImpactWaterResourcesComponent.jl")
include("components/ImpactSeaLevelRiseComponent.jl")
include("components/ImpactAggregationComponent.jl")
include("components/VslVmorbComponent.jl")
include("components/WelfareComponent.jl")

export
getfund # a function that returns a version of fund allowing for different user specifications
Expand Down Expand Up @@ -101,6 +102,7 @@ function get_model(; nsteps = default_nsteps, datadir = default_datadir, params
add_comp!(m, impactwaterresources)
add_comp!(m, impactsealevelrise)
add_comp!(m, impactaggregation)
add_comp!(m, welfare)

# ---------------------------------------------
# Connect parameters to variables
Expand Down Expand Up @@ -242,6 +244,9 @@ function get_model(; nsteps = default_nsteps, datadir = default_datadir, params
connect_param!(m, :impactaggregation, :wetcost, :impactsealevelrise, :wetcost)
connect_param!(m, :impactaggregation, :leavecost, :impactsealevelrise, :leavecost)

connect_param!(m, :welfare, :populationin1, :population, :populationin1)
connect_param!(m, :welfare, :consumption, :socioeconomic, :consumption)

# ---------------------------------------------
# Set leftover parameters
# ---------------------------------------------
Expand Down
49 changes: 49 additions & 0 deletions src/components/WelfareComponent.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
func_U(c, γ) = γ==1.0 ? log(c) : c^(1-γ)/(1-γ)
func_inv_U(u, γ) = γ==1.0 ? exp(u) : (u*(1-γ))^(1/(1-γ))
func_V(c, η) = η==1.0 ? log(c) : c^(1-η)/(1-η)

@defcomp welfare begin
regions = Index()

prtp = Parameter(default=0.015)
temporal_inequality_aversion = Parameter(default=1.5)
regional_inequality_aversion = Parameter(default=0.)

start_timeperiod::Int = Parameter(default=2020)

populationin1 = Parameter(index=[time,regions])
consumption = Parameter(index=[time,regions])

c_ede = Variable(index=[time])

welfare = Variable(index=[time])
marginal_welfare = Variable(index=[time, regions])
cum_welfare = Variable(index=[time])


function run_timestep(p, v, d, t)
year = gettime(t)

if year >= p.start_timeperiod
global_population = sum(p.populationin1[t,r] for r in d.regions)

c_ede = 0.
for r in d.regions
c_ede += func_U(p.consumption[t,r] / p.populationin1[t,r], p.regional_inequality_aversion) * p.populationin1[t,r] / global_population
end
v.c_ede[t] = func_inv_U(c_ede, p.regional_inequality_aversion)

v.welfare[t] = global_population * func_V(v.c_ede[t], p.temporal_inequality_aversion) * 1.0/(1+p.prtp)^(year-p.start_timeperiod)

if year==p.start_timeperiod
v.cum_welfare[t] = v.welfare[t]
else
v.cum_welfare[t] = v.cum_welfare[t-1] + v.welfare[t]
end

for r in d.regions
v.marginal_welfare[t,r] = v.c_ede[t]^(p.regional_inequality_aversion-p.temporal_inequality_aversion) * (p.consumption[t,r] / p.populationin1[t,r])^(-p.regional_inequality_aversion) * 1.0/(1+p.prtp)^(year-p.start_timeperiod)
end
end
end
end