|
| 1 | +"""Example: Calculate household tax and benefit impacts. |
| 2 | +
|
| 3 | +This script demonstrates using calculate_household_impact for both UK and US |
| 4 | +to compute taxes and benefits for custom households. |
| 5 | +
|
| 6 | +Run: python examples/household_impact_example.py |
| 7 | +""" |
| 8 | + |
| 9 | +from policyengine.tax_benefit_models.uk import ( |
| 10 | + UKHouseholdInput, |
| 11 | +) |
| 12 | +from policyengine.tax_benefit_models.uk import ( |
| 13 | + calculate_household_impact as calculate_uk_impact, |
| 14 | +) |
| 15 | +from policyengine.tax_benefit_models.us import ( |
| 16 | + USHouseholdInput, |
| 17 | +) |
| 18 | +from policyengine.tax_benefit_models.us import ( |
| 19 | + calculate_household_impact as calculate_us_impact, |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +def uk_example(): |
| 24 | + """UK household impact example.""" |
| 25 | + print("=" * 60) |
| 26 | + print("UK HOUSEHOLD IMPACT") |
| 27 | + print("=" * 60) |
| 28 | + |
| 29 | + # Single adult earning £50,000 |
| 30 | + household = UKHouseholdInput( |
| 31 | + people=[{"age": 35, "employment_income": 50_000}], |
| 32 | + year=2026, |
| 33 | + ) |
| 34 | + result = calculate_uk_impact(household) |
| 35 | + |
| 36 | + print("\nSingle adult, £50k income:") |
| 37 | + print( |
| 38 | + f" Net income: £{result.household['hbai_household_net_income']:,.0f}" |
| 39 | + ) |
| 40 | + print(f" Income tax: £{result.person[0]['income_tax']:,.0f}") |
| 41 | + print( |
| 42 | + f" National Insurance: £{result.person[0]['national_insurance']:,.0f}" |
| 43 | + ) |
| 44 | + print(f" Total tax: £{result.household['household_tax']:,.0f}") |
| 45 | + |
| 46 | + # Family with two children, £30k income, renting |
| 47 | + household = UKHouseholdInput( |
| 48 | + people=[ |
| 49 | + {"age": 35, "employment_income": 30_000}, |
| 50 | + {"age": 33}, |
| 51 | + {"age": 8}, |
| 52 | + {"age": 5}, |
| 53 | + ], |
| 54 | + benunit={ |
| 55 | + "would_claim_uc": True, |
| 56 | + "would_claim_child_benefit": True, |
| 57 | + }, |
| 58 | + household={ |
| 59 | + "rent": 12_000, # £1k/month |
| 60 | + "region": "NORTH_WEST", |
| 61 | + }, |
| 62 | + year=2026, |
| 63 | + ) |
| 64 | + result = calculate_uk_impact(household) |
| 65 | + |
| 66 | + print("\nFamily (2 adults, 2 children), £30k income, renting:") |
| 67 | + print( |
| 68 | + f" Net income: £{result.household['hbai_household_net_income']:,.0f}" |
| 69 | + ) |
| 70 | + print(f" Income tax: £{result.person[0]['income_tax']:,.0f}") |
| 71 | + print(f" Child benefit: £{result.benunit[0]['child_benefit']:,.0f}") |
| 72 | + print(f" Universal credit: £{result.benunit[0]['universal_credit']:,.0f}") |
| 73 | + print(f" Total benefits: £{result.household['household_benefits']:,.0f}") |
| 74 | + |
| 75 | + |
| 76 | +def us_example(): |
| 77 | + """US household impact example.""" |
| 78 | + print("\n" + "=" * 60) |
| 79 | + print("US HOUSEHOLD IMPACT") |
| 80 | + print("=" * 60) |
| 81 | + |
| 82 | + # Single adult earning $50,000 |
| 83 | + household = USHouseholdInput( |
| 84 | + people=[ |
| 85 | + {"age": 35, "employment_income": 50_000, "is_tax_unit_head": True} |
| 86 | + ], |
| 87 | + tax_unit={"filing_status": "SINGLE"}, |
| 88 | + household={"state_code_str": "CA"}, |
| 89 | + year=2024, |
| 90 | + ) |
| 91 | + result = calculate_us_impact(household) |
| 92 | + |
| 93 | + print("\nSingle adult, $50k income (California):") |
| 94 | + print(f" Net income: ${result.household['household_net_income']:,.0f}") |
| 95 | + print(f" Income tax: ${result.tax_unit[0]['income_tax']:,.0f}") |
| 96 | + print(f" Payroll tax: ${result.tax_unit[0]['employee_payroll_tax']:,.0f}") |
| 97 | + |
| 98 | + # Married couple with children, lower income |
| 99 | + household = USHouseholdInput( |
| 100 | + people=[ |
| 101 | + {"age": 35, "employment_income": 40_000, "is_tax_unit_head": True}, |
| 102 | + {"age": 33, "is_tax_unit_spouse": True}, |
| 103 | + {"age": 8, "is_tax_unit_dependent": True}, |
| 104 | + {"age": 5, "is_tax_unit_dependent": True}, |
| 105 | + ], |
| 106 | + tax_unit={"filing_status": "JOINT"}, |
| 107 | + household={"state_code_str": "TX"}, |
| 108 | + year=2024, |
| 109 | + ) |
| 110 | + result = calculate_us_impact(household) |
| 111 | + |
| 112 | + print("\nMarried couple with 2 children, $40k income (Texas):") |
| 113 | + print(f" Net income: ${result.household['household_net_income']:,.0f}") |
| 114 | + print(f" Federal income tax: ${result.tax_unit[0]['income_tax']:,.0f}") |
| 115 | + print(f" EITC: ${result.tax_unit[0]['eitc']:,.0f}") |
| 116 | + print(f" Child tax credit: ${result.tax_unit[0]['ctc']:,.0f}") |
| 117 | + print(f" SNAP: ${result.spm_unit[0]['snap']:,.0f}") |
| 118 | + |
| 119 | + |
| 120 | +def main(): |
| 121 | + uk_example() |
| 122 | + us_example() |
| 123 | + print("\n" + "=" * 60) |
| 124 | + print("Done!") |
| 125 | + |
| 126 | + |
| 127 | +if __name__ == "__main__": |
| 128 | + main() |
0 commit comments