Skip to content

Commit

Permalink
cleaned up Wealth
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamstark committed Sep 5, 2023
1 parent 8e3cd48 commit 2aa1a8c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/OtherTaxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ module OtherTaxes

using ScottishTaxBenefitModel
using .Definitions
using .GeneralTaxComponents: calctaxdue
using .ModelHousehold
using .Results
using .STBParameters
using .STBIncomes
export calculate_other_taxes!
export calculate_other_taxes!, calculate_wealth_tax!

"""
Flat rate wealth tax, assigned soley to HH head.
"""
function calculate_wealth_tax!(
household_result :: HouseholdResult,
hh :: Household,
sys :: WealthTax )
sys :: WealthTaxSys )
hd = get_head( hh )
pres = household_result.bus[1].pers[ hd.pid ]
wealth = 0.0
# to individual level
if sys.wealth.abolished > 0
if sys.abolished > 0
return
end
if net_physical_wealth in sys.included_wealth
Expand All @@ -34,11 +35,11 @@ function calculate_wealth_tax!(
if net_pension_wealth in sys.included_wealth
wealth += hh.net_pension_wealth
end

# println( "hh $(hh.hid); got wealth as $wealth")
wealth = max( 0.0, wealth - sys.allowance )
wtax = calctaxdue( taxable=wealth, rates=sys.rates, thresholds=sys.thresholds )
pres.wealth.total = wtax.due
pres.wealth.weekly_equiv = pres.wealth.total * sys.weekly_rate
pres.wealth.total_payable = wtax.due
pres.wealth.weekly_equiv = pres.wealth.total_payable * sys.weekly_rate
household_result.bus[1].pers[ hd.pid ].income[OTHER_TAX] += pres.wealth.weekly_equiv
end

Expand Down
9 changes: 5 additions & 4 deletions src/STBParameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module STBParameters
export WidowsPensions, BereavementSupport, RetirementPension, JobSeekersAllowance
export NonMeansTestedSys, MaternityAllowance, ChildLimits
export BenefitCapSys, make_ubi_pre_adjustments!
export OtherTaxesSys, IndirectTaxSystem, VATSystem
export OtherTaxesSys, IndirectTaxSystem, VATSystem, WealthTaxSys

const MCA_DATE = Date(1935,4,6) # fixme make this a parameter

Expand Down Expand Up @@ -954,13 +954,14 @@ I More than £424,000

# these are roughly the parameters
@with_kw mutable struct WealthTaxSys{RT<:Real}
abolished :: Boolean = true
one_off :: Boolean = true
abolished :: Bool = true
one_off :: Bool = true
payment_years :: Int = 0
weekly_rate :: RT = zero(RT)
rates :: RateBands{RT} = [zero(RT)]
thresholds :: RateBands{RT} = [zero(RT)]
allowance :: RT = zero(RT)
aggregation :: AggregationLevel = household
included_wealth = WealthSet([
net_physical_wealth,
net_financial_wealth,
Expand All @@ -969,7 +970,7 @@ I More than £424,000

function weeklyise!( wealth :: WealthTaxSys; wpm=WEEKS_PER_MONTH, wpy=WEEKS_PER_YEAR )
wealth.weekly_rate = 0.0
if( wealth.payment_years > 0 ) && (!wealth.one_off)
if( wealth.payment_years > 0 ) && (wealth.one_off)
wealth.weekly_rate = 1/(wealth.payment_years*wpy)
end
end
Expand Down
5 changes: 4 additions & 1 deletion src/SingleHouseholdCalculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ using .ScottishBenefits:

using .UBI: calc_UBI!, make_ubi_post_adjustments!

using .OtherTaxes: calculate_other_taxes!
using .OtherTaxes: calculate_other_taxes!, calculate_wealth_tax!

export do_one_calc

Expand Down Expand Up @@ -220,6 +220,9 @@ function do_one_calc(
if ! sys.ubi.abolished
make_ubi_post_adjustments!( hres, sys.ubi )
end
if ! sys.wealth.abolished
calculate_wealth_tax!( hres, hh, sys.wealth )
end

calculate_other_taxes!( hres, hh, sys.othertaxes )
if settings.do_indirect_tax_calculations
Expand Down
46 changes: 37 additions & 9 deletions test/wealth_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ using .ExampleHelpers
using .HouseholdFromFrame: create_regression_dataframe
using .ModelHousehold
using .Monitor: Progress
using .OtherTaxes: calculate_other_taxes!
using .Runner
using .OtherTaxes: calculate_other_taxes!,calculate_wealth_tax!
using .Results
using .RunSettings
using .SingleHouseholdCalculations
using .STBIncomes
using .STBOutput
using .Utils

using CSV
Expand All @@ -21,18 +24,38 @@ using StatsBase


@testset "Wealth Tax Examples" begin
sys = get_system( year=2023, scotland=true )
sys.wealth.rates = [0.01]
sys = get_system( year=2023, scotland=false )
settings = get_all_uk_settings_2023()
sys.wealth.rates = [0.05]
sys.wealth.thresholds = []
sys.wealth.abolished = false
sys.wealth.allowance = 500_000.0
sys.wealth.one_off = true
sys.wealth.aggregation = household
sys.wealth.payment_years = 5
weeklyise!( sys.wealth )
hh = make_hh()
hd = get_head( hh )
println( INCOME_TAXES )
println( sys.wealth )
t = [0,0,0.0,0.0,90_000.00]
for w in [0,1_000,100_000.0,1_000_000.0,10_000_000.0]
hh.net_physical_wealth = w
hres = init_household_result( hh )
calculate_other_taxes!( hres, hh, sys.othertaxes )
calculate_wealth_tax!( hres, hh, sys.wealth )
aggregate!( hh, hres )
@test hres.income[OTHER_TAX] max(0,w-sys.wealth.allowance) *sys.wealth.rates[1]
println( hres.bus[1].pers[hd.pid].wealth )
@test hres.income[OTHER_TAX] max(0,w-sys.wealth.allowance) * sys.wealth.rates[1] * sys.wealth.weekly_rate
println( "hres.bhc_net_income=$(hres.bhc_net_income)" )
end
t = [0,0,0.0,0.0,90_000.00]
for w in [0,1_000,100_000.0,1_000_000.0,10_000_000.0]
hh.net_physical_wealth = w
hres = init_household_result( hh )
hres = do_one_calc( hh, sys, settings )
aggregate!( hh, hres )
println( hres.bus[1].pers[hd.pid].wealth )
@test hres.income[OTHER_TAX] max(0,w-sys.wealth.allowance) * sys.wealth.rates[1] * sys.wealth.weekly_rate
println( "hres.bhc_net_income=$(hres.bhc_net_income)" )
end
end
Expand All @@ -44,7 +67,6 @@ end
# observer = Observer(Progress("",0,0,0))
obs = Observable( Progress(settings.uuid,"",0,0,0,0))
of = on(obs) do p
global tot
println(p)
tot += p.step
println(tot)
Expand All @@ -53,14 +75,20 @@ end
@time settings.num_households, settings.num_people, nhh2 = initialise( settings; reset=true )
settings.requested_threads = 4
settings.ineq_income_measure = eq_bhc_net_income
# FIXME 2019->2023
sys1 = get_system(year=2023, scotland=false)
sys2 = deepcopy(sys1)
sys.wealth.rates = [0.01]
sys.wealth.thresholds = []
sys2.wealth.rates = [0.05]
sys2.wealth.thresholds = []
sys2.wealth.abolished = false
sys2.wealth.allowance = 500_000.0
sys2.wealth.one_off = true
sys2.wealth.aggregation = household
sys2.wealth.payment_years = 5
weeklyise!( sys2.wealth )
sys = [sys1, sys2]
results = do_one_run( settings, sys, obs )
outf = summarise_frames!( results, settings )
dump_frames( settings, results )
end

@testset "Corporation Tax" begin
Expand Down

0 comments on commit 2aa1a8c

Please sign in to comment.