Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
44132ab
Refactor earned_taxable_income
MaxGhenis Dec 23, 2021
31e2cb1
Add currency for variables in liability.py
MaxGhenis Dec 23, 2021
ee979ce
Refactor formulas in liability.py
MaxGhenis Dec 23, 2021
9dc6987
Refactor formulas in allowances.py
MaxGhenis Dec 23, 2021
ed65c50
Refactor formulas in relief.py
MaxGhenis Dec 23, 2021
a94a70a
Refactor formulas in tax.py
MaxGhenis Dec 23, 2021
6fb9d00
Refactor formulas in NI class_1.py
MaxGhenis Dec 23, 2021
ce355b4
Refactor formulas in class_2.py
MaxGhenis Dec 23, 2021
d1d21c4
Refactor formulas in class_4.py
MaxGhenis Dec 23, 2021
c3958d4
Refactor expense.py
MaxGhenis Dec 23, 2021
937b614
Refactor income.py
MaxGhenis Dec 23, 2021
64121bd
Refactor benefit.py
MaxGhenis Dec 23, 2021
3d0b00d
Bump version
MaxGhenis Dec 23, 2021
b29e0b8
Update changelog
MaxGhenis Dec 24, 2021
9cf07d8
Refactor poverty.py
MaxGhenis Dec 24, 2021
6da5f0b
Refactor property.py
MaxGhenis Dec 24, 2021
f55a761
Refactor benunit.py
MaxGhenis Dec 24, 2021
0d00a27
Refactor household.py
MaxGhenis Dec 24, 2021
da22d30
Fix bug
MaxGhenis Dec 24, 2021
d285009
Refactor person.py
MaxGhenis Dec 24, 2021
1cda71f
Refactor poverty.py
MaxGhenis Dec 24, 2021
de8fd82
Fix age between bug
MaxGhenis Dec 24, 2021
2f1522e
Refactor marriage_allowance
MaxGhenis Dec 24, 2021
bd9e71a
Refactor person.py
MaxGhenis Dec 24, 2021
a592c41
Consolidate imports to `from openfisca_uk.model_api import *`
MaxGhenis Dec 24, 2021
9e775de
Add unit test for meets_marriage_allowance_income_conditions
MaxGhenis Dec 24, 2021
b63d170
Refactor benunit_is_renting
MaxGhenis Dec 24, 2021
e342732
Remove isin from meets_marriage_allowance_income_conditions, which is…
MaxGhenis Dec 24, 2021
a744be5
Refactor housing_benefit.py
MaxGhenis Dec 24, 2021
d09ad5c
Refactoring of household and benunift functions
MaxGhenis Dec 24, 2021
2d96a6e
Revert switch from `is_in` to `np.isin`
MaxGhenis Dec 24, 2021
09c07f6
Remove unnecessary import
MaxGhenis Dec 24, 2021
31366fe
Refactor LTT
MaxGhenis Dec 24, 2021
8b8b7d6
refactor benefit_cap.py
MaxGhenis Dec 24, 2021
cee34af
refactor council_tax_benefit
MaxGhenis Dec 24, 2021
63959f3
Refactor ESA_income.py
MaxGhenis Dec 24, 2021
60dc034
Refactor housing_benefit.py
MaxGhenis Dec 24, 2021
ecaee0c
Refactor income_support
MaxGhenis Dec 24, 2021
af2568b
Refactor JSA_income_eligible
MaxGhenis Dec 24, 2021
f89a526
Refactor JSA_income_applicable_amount
MaxGhenis Dec 24, 2021
59c069b
Refactor remaining variables in JSA_income.py
MaxGhenis Dec 24, 2021
78595bc
Refactor LHA.py
MaxGhenis Dec 25, 2021
c1f1bc4
Refactor pension_credit.py
MaxGhenis Dec 25, 2021
9b12c01
Refactor tax_credits.py
MaxGhenis Dec 25, 2021
979e596
Refactor about half of universal_credit.py
MaxGhenis Dec 25, 2021
a7207bd
Refactor remainder of universal_credit.py
MaxGhenis Dec 25, 2021
ae5f689
Apply aggr and refactor benefit_cap
MaxGhenis Dec 25, 2021
ee0ba68
Refactor council_tax_benefit.py and ESA_income.py
MaxGhenis Dec 25, 2021
f6b4648
Refactor housing_benefit_applicable_income
MaxGhenis Dec 25, 2021
7bc61b6
Fix benefit_cap bug
MaxGhenis Dec 25, 2021
73e6059
More housing_benefit.py refactoring
MaxGhenis Dec 25, 2021
cc4ccb5
Refactor income_support.py
MaxGhenis Dec 25, 2021
bc2e7dd
Refactor JSA_income.py
MaxGhenis Dec 25, 2021
59a796d
Refactor personal benefits
MaxGhenis Dec 25, 2021
f3a618b
Refactor benefit.py
MaxGhenis Dec 25, 2021
c8c2602
Refactor care.py
MaxGhenis Dec 25, 2021
a4fc5ae
Refactor disability.py
MaxGhenis Dec 25, 2021
03915a9
Add currency unit to allowances.py
MaxGhenis Dec 25, 2021
0fe34a3
Refactor income tax files
MaxGhenis Dec 25, 2021
ebf49a5
Minor changes
MaxGhenis Dec 25, 2021
4304c65
Refactor expense and income
MaxGhenis Dec 25, 2021
9fb0698
Refactor remaining formulas
MaxGhenis Dec 25, 2021
1bb2086
Fix bug in ESA_income.py
MaxGhenis Dec 25, 2021
72f0304
Minor changes
MaxGhenis Dec 25, 2021
83e5f47
Undo accidental replacement of default with lower in WTC
MaxGhenis Dec 25, 2021
5a2e1cc
refactor family_type
MaxGhenis Dec 25, 2021
ce257dd
refactor claims_UC
MaxGhenis Dec 25, 2021
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
22 changes: 13 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

