diff --git a/src/OtherTaxes.jl b/src/OtherTaxes.jl index 2633ea3d..46948f8c 100644 --- a/src/OtherTaxes.jl +++ b/src/OtherTaxes.jl @@ -2,11 +2,12 @@ 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. @@ -14,12 +15,12 @@ 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 @@ -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 diff --git a/src/STBParameters.jl b/src/STBParameters.jl index 48339cd3..404cd624 100644 --- a/src/STBParameters.jl +++ b/src/STBParameters.jl @@ -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 @@ -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, @@ -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 diff --git a/src/SingleHouseholdCalculations.jl b/src/SingleHouseholdCalculations.jl index d877dd49..acb0f2ea 100644 --- a/src/SingleHouseholdCalculations.jl +++ b/src/SingleHouseholdCalculations.jl @@ -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 @@ -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 diff --git a/test/wealth_tests.jl b/test/wealth_tests.jl index 95f2727c..c310ca4e 100644 --- a/test/wealth_tests.jl +++ b/test/wealth_tests.jl @@ -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 @@ -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 @@ -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) @@ -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