From bd69b82e14c16c9036cd15cd5d640ad30f8cc089 Mon Sep 17 00:00:00 2001 From: Cora Kingdon Date: Wed, 30 Sep 2020 18:57:59 -0400 Subject: [PATCH 1/6] use variabe for ramsey discounting --- src/components/EquityWeighting.jl | 10 +++++----- src/compute_scc.jl | 19 ++++++++++++++----- test/test_standard_api.jl | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/components/EquityWeighting.jl b/src/components/EquityWeighting.jl index 0a81265a..4211bd04 100644 --- a/src/components/EquityWeighting.jl +++ b/src/components/EquityWeighting.jl @@ -118,22 +118,22 @@ v.dfc_consumptiondiscountrate[tt, rr] = v.dfc_consumptiondiscountrate[tt - 1, rr] * (1 + v.dr_discountrate[tt, rr] / 100)^(-v.yp_yearsperiod[tt]) end + ## Equity weighted impacts (end of page 28, Hope 2009) + v.wit_equityweightedimpact[tt, rr] = ((p.cons_percap_consumption_0[1]^p.emuc_utilityconvexity) / (1 - p.emuc_utilityconvexity)) * (p.cons_percap_aftercosts[tt, rr]^(1 - p.emuc_utilityconvexity) - p.rcons_percap_dis[tt, rr]^(1 - p.emuc_utilityconvexity)) * p.pop_population[tt, rr] + # Discounted costs if p.equity_proportion == 0 v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] v.wacdt_partiallyweighted_discounted[tt, rr] = p.act_adaptationcosts_total[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] + v.widt_equityweightedimpact_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] else v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] v.wacdt_partiallyweighted_discounted[tt, rr] = v.wact_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] + v.widt_equityweightedimpact_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] end v.pcdat_partiallyweighted_discountedaggregated[tt, rr] = v.pcdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] - ## Equity weighted impacts (end of page 28, Hope 2009) - v.wit_equityweightedimpact[tt, rr] = ((p.cons_percap_consumption_0[1]^p.emuc_utilityconvexity) / (1 - p.emuc_utilityconvexity)) * (p.cons_percap_aftercosts[tt, rr]^(1 - p.emuc_utilityconvexity) - p.rcons_percap_dis[tt, rr]^(1 - p.emuc_utilityconvexity)) * p.pop_population[tt, rr] - - v.widt_equityweightedimpact_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] - v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_equityweightedimpact_discounted[tt, rr] * p.yagg_periodspan[tt] v.aact_equityweightedadaptation_discountedaggregated[tt, rr] = v.wacdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] end diff --git a/src/compute_scc.jl b/src/compute_scc.jl index c5e8975e..058939fd 100644 --- a/src/compute_scc.jl +++ b/src/compute_scc.jl @@ -42,7 +42,7 @@ end @defcomp ExtraEmissions begin e_globalCO2emissions = Parameter(index=[time],unit="Mtonne/year") - pulse_size = Parameter() + pulse_size = Parameter(unit="Mtonne CO2") pulse_year = Parameter() e_globalCO2emissions_adjusted = Variable(index=[time],unit="Mtonne/year") @@ -74,7 +74,7 @@ and ptp_timepreference in the model. If no values are provided, the discount fac PAGE values of emuc_utilitiyconvexity=1.1666666667 and ptp_timepreference=1.0333333333. The size of the marginal emission pulse can be modified with the `pulse_size` keyword argument, in metric -tonnes (this does not change the units of the returned value, which is always normalized by the `pulse_size` used). +tonnes of CO2 (this does not change the units of the returned value, which is always normalized by the `pulse_size` used). By default, `n = nothing`, and a single value for the "best guess" social cost of CO2 is returned. If a positive value for keyword `n` is specified, then a Monte Carlo simulation with sample size `n` will run, sampling from @@ -88,7 +88,8 @@ function compute_scc( year::Union{Int, Nothing} = nothing, eta::Union{Float64, Nothing} = nothing, prtp::Union{Float64, Nothing} = nothing, - pulse_size = 100000., + equity_weighting::Bool = true, + pulse_size = 100_000., n::Union{Int,Nothing}=nothing, trials_output_filename::Union{String, Nothing} = nothing, seed::Union{Int, Nothing} = nothing @@ -97,7 +98,7 @@ function compute_scc( year === nothing ? error("Must specify an emission year. Try `compute_scc(m, year=2020)`.") : nothing !(year in page_years) ? error("Cannot compute the scc for year $year, year must be within the model's time index $page_years.") : nothing - if eta != nothing + if eta !== nothing try set_param!(m, :emuc_utilityconvexity, eta) # since eta is a default parameter in PAGE, we need to use `set_param!` if it hasn't been set yet catch e @@ -105,13 +106,21 @@ function compute_scc( end end - if prtp != nothing + if prtp !== nothing try set_param!(m, :ptp_timepreference, prtp * 100) # since prtp is a default parameter in PAGE, we need to use `set_param!` if it hasn't been set yet catch e update_param!(m, :ptp_timepreference, prtp * 100) # or update_param! if it has been set end end + + if !equity_weighting #&& eta != 0 + try + set_param!(m, :equity_proportion, 0) + catch e + update_param!(m, :equity_proportion, 0) + end + end mm = get_marginal_model(m, year=year, pulse_size=pulse_size) # Returns a marginal model that has already been run diff --git a/test/test_standard_api.jl b/test/test_standard_api.jl index e6615cd8..41cc5856 100644 --- a/test/test_standard_api.jl +++ b/test/test_standard_api.jl @@ -34,4 +34,19 @@ sccs2 = MimiPAGE2009.compute_scc(year=2020, n=10, seed=350) sccs3 = MimiPAGE2009.compute_scc(year=2020, n=10, seed=351) @test sccs3 != sccs1 +#Test equity weighting options + +# Test that regional equity weighting inreases the SCC +@test MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = true) > + MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = false) + +# Test that when eta==0, equity_weighting does not change the SCC value +@test MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = true) == + MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = false) + +# Test Monte Carlo w/ and w/o equity weighting, with the same seed +scc10a = MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = true, n = 10, seed=350) +scc10b = MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = false, n = 10, seed=350) +@test all(scc10a .> scc10b) + end \ No newline at end of file From f1bf00e91e785ae261b6954e611e6474ed8e8273 Mon Sep 17 00:00:00 2001 From: Cora Kingdon Date: Wed, 30 Sep 2020 19:04:21 -0400 Subject: [PATCH 2/6] rename weighted variable --- src/components/EquityWeighting.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/EquityWeighting.jl b/src/components/EquityWeighting.jl index 4211bd04..e84601d9 100644 --- a/src/components/EquityWeighting.jl +++ b/src/components/EquityWeighting.jl @@ -57,7 +57,7 @@ rcons_percap_dis = Parameter(index=[time, region], unit="\$/person") wit_equityweightedimpact = Variable(index=[time, region], unit="\$million") - widt_equityweightedimpact_discounted = Variable(index=[time, region], unit="\$million") + widt_partiallyweighted_discounted = Variable(index=[time, region], unit="\$million") yagg_periodspan = Parameter(index=[time], unit="year") @@ -125,16 +125,16 @@ if p.equity_proportion == 0 v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] v.wacdt_partiallyweighted_discounted[tt, rr] = p.act_adaptationcosts_total[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] - v.widt_equityweightedimpact_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] + v.widt_partiallyweighted_discounted [tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] else v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] v.wacdt_partiallyweighted_discounted[tt, rr] = v.wact_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] - v.widt_equityweightedimpact_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] + v.widt_partiallyweighted_discounted [tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] end v.pcdat_partiallyweighted_discountedaggregated[tt, rr] = v.pcdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] - v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_equityweightedimpact_discounted[tt, rr] * p.yagg_periodspan[tt] + v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_partiallyweighted_discounted [tt, rr] * p.yagg_periodspan[tt] v.aact_equityweightedadaptation_discountedaggregated[tt, rr] = v.wacdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] end From 666291a1449a23d3c65d0e0f0548ed3f4b198d9e Mon Sep 17 00:00:00 2001 From: Cora Kingdon Date: Wed, 30 Sep 2020 19:28:37 -0400 Subject: [PATCH 3/6] fix whitespace problem --- src/components/EquityWeighting.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/EquityWeighting.jl b/src/components/EquityWeighting.jl index e84601d9..644c0483 100644 --- a/src/components/EquityWeighting.jl +++ b/src/components/EquityWeighting.jl @@ -125,16 +125,16 @@ if p.equity_proportion == 0 v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] v.wacdt_partiallyweighted_discounted[tt, rr] = p.act_adaptationcosts_total[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] - v.widt_partiallyweighted_discounted [tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] + v.widt_partiallyweighted_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] else v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] v.wacdt_partiallyweighted_discounted[tt, rr] = v.wact_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] - v.widt_partiallyweighted_discounted [tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] + v.widt_partiallyweighted_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] end v.pcdat_partiallyweighted_discountedaggregated[tt, rr] = v.pcdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] - v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_partiallyweighted_discounted [tt, rr] * p.yagg_periodspan[tt] + v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] v.aact_equityweightedadaptation_discountedaggregated[tt, rr] = v.wacdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] end From 84352c8119d59626888da01dbb7776e16502b641 Mon Sep 17 00:00:00 2001 From: James Rising Date: Fri, 2 Oct 2020 15:50:47 +0100 Subject: [PATCH 4/6] swap out equity weighting --- src/components/EquityWeighting.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/EquityWeighting.jl b/src/components/EquityWeighting.jl index 644c0483..01c4b606 100644 --- a/src/components/EquityWeighting.jl +++ b/src/components/EquityWeighting.jl @@ -56,7 +56,7 @@ # Equity weighted impact totals rcons_percap_dis = Parameter(index=[time, region], unit="\$/person") - wit_equityweightedimpact = Variable(index=[time, region], unit="\$million") + wit_partiallyweighted = Variable(index=[time, region], unit="\$million") widt_partiallyweighted_discounted = Variable(index=[time, region], unit="\$million") yagg_periodspan = Parameter(index=[time], unit="year") @@ -118,22 +118,23 @@ v.dfc_consumptiondiscountrate[tt, rr] = v.dfc_consumptiondiscountrate[tt - 1, rr] * (1 + v.dr_discountrate[tt, rr] / 100)^(-v.yp_yearsperiod[tt]) end - ## Equity weighted impacts (end of page 28, Hope 2009) - v.wit_equityweightedimpact[tt, rr] = ((p.cons_percap_consumption_0[1]^p.emuc_utilityconvexity) / (1 - p.emuc_utilityconvexity)) * (p.cons_percap_aftercosts[tt, rr]^(1 - p.emuc_utilityconvexity) - p.rcons_percap_dis[tt, rr]^(1 - p.emuc_utilityconvexity)) * p.pop_population[tt, rr] - # Discounted costs if p.equity_proportion == 0 v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] v.wacdt_partiallyweighted_discounted[tt, rr] = p.act_adaptationcosts_total[tt, rr] * v.dfc_consumptiondiscountrate[tt, rr] - v.widt_partiallyweighted_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.dfc_consumptiondiscountrate[tt] + + v.wit_partiallyweighted[tt, rr] = (p.cons_percap_aftercosts[tt, rr] - p.rcons_percap_dis[tt, rr]) * p.pop_population[tt, rr] # equivalent to emuc = 0 + v.widt_partiallyweighted_discounted[tt, rr] = v.wit_partiallyweighted[tt, rr] * v.dfc_consumptiondiscountrate[tt] # apply Ramsey discounting else v.pcdt_partiallyweighted_discounted[tt, rr] = v.pct_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] v.wacdt_partiallyweighted_discounted[tt, rr] = v.wact_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] - v.widt_partiallyweighted_discounted[tt, rr] = v.wit_equityweightedimpact[tt, rr] * v.df_utilitydiscountfactor[tt] + + ## Equity weighted impacts (end of page 28, Hope 2009) + v.wit_partiallyweighted[tt, rr] = ((p.cons_percap_consumption_0[1]^p.emuc_utilityconvexity) / (1 - p.emuc_utilityconvexity)) * (p.cons_percap_aftercosts[tt, rr]^(1 - p.emuc_utilityconvexity) - p.rcons_percap_dis[tt, rr]^(1 - p.emuc_utilityconvexity)) * p.pop_population[tt, rr] + v.widt_partiallyweighted_discounted[tt, rr] = v.wit_partiallyweighted[tt, rr] * v.df_utilitydiscountfactor[tt] end v.pcdat_partiallyweighted_discountedaggregated[tt, rr] = v.pcdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] - v.addt_equityweightedimpact_discountedaggregated[tt, rr] = v.widt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] v.aact_equityweightedadaptation_discountedaggregated[tt, rr] = v.wacdt_partiallyweighted_discounted[tt, rr] * p.yagg_periodspan[tt] end From c4d59a0fe501915947b0a886ad0cf1eae9b6af8d Mon Sep 17 00:00:00 2001 From: Cora Kingdon Date: Fri, 2 Oct 2020 12:48:11 -0400 Subject: [PATCH 5/6] fix renamed variable in test --- test/test_EquityWeighting.jl | 4 ++-- ...wit_equityweightedimpact.csv => wit_partiallyweighted.csv} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename test/validationdata/{wit_equityweightedimpact.csv => wit_partiallyweighted.csv} (100%) diff --git a/test/test_EquityWeighting.jl b/test/test_EquityWeighting.jl index 64949424..6ca281b2 100644 --- a/test/test_EquityWeighting.jl +++ b/test/test_EquityWeighting.jl @@ -34,7 +34,7 @@ pcdt = m[:EquityWeighting, :pcdt_partiallyweighted_discounted] wacdt = m[:EquityWeighting, :wacdt_partiallyweighted_discounted] aact = m[:EquityWeighting, :aact_equityweightedadaptation_discountedaggregated] -wit = m[:EquityWeighting, :wit_equityweightedimpact] +wit = m[:EquityWeighting, :wit_partiallyweighted] addt = m[:EquityWeighting, :addt_equityweightedimpact_discountedaggregated] addt_gt = m[:EquityWeighting, :addt_gt_equityweightedimpact_discountedglobal] te = m[:EquityWeighting, :te_totaleffect] @@ -50,7 +50,7 @@ pcdt_compare = readpagedata(m, "test/validationdata/pcdt_partiallyweighted_disco wacdt_compare = readpagedata(m, "test/validationdata/wacdt_partiallyweighted_discounted.csv") aact_compare = readpagedata(m, "test/validationdata/aact_equityweightedadaptation_discountedaggregated.csv") -wit_compare = readpagedata(m, "test/validationdata/wit_equityweightedimpact.csv") +wit_compare = readpagedata(m, "test/validationdata/wit_partiallyweighted.csv") addt_compare = readpagedata(m, "test/validationdata/addt_equityweightedimpact_discountedaggregated.csv") addt_gt_compare = 204132238.85242900 te_compare = 213208136.69903600 diff --git a/test/validationdata/wit_equityweightedimpact.csv b/test/validationdata/wit_partiallyweighted.csv similarity index 100% rename from test/validationdata/wit_equityweightedimpact.csv rename to test/validationdata/wit_partiallyweighted.csv From 275bac4988b14718e37469e64106048238292335 Mon Sep 17 00:00:00 2001 From: Cora Kingdon Date: Tue, 6 Oct 2020 10:19:42 -0400 Subject: [PATCH 6/6] relax test tolerance --- src/compute_scc.jl | 2 +- test/test_standard_api.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compute_scc.jl b/src/compute_scc.jl index 058939fd..fbab3380 100644 --- a/src/compute_scc.jl +++ b/src/compute_scc.jl @@ -114,7 +114,7 @@ function compute_scc( end end - if !equity_weighting #&& eta != 0 + if !equity_weighting try set_param!(m, :equity_proportion, 0) catch e diff --git a/test/test_standard_api.jl b/test/test_standard_api.jl index 41cc5856..a21bfcfe 100644 --- a/test/test_standard_api.jl +++ b/test/test_standard_api.jl @@ -41,8 +41,8 @@ sccs3 = MimiPAGE2009.compute_scc(year=2020, n=10, seed=351) MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = false) # Test that when eta==0, equity_weighting does not change the SCC value -@test MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = true) == - MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = false) +@test MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = true) ≈ + MimiPAGE2009.compute_scc(year=2020, eta=0., prtp = 0.03, equity_weighting = false) atol=1e3 # Test Monte Carlo w/ and w/o equity weighting, with the same seed scc10a = MimiPAGE2009.compute_scc(year=2020, eta=1.5, prtp = 0.01, equity_weighting = true, n = 10, seed=350)