* First stable version with tax modelling, UBI reforms, and some benefits modelling.
* Details:
- Income Tax, National Insurance, Capital Gains Tax.
- All benefits are at least taken from survey reporting (can be switched on-off).
- Child Benefit is modelled, others such as Income Support, JSA (both types), Tax Credits can be simulated/reformed but require more reviewing in how to account for discrepancies caused by take-up rates.
- Four budget-neutral UBI reforms are implemented.
- 15 test cases (unit and integration) testing benefits and taxes.
- Simulation helper tools.
+ Income Tax, National Insurance, Capital Gains Tax.
+ All benefits are at least taken from survey reporting (can be switched on-off).
+ Child Benefit is modelled, others such as Income Support, JSA (both types), Tax Credits can be simulated/reformed but require more reviewing in how to account for discrepancies caused by take-up rates.
+ Four budget-neutral UBI reforms are implemented.
+ 15 test cases (unit and integration) testing benefits and taxes.
+ Simulation helper tools.

### 0.2.0

* Improvements to handling of time periods, MTRs and more
* Details:
- Time periods now appropriate, using an implementation of WEEK for most benefits
- MTRs handled properly and include a breakdown
- Simulation tools are improved and included in a class
+ Time periods now appropriate, using an implementation of WEEK for most benefits
+ MTRs handled properly and include a breakdown
+ Simulation tools are improved and included in a class

### 0.2.1

Expand Down Expand Up @@ -51,3 +51,7 @@
* Tests for variable naming conventions
* Postcode lookup optional features available
* LHA rates for all BRMA areas added

### 0.7.17

* Code refactoring, including adding units to more variables
3 changes: 1 addition & 2 deletions openfisca_uk/config/postcode_lookup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *
from openfisca_uk.variables.demographic.locations import LocalAuthority
import pandas as pd

Expand Down
3 changes: 1 addition & 2 deletions openfisca_uk/reforms/presets/modelling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *


class tax(Variable):
Expand Down
3 changes: 1 addition & 2 deletions openfisca_uk/reforms/tools/parametric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import openfisca_uk
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *
from typing import Union


Expand Down
3 changes: 1 addition & 2 deletions openfisca_uk/reforms/tools/structural.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *
from typing import Union


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- name: Basic rate band is eligible for Marriage Allowance
period: 2021
input:
tax_band: BASIC
output:
meets_marriage_allowance_income_conditions: true

- name: Higher rate band is ineligible for Marriage Allowance
period: 2021
input:
tax_band: HIGHER
output:
meets_marriage_allowance_income_conditions: false

- name: Additional rate band is ineligible for Marriage Allowance
period: 2021
input:
tax_band: ADDITIONAL
output:
meets_marriage_allowance_income_conditions: false
14 changes: 9 additions & 5 deletions openfisca_uk/variables/consumption/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class main_residential_property_purchased(Variable):
unit = "currency-GBP"

def formula(household, period):
return household("property_purchased", period) * household(
"main_residence_value", period
)
property_purchased = household("property_purchased", period)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have thought about this - while this is equivalent to before, I think assigning to variables like this to avoid the auto-formatted brackets mess makes the formulas more readable - will do this in future, thanks.

main_residence_value = household("main_residence_value", period)
return main_residence_value * property_purchased


class additional_residential_property_purchased(Variable):
Expand All @@ -57,9 +57,11 @@ class additional_residential_property_purchased(Variable):
unit = "currency-GBP"

def formula(household, period):
return household("property_purchased", period) * household(
property_purchased = household("property_purchased", period)
other_residential_property_value = household(
"other_residential_property_value", period
)
return other_residential_property_value * property_purchased


class main_residential_property_purchased_is_first_home(Variable):
Expand Down Expand Up @@ -103,9 +105,11 @@ class non_residential_property_purchased(Variable):
unit = "currency-GBP"

def formula(household, period):
return household("property_purchased", period) * household(
property_purchased = household("property_purchased", period)
non_residential_property_value = household(
"non_residential_property_value", period
)
return property_purchased * non_residential_property_value


class cumulative_non_residential_rent(Variable):
Expand Down
38 changes: 19 additions & 19 deletions openfisca_uk/variables/demographic/benunit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from openfisca_uk.variables.demographic.household import TenureType
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *


class benunit_id(Variable):
Expand Down Expand Up @@ -54,13 +53,16 @@ class family_type(Variable):
definition_period = YEAR

def formula(benunit, period, parameters):
two_adults = benunit.sum(benunit.members("is_adult", period)) == 2
has_children = benunit.sum(benunit.members("is_child", period)) > 0
is_single = not_(two_adults) * not_(has_children)
is_couple = two_adults * not_(has_children)
is_lone = not_(two_adults) * has_children
is_full = two_adults * has_children
return select([is_single, is_couple, is_lone, is_full], FamilyType)
two_adults = aggr(benunit, period, ["is_adult"]) == 2
has_children = benunit.any(benunit.members("is_child", period))
single = ~two_adults & ~has_children
couple_no_children = two_adults & ~has_children
lone_parent = ~two_adults & has_children
couple_with_children = two_adults & has_children
return select(
[single, couple_no_children, lone_parent, couple_with_children],
FamilyType,
)


class relation_type(Variable):
Expand Down Expand Up @@ -156,10 +158,9 @@ class benunit_tenure_type(Variable):
definition_period = YEAR

def formula(benunit, period, parameters):
tenure = benunit.value_from_first_person(
return benunit.value_from_first_person(
benunit.members.household("tenure_type", period)
)
return tenure


class benunit_is_renting(Variable):
Expand All @@ -170,14 +171,13 @@ class benunit_is_renting(Variable):

def formula(benunit, period, parameters):
tenure = benunit("benunit_tenure_type", period)
return np.isin(
tenure,
(
TenureType.RENT_PRIVATELY,
TenureType.RENT_FROM_COUNCIL,
TenureType.RENT_FROM_HA,
),
)
tenures = tenure.possible_values
RENT_TENURES = [
tenures.RENT_PRIVATELY,
tenures.RENT_FROM_COUNCIL,
tenures.RENT_FROM_HA,
]
return np.isin(tenure, RENT_TENURES)


class benunit_random_number(Variable):
Expand Down
62 changes: 31 additions & 31 deletions openfisca_uk/variables/demographic/household.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *


class household_id(Variable):
Expand Down Expand Up @@ -55,12 +54,15 @@ class country(Variable):
definition_period = ETERNITY

def formula(household, period, parameters):
unknown_region = household("region", period) == Region.UNKNOWN
wales = household("region", period) == Region.WALES
ni = household("region", period) == Region.NORTHERN_IRELAND
scot = household("region", period) == Region.SCOTLAND
country = select(
[unknown_region, scot, wales, ni, True],
region = household("region", period)
return select(
[
region == Region.UNKNOWN,
region == Region.SCOTLAND,
region == Region.WALES,
region == Region.NORTHERN_IRELAND,
True,
],
[
Country.UNKNOWN,
Country.SCOTLAND,
Expand All @@ -69,7 +71,6 @@ def formula(household, period, parameters):
Country.ENGLAND,
],
)
return country


class Region(Enum):
Expand Down Expand Up @@ -123,12 +124,13 @@ class is_renting(Variable):

def formula(household, period, parameters):
tenure = household("tenure_type", period)
rent_types = (
TenureType.RENT_PRIVATELY,
TenureType.RENT_FROM_COUNCIL,
TenureType.RENT_PRIVATELY,
)
return sum([tenure == rent_type for rent_type in rent_types])
tenures = tenure.possible_values
RENT_TENURES = [
tenures.RENT_PRIVATELY,
tenures.RENT_FROM_COUNCIL,
tenures.RENT_PRIVATELY,
]
return np.isin(tenure, RENT_TENURES)


class AccommodationType(Enum):
Expand Down Expand Up @@ -158,22 +160,21 @@ class household_equivalisation_bhc(Variable):
definition_period = YEAR

def formula(household, period, parameters):
other_adults = max_(
count_other_adults = max_(
household.sum(household.members("is_adult", period)) - 1, 0
)
num_young_children = household.sum(
count_young_children = household.sum(
household.members("is_young_child", period)
)
num_older_children = household.sum(
count_older_children = household.sum(
household.members("is_older_child", period)
)
weighting = (
return (
0.67
+ 0.33 * other_adults
+ 0.33 * num_older_children
+ 0.2 * num_young_children
+ 0.33 * count_other_adults
+ 0.33 * count_older_children
+ 0.2 * count_young_children
)
return weighting


class household_equivalisation_ahc(Variable):
Expand All @@ -183,22 +184,21 @@ class household_equivalisation_ahc(Variable):
definition_period = YEAR

def formula(household, period, parameters):
other_adults = max_(
count_other_adults = max_(
household.sum(household.members("is_adult", period)) - 1, 0
)
num_young_children = household.sum(
count_young_children = household.sum(
household.members("is_young_child", period)
)
num_older_children = household.sum(
count_older_children = household.sum(
household.members("is_older_child", period)
)
weighting = (
return (
0.58
+ 0.42 * other_adults
+ 0.42 * num_older_children
+ 0.2 * num_young_children
+ 0.42 * count_other_adults
+ 0.42 * count_older_children
+ 0.2 * count_young_children
)
return weighting


class household_num_people(Variable):
Expand Down
3 changes: 1 addition & 2 deletions openfisca_uk/variables/demographic/locations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *


class BRMAName(Enum):
Expand Down
21 changes: 10 additions & 11 deletions openfisca_uk/variables/demographic/person.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openfisca_uk.tools.general import *
from openfisca_uk.entities import *
from openfisca_uk.model_api import *
import pandas as pd


Expand Down Expand Up @@ -56,7 +55,10 @@ class age(Variable):
definition_period = YEAR

def formula(person, period, parameters):
return where(person.benunit.members_role == BenUnit.ADULT, 18, 10)
ADULT_DEFAULT_AGE = 18
CHILD_DEFAULT_AGE = 10
is_adult = person.benunit.members_role == BenUnit.ADULT
return where(is_adult, ADULT_DEFAULT_AGE, CHILD_DEFAULT_AGE)


class birth_year(Variable):
Expand Down Expand Up @@ -116,10 +118,7 @@ def formula(person, period, parameters):
+ 1
)
# Fill in adult values
adjusted_for_adults = where(
person("is_child", period), child_ranking, 100
)
return adjusted_for_adults
return where(person("is_child", period), child_ranking, 100)


class is_eldest_child(Variable):
Expand Down Expand Up @@ -286,8 +285,7 @@ class in_social_housing(Variable):
def formula(person, period, parameters):
tenure = person.household("tenure_type", period.this_year)
tenures = tenure.possible_values
social = is_in(tenure, tenures.RENT_FROM_COUNCIL, tenures.RENT_FROM_HA)
return social
return is_in(tenure, tenures.RENT_FROM_COUNCIL, tenures.RENT_FROM_HA)


class is_WA_adult(Variable):
Expand All @@ -297,7 +295,7 @@ class is_WA_adult(Variable):
definition_period = YEAR

def formula(person, period, parameters):
return person("is_adult", period) * not_(person("is_SP_age", period))
return person("is_adult", period) & ~person("is_SP_age", period)


class is_young_child(Variable):
Expand Down Expand Up @@ -348,4 +346,5 @@ class is_older_child(Variable):
definition_period = YEAR

def formula(person, period, parameters):
return (person("age", period) >= 14) * (person("age", period) < 18)
age = person("age", period)
return (age >= 14) & (age < 18)
Loading