API Reference
This section provides a complete API reference for the nztaxmicrosim
package, automatically generated from the source code docstrings.
Core Simulation
Simulation Pipeline
src.pipeline
Simple plug-in pipeline for orchestrating tax and benefit rules.
SimulationPipeline
dataclass
A pipeline for running a series of simulation rules.
The pipeline stores a list of rules and executes them sequentially on a given data dictionary. Rules can be enabled, disabled, or replaced.
Source code in src/pipeline.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
disable(name)
Disable a rule in the pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the rule to disable. |
required |
Source code in src/pipeline.py
112 113 114 115 116 117 118 119 |
|
enable(name)
Enable a rule in the pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the rule to enable. |
required |
Source code in src/pipeline.py
103 104 105 106 107 108 109 110 |
|
from_config(config_path)
classmethod
Create a SimulationPipeline from a YAML configuration file.
The configuration file should specify a list of rules to be included
in the pipeline. This method uses the RULE_REGISTRY to find and
instantiate the rules. The rules are instantiated without parameters;
they are expected to receive them from the data
dictionary during
the run
phase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
str
|
The path to the YAML configuration file. |
required |
Returns:
Type | Description |
---|---|
'SimulationPipeline'
|
A new |
Source code in src/pipeline.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
replace(name, new_rule)
Replace a rule in the pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the rule to replace. |
required |
new_rule
|
Rule
|
The new rule to insert into the pipeline. |
required |
Source code in src/pipeline.py
121 122 123 124 125 126 127 128 129 |
|
run(data=None)
Run all enabled rules in the pipeline sequentially.
Each rule is called with the data
dictionary, which it can modify
in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, Any] | None
|
The data dictionary to be processed by the rules. It is expected to contain a 'df' key with a pandas DataFrame. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The modified data dictionary. |
Source code in src/pipeline.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
Main Simulation Logic
src.microsim
calctax(taxy, split, params1, params2)
Calculate income tax for a year with a mid-year policy change (split year).
This is used when tax rules change during a financial year. It calculates
the tax for the full year under the old rules (params1
) and the new rules
(params2
), then prorates the results based on the split
month.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxy
|
float
|
The total taxable income for the year. |
required |
split
|
int
|
The month number (1-12) in which the tax change occurs. The new rules apply from this month onwards. |
required |
params1
|
TaxBracketParams
|
The tax bracket parameters for the first part of the year. |
required |
params2
|
TaxBracketParams
|
The tax bracket parameters for the second part of the year. |
required |
Returns:
Type | Description |
---|---|
float
|
The total income tax for the split year. |
Source code in src/microsim.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
calculate_net_weekly_income(gross_weekly_income, acc_earners_premium_rate, tax_params)
Calculate the net average weekly income after tax and ACC levy.
This function annualizes the weekly income, calculates the annual income tax, deducts the ACC Earner's Premium, and then converts the result back to a weekly net income.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gross_weekly_income
|
float
|
The gross weekly income. |
required |
acc_earners_premium_rate
|
float
|
The ACC Earner's Premium rate. |
required |
tax_params
|
TaxBracketParams
|
The tax bracket parameters. |
required |
Returns:
Type | Description |
---|---|
float
|
The net average weekly income, rounded to two decimal places. |
Source code in src/microsim.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
load_parameters(year)
Load policy parameters for year
from the SQLite database.
This function connects to the parameters database, queries for all policy parameters for the given year, reconstructs the parameter dictionary, and validates it using the Pydantic model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year
|
str
|
The start year for which to load the parameters (e.g., |
required |
Returns:
Name | Type | Description |
---|---|---|
Parameters |
Parameters
|
A Pydantic model containing all parameter groups for the year. |
Source code in src/microsim.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
simrwt(interest, rwt_rate)
Calculates the Resident Withholding Tax (RWT).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interest
|
float
|
The interest income. |
required |
rwt_rate
|
float
|
The RWT rate to apply. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The calculated RWT. |
Source code in src/microsim.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
supstd(cpi_factors, average_weekly_earnings, earner_premium_rates, super_floor_relativities, tax_parameters, base_year_average_weekly_earnings, base_year_earner_premium_rate, base_year_tax_parameters)
Calculates standard superannuation rates for a base year and 4 simulation years.
This function projects superannuation payments, ensuring they are indexed to the higher of CPI inflation or a "floor" relative to the average weekly earnings. It calculates both gross and net superannuation amounts.
This function replicates the logic of the SAS macro %supstd
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cpi_factors
|
list[float]
|
A list of 4 CPI factors for the simulation years. |
required |
average_weekly_earnings
|
list[float]
|
A list of 4 average weekly earnings for the simulation years. |
required |
earner_premium_rates
|
list[float]
|
A list of 4 ACC earner premium rates for the simulation years. |
required |
super_floor_relativities
|
list[float]
|
A list of 4 superannuation accord floor relativities for the simulation years. |
required |
tax_parameters
|
list[TaxBracketParams]
|
A list of 4 tax parameter sets for the simulation years. |
required |
base_year_average_weekly_earnings
|
float
|
The average weekly earnings for the base year. |
required |
base_year_earner_premium_rate
|
float
|
The ACC earner premium rate for the base year. |
required |
base_year_tax_parameters
|
TaxBracketParams
|
Tax parameters for the base year. |
required |
Returns:
Type | Description |
---|---|
dict[str, float]
|
A dictionary containing the calculated gross and net standard |
dict[str, float]
|
superannuation amounts for the base year and 4 simulation years. |
Source code in src/microsim.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
taxit(taxy, params)
Calculate income tax using a progressive tax bracket system.
This function iterates through the tax brackets defined in params
. For each
bracket, it calculates the tax owed on the portion of income that falls
within that bracket's range. The total tax is the sum of the tax from
each bracket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxy
|
float
|
The taxable income. |
required |
params
|
Mapping[str, Any] | TaxBracketParams
|
A |
required |
Returns:
Type | Description |
---|---|
float
|
The total calculated income tax. |
Source code in src/microsim.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
Tax & Levy Calculations
Main Tax Calculator
src.tax_calculator
TaxCalculator
Bases: BaseModel
Convenience wrapper around core tax calculations.
The class stores a set of policy parameters and exposes small helper
methods which delegate to the functions defined in :mod:microsim
.
Source code in src/tax_calculator.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
calculate_emtr(individual_data)
Calculates the Effective Marginal Tax Rate (EMTR) for an individual.
The EMTR is the proportion of an additional dollar of earnings that is lost to taxes and reduced benefits. It is calculated by simulating the individual's net income with and without a small increase in income.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
individual_data
|
dict
|
A dictionary representing a single person, containing all necessary fields for tax and benefit calculations (e.g., 'income', 'age', etc.). |
required |
Returns:
Type | Description |
---|---|
float
|
The Effective Marginal Tax Rate as a float (e.g., 0.3 for 30%). |
Source code in src/tax_calculator.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
donation_credit(total_donations, taxable_income)
Calculates the tax credit for charitable donations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total_donations
|
float
|
The total amount of donations made in the year. |
required |
taxable_income
|
float
|
The individual's total taxable income for the year. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated donation tax credit. Returns 0 if donation credit |
float
|
parameters are not available for the year. |
Source code in src/tax_calculator.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
eitc(is_credit_enabled, is_eligible, income, min_income_threshold, max_entitlement_income, abatement_income_threshold, earning_rate, abatement_rate)
Calculates the Earned Income Tax Credit (EITC).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_credit_enabled
|
bool
|
Flag to enable or disable the credit calculation. |
required |
is_eligible
|
bool
|
Flag indicating if the individual is eligible for the credit. |
required |
income
|
float
|
The income amount to base the calculation on. |
required |
min_income_threshold
|
float
|
The income level at which the credit begins. |
required |
max_entitlement_income
|
float
|
The income level where the credit reaches its maximum. |
required |
abatement_income_threshold
|
float
|
The income level at which the credit begins to abate. |
required |
earning_rate
|
float
|
The rate at which the credit is earned during phase-in. |
required |
abatement_rate
|
float
|
The rate at which the credit is reduced during phase-out. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated EITC amount. |
Source code in src/tax_calculator.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
family_boost_credit(family_income, childcare_costs)
Calculates the FamilyBoost childcare tax credit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total family income. |
required |
childcare_costs
|
float
|
The total childcare costs for the period. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated FamilyBoost credit amount. |
Source code in src/tax_calculator.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
from_year(year)
classmethod
Construct a :class:TaxCalculator
from stored parameter files.
This method loads the parameters for a given tax year from the
corresponding JSON file (e.g., parameters_2023-2024.json
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year
|
str
|
The tax year to load parameters for (e.g., "2023-2024"). |
required |
Returns:
Type | Description |
---|---|
'TaxCalculator'
|
A new |
Source code in src/tax_calculator.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
ietc(taxable_income, is_wff_recipient, is_super_recipient, is_benefit_recipient)
Calculate the Independent Earner Tax Credit (IETC).
The IETC is a tax credit for individuals who are not receiving certain other benefits, such as Working for Families or NZ Super.
The calculation is performed by the calcietc
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxable_income
|
float
|
The individual's taxable income. |
required |
is_wff_recipient
|
bool
|
Whether the individual is a recipient of Working for Families tax credits. |
required |
is_super_recipient
|
bool
|
Whether the individual is a recipient of NZ Superannuation. |
required |
is_benefit_recipient
|
bool
|
Whether the individual is a recipient of a main benefit. |
required |
Returns:
Type | Description |
---|---|
float
|
The amount of IETC the individual is entitled to. |
Source code in src/tax_calculator.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
income_tax(taxable_income)
Calculate income tax for a given taxable income.
This method uses a progressive tax system with multiple tax brackets.
The tax rates and thresholds for these brackets are drawn from
params.tax_brackets
.
The calculation is performed by the taxit
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxable_income
|
float
|
The amount of income to calculate tax on. |
required |
Returns:
Type | Description |
---|---|
float
|
The amount of income tax payable. |
Source code in src/tax_calculator.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
pie_tax(pie_income, taxable_income)
Calculates tax on Portfolio Investment Entity (PIE) income.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pie_income
|
float
|
The income from the PIE investment. |
required |
taxable_income
|
float
|
The individual's total taxable income for the year, used to determine the Prescribed Investor Rate (PIR). |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated tax on the PIE income. Returns 0 if PIE parameters |
float
|
are not available for the year. |
Source code in src/tax_calculator.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
rwt(interest, taxable_income)
Calculate Resident Withholding Tax (RWT) on interest income.
RWT is a tax on interest earned from sources like bank accounts and investments. The tax rate depends on the individual's income tax bracket. This method determines the correct RWT rate based on the provided taxable income and then calculates the RWT amount.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interest
|
float
|
The amount of interest income subject to RWT. |
required |
taxable_income
|
float
|
The individual's total taxable income, used to determine the RWT rate. |
required |
Returns:
Type | Description |
---|---|
float
|
The amount of RWT payable. |
Source code in src/tax_calculator.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
Tax Credits
src.tax_credits
calcietc(taxable_income, is_wff_recipient, is_super_recipient, is_benefit_recipient, ietc_params)
Calculates the Independent Earner Tax Credit (IETC).
This function determines the IETC entitlement based on taxable income and
eligibility criteria. It replicates the logic of the SAS macro %calcietc
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxable_income
|
float
|
The individual's taxable income. |
required |
is_wff_recipient
|
bool
|
True if the individual receives Working for Families tax credits. |
required |
is_super_recipient
|
bool
|
True if the individual receives superannuation payments. |
required |
is_benefit_recipient
|
bool
|
True if the individual receives a main benefit. |
required |
ietc_params
|
Mapping[str, Any] | IETCParams
|
Structured IETC parameters. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The calculated IETC amount. |
Source code in src/tax_credits.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
calculate_donation_credit(total_donations, taxable_income, params)
Calculates the tax credit for charitable donations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total_donations
|
float
|
The total amount of donations made in the year. |
required |
taxable_income
|
float
|
The individual's total taxable income for the year. |
required |
params
|
DonationCreditParams
|
The parameters for the donation tax credit. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated donation tax credit. |
Source code in src/tax_credits.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
eitc(is_credit_enabled, is_eligible, income, min_income_threshold, max_entitlement_income, abatement_income_threshold, earning_rate, abatement_rate)
Calculates the Earned Income Tax Credit (EITC).
The EITC calculation has three phases based on income:
1. Phase-in: For income between min_income_threshold
and
max_entitlement_income
, the credit increases at the earning_rate
.
2. Plateau: For income between max_entitlement_income
and
abatement_income_threshold
, the credit is at its maximum.
3. Phase-out: For income above abatement_income_threshold
, the
credit is reduced at the abatement_rate
.
This function replicates the logic of the SAS macro %eitc
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_credit_enabled
|
bool
|
Flag to enable or disable the credit calculation. |
required |
is_eligible
|
bool
|
Flag indicating if the individual is eligible for the credit. |
required |
income
|
float
|
The income amount to base the calculation on. |
required |
min_income_threshold
|
float
|
The income level at which the credit begins. |
required |
max_entitlement_income
|
float
|
The income level where the credit reaches its maximum. |
required |
abatement_income_threshold
|
float
|
The income level at which the credit begins to abate. |
required |
earning_rate
|
float
|
The rate at which the credit is earned during phase-in. |
required |
abatement_rate
|
float
|
The rate at which the credit is reduced during phase-out. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated EITC amount. |
Source code in src/tax_credits.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
family_boost_credit(family_income, childcare_costs, family_boost_params)
Calculates the FamilyBoost childcare tax credit.
The credit is calculated as 25% of childcare costs, up to a maximum credit amount. The credit is then abated for families with income above a certain threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total family income. |
required |
childcare_costs
|
float
|
The total childcare costs for the period. |
required |
family_boost_params
|
FamilyBoostParams
|
The parameters for the FamilyBoost credit, including max credit, income thresholds, and abatement rate. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated FamilyBoost credit amount. |
Source code in src/tax_credits.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
ACC Levy
src.acc_levy
ACC earner's levy calculations.
calculate_acc_levy(income, levy_rate, max_income)
Calculate the ACC (Accident Compensation Corporation) earner's levy.
The ACC earner's levy is a compulsory payment that helps fund the cost of accidents in New Zealand. It is calculated as a flat rate on income up to a specified maximum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
income
|
float
|
The annual earnings subject to the levy. |
required |
levy_rate
|
float
|
The ACC levy rate, expressed as a decimal (e.g., 1.46% is 0.0146). |
required |
max_income
|
float
|
The maximum income on which the levy is charged. |
required |
Returns:
Type | Description |
---|---|
float
|
The total ACC levy owed for the year. |
Source code in src/acc_levy.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
calculate_payroll_deductions(income, tax_params, levy_rate, levy_max_income)
Calculate total payroll deductions, including income tax and ACC levy.
This function provides a combined calculation of the two main deductions from an individual's income: income tax and the ACC earner's levy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
income
|
float
|
The annual income. |
required |
tax_params
|
'TaxBracketParams'
|
The tax bracket parameters for the income tax calculation. |
required |
levy_rate
|
float
|
The ACC levy rate. |
required |
levy_max_income
|
float
|
The maximum income for the ACC levy. |
required |
Returns:
Type | Description |
---|---|
float
|
The total amount of payroll deductions. |
Source code in src/acc_levy.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
Investment Income Tax (PIE)
src.investment_tax
calculate_pie_tax(pie_income, taxable_income, pie_params)
Calculates tax on Portfolio Investment Entity (PIE) income.
This function determines the Prescribed Investor Rate (PIR) based on the individual's taxable income and then calculates the tax on the PIE income.
.. warning:: The current implementation uses a simplified logic based on a single year's income to determine the PIR. The official IRD rules require looking at income from the two preceding years. This implementation should be updated when the definitive two-year lookback logic is clarified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pie_income
|
float
|
The income from the PIE investment. |
required |
taxable_income
|
float
|
The individual's total taxable income for the year. |
required |
pie_params
|
PIEParams
|
The parameters for PIE tax, including rates and thresholds. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated tax on the PIE income. |
Source code in src/investment_tax.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Payroll Deductions (KiwiSaver, Student Loans)
src.payroll_deductions
Helper functions for payroll deductions.
calculate_kiwisaver_contribution(income, rate)
Calculate the employee's KiwiSaver contribution.
KiwiSaver is a voluntary savings scheme to help New Zealanders save for their retirement. This function calculates the employee's contribution based on their income and a specified contribution rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
income
|
float
|
The annual income subject to KiwiSaver contributions. |
required |
rate
|
float
|
The contribution rate, expressed as a decimal (e.g., 0.03 for 3%). |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated KiwiSaver contribution. Returns 0.0 for negative or |
float
|
zero income or rate. |
Source code in src/payroll_deductions.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
calculate_student_loan_repayment(income, repayment_threshold, repayment_rate)
Calculate the mandatory student loan repayment for a given income.
This function calculates the amount of student loan repayment required based on an individual's income. Repayments are only required if the income is above a certain threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
income
|
float
|
The annual taxable income. |
required |
repayment_threshold
|
float
|
The income threshold above which repayments apply. |
required |
repayment_rate
|
float
|
The rate applied to income above the threshold, expressed as a decimal. |
required |
Returns:
Type | Description |
---|---|
float
|
The calculated student loan repayment amount. |
Source code in src/payroll_deductions.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Benefit Calculations
Benefit Rule Classes
src.benefit_rules
AccommodationSupplementRule
dataclass
Bases: Rule
A rule to calculate the Accommodation Supplement.
The Accommodation Supplement is a weekly payment that helps people with their rent, board, or mortgage payments.
This rule calculates the Accommodation Supplement entitlement based on household income, housing costs, region, and number of dependent children.
The calculation is performed by the calculate_accommodation_supplement
function.
Source code in src/benefit_rules.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
__call__(data)
Calculate Accommodation Supplement entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
BSTCRule
dataclass
Bases: Rule
A rule to calculate the Best Start Tax Credit (BSTC).
The BSTC is a payment for families with a new baby. It is designed to help with the costs of raising a child in their first few years.
This rule calculates the BSTC entitlement based on family income and the age of the youngest child.
The calculation is performed by the calculate_bstc
function.
Source code in src/benefit_rules.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
__call__(data)
Calculate BSTC entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
DisabilityAllowanceRule
dataclass
Bases: Rule
A rule to calculate the Disability Allowance.
The Disability Allowance is a weekly payment for people who have regular, ongoing costs because of a disability.
This rule calculates the Disability Allowance entitlement based on income, disability-related costs, and family situation.
The calculation is performed by the calculate_disability_allowance
function.
Source code in src/benefit_rules.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
__call__(data)
Calculate Disability Allowance entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
FTCRule
dataclass
Bases: Rule
A rule to calculate the Family Tax Credit (FTC).
The FTC is a payment for families with dependent children. It is designed to help with the costs of raising a family.
This rule calculates the FTC entitlement based on family income and the number of children.
The calculation is performed by the calculate_ftc
function.
Source code in src/benefit_rules.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
__call__(data)
Calculate FTC entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
IWTCRule
dataclass
Bases: Rule
A rule to calculate the In-Work Tax Credit (IWTC).
The IWTC is a payment for working families with dependent children. It is designed to help make work pay for low to middle-income families.
This rule calculates the IWTC entitlement based on family income, number of children, and hours worked.
The calculation is performed by the calculate_iwtc
function.
Source code in src/benefit_rules.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
__call__(data)
Calculate IWTC entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
JSSRule
dataclass
Bases: Rule
A rule to calculate Jobseeker Support (JSS).
JSS is a weekly payment for people who are not in full-time employment, are available for and looking for work, or are unable to work due to a health condition, injury, or disability.
This rule calculates the JSS entitlement based on an individual's income, marital status, and number of dependent children.
The calculation is performed by the calculate_jss
function.
Source code in src/benefit_rules.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
__call__(data)
Calculate JSS entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
MFTCRule
dataclass
Bases: Rule
A rule to calculate the Minimum Family Tax Credit (MFTC).
The MFTC is a payment for working families who would otherwise be better off on a benefit. It tops up their after-tax income to a guaranteed minimum amount.
This rule calculates the MFTC entitlement based on family income and tax paid.
The calculation is performed by the calculate_mftc
function.
Source code in src/benefit_rules.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
__call__(data)
Calculate MFTC entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
SLPRule
dataclass
Bases: Rule
A rule to calculate Supported Living Payment (SLP).
SLP is a weekly payment for people who have, or are caring for someone with, a significant health condition, injury, or disability.
This rule calculates the SLP entitlement based on an individual's income, marital status, and disability status.
The calculation is performed by the calculate_slp
function.
Source code in src/benefit_rules.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
__call__(data)
Calculate SLP entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
SPSRule
dataclass
Bases: Rule
A rule to calculate Sole Parent Support (SPS).
SPS is a weekly payment for single parents with dependent children.
This rule calculates the SPS entitlement based on an individual's income and the number of dependent children.
The calculation is performed by the calculate_sps
function.
Source code in src/benefit_rules.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
__call__(data)
Calculate SPS entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
WEPRule
dataclass
Bases: Rule
A rule to calculate the Winter Energy Payment (WEP).
The WEP is a payment to help with the cost of heating during the winter months. It is available to people receiving certain benefits or superannuation.
This rule calculates the WEP entitlement based on eligibility, marital status, and number of dependent children.
The calculation is performed by the calculate_wep
function.
Source code in src/benefit_rules.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
__call__(data)
Calculate WEP entitlement and add it to the DataFrame.
Source code in src/benefit_rules.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
Benefit Calculation Functions
src.benefits
calculate_accommodation_supplement(household_income, housing_costs, region, num_dependent_children, as_params)
Calculate the Accommodation Supplement entitlement.
The Accommodation Supplement is a weekly payment that helps people with their rent, board, or mortgage payments. The entitlement is based on household income, housing costs, region, and the number of dependent children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
household_income
|
float
|
The total weekly income of the household. |
required |
housing_costs
|
float
|
The weekly housing costs. |
required |
region
|
str
|
The region where the household is located. |
required |
num_dependent_children
|
int
|
The number of dependent children in the household. |
required |
as_params
|
AccommodationSupplementParams
|
The parameters for the Accommodation Supplement. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly Accommodation Supplement entitlement. |
Source code in src/benefits.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
calculate_bstc(family_income, child_age, bstc_params)
Calculate the Best Start Tax Credit (BSTC) entitlement.
The BSTC is a payment for families with a new baby. It is designed to help with the costs of raising a child in their first few years. The entitlement is based on family income and the age of the youngest child.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total annual family income. |
required |
child_age
|
int
|
The age of the youngest child in years. |
required |
bstc_params
|
BSTCParams
|
The parameters for the BSTC. |
required |
Returns:
Type | Description |
---|---|
float
|
The annual BSTC entitlement. |
Source code in src/benefits.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
calculate_child_support(liable_income, cs_params)
Calculate child support payments based on liable income.
.. warning:: This is a simplified implementation and does not reflect the full complexity of the official formula, which includes the other parent's income, care arrangements, and other factors.
Child support is a payment made by a parent who does not live with their child to the parent or caregiver who does. This function calculates the amount of child support payable based on the liable parent's income.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
liable_income
|
float
|
The liable parent's annual income. |
required |
cs_params
|
ChildSupportParams
|
The parameters for child support. |
required |
Returns:
Type | Description |
---|---|
float
|
The amount of child support payable. |
Source code in src/benefits.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
calculate_disability_allowance(weekly_income, disability_costs, family_situation, params)
Calculate the Disability Allowance entitlement.
The Disability Allowance is a weekly payment for people who have regular, ongoing costs because of a disability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weekly_income
|
float
|
The individual's or couple's weekly income before tax. |
required |
disability_costs
|
float
|
The weekly costs due to disability. |
required |
family_situation
|
str
|
The family situation of the person, which determines the income threshold. |
required |
params
|
DisabilityAllowanceParams
|
The parameters for the Disability Allowance. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly Disability Allowance entitlement. |
Source code in src/benefits.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
calculate_ftc(family_income, num_children, ftc_params)
Calculate the Family Tax Credit (FTC) entitlement.
The FTC is a payment for families with dependent children. It is designed to help with the costs of raising a family. The entitlement is based on family income and the number of children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total annual family income. |
required |
num_children
|
int
|
The number of dependent children. |
required |
ftc_params
|
FTCParams
|
The parameters for the FTC. |
required |
Returns:
Type | Description |
---|---|
float
|
The annual FTC entitlement. |
Source code in src/benefits.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
calculate_iwtc(family_income, num_children, hours_worked, iwtc_params)
Calculate the In-Work Tax Credit (IWTC) entitlement.
The IWTC is a payment for working families with dependent children. It is designed to help make work pay for low to middle-income families. The entitlement is based on family income, the number of children, and the hours worked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total annual family income. |
required |
num_children
|
int
|
The number of dependent children. |
required |
hours_worked
|
int
|
The number of hours worked per week. |
required |
iwtc_params
|
IWTCParams
|
The parameters for the IWTC. |
required |
Returns:
Type | Description |
---|---|
float
|
The annual IWTC entitlement. |
Source code in src/benefits.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
calculate_jss(individual_income, is_single, is_partnered, num_dependent_children, jss_params)
Calculate the Jobseeker Support (JSS) entitlement.
JSS is a weekly payment for people who are not in full-time employment. The entitlement is based on the individual's income, marital status, and the number of dependent children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
individual_income
|
float
|
The individual's weekly income. |
required |
is_single
|
bool
|
Whether the individual is single. |
required |
is_partnered
|
bool
|
Whether the individual is partnered. |
required |
num_dependent_children
|
int
|
The number of dependent children. |
required |
jss_params
|
JSSParams
|
The parameters for JSS. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly JSS entitlement. |
Source code in src/benefits.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
calculate_mftc(family_income, tax_paid, mftc_params)
Calculate the Minimum Family Tax Credit (MFTC) entitlement.
The MFTC is a payment for working families who would otherwise be better off on a benefit. It tops up their after-tax income to a guaranteed minimum amount.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family_income
|
float
|
The total annual family income. |
required |
tax_paid
|
float
|
The amount of tax paid by the family. |
required |
mftc_params
|
MFTCParams
|
The parameters for the MFTC. |
required |
Returns:
Type | Description |
---|---|
float
|
The annual MFTC entitlement. |
Source code in src/benefits.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
calculate_ppl(weeks_taken, ppl_params)
Calculate Paid Parental Leave (PPL) payments.
PPL is a payment for eligible parents to help them take time off work to care for a new baby or a child under six who has come into their care.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weeks_taken
|
int
|
The number of weeks of PPL taken. |
required |
ppl_params
|
PPLParams
|
The parameters for PPL. |
required |
Returns:
Type | Description |
---|---|
float
|
The total PPL payment. |
Source code in src/benefits.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
calculate_slp(individual_income, is_single, is_partnered, is_disabled, slp_params)
Calculate the Supported Living Payment (SLP) entitlement.
SLP is a weekly payment for people who have, or are caring for someone with, a significant health condition, injury, or disability. The entitlement is based on the individual's income, marital status, and disability status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
individual_income
|
float
|
The individual's weekly income. |
required |
is_single
|
bool
|
Whether the individual is single. |
required |
is_partnered
|
bool
|
Whether the individual is partnered. |
required |
is_disabled
|
bool
|
Whether the individual has a disability. |
required |
slp_params
|
SLPParams
|
The parameters for SLP. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly SLP entitlement. |
Source code in src/benefits.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
calculate_sps(individual_income, num_dependent_children, sps_params)
Calculate the Sole Parent Support (SPS) entitlement.
SPS is a weekly payment for single parents with dependent children. The entitlement is based on the individual's income and the number of dependent children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
individual_income
|
float
|
The individual's weekly income. |
required |
num_dependent_children
|
int
|
The number of dependent children. |
required |
sps_params
|
SPSParams
|
The parameters for SPS. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly SPS entitlement. |
Source code in src/benefits.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
calculate_wep(is_eligible, is_single, is_partnered, num_dependent_children, wep_params)
Calculate the Winter Energy Payment (WEP) entitlement.
The WEP is a payment to help with the cost of heating during the winter months. It is available to people receiving certain benefits or superannuation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_eligible
|
bool
|
Whether the individual is eligible for the WEP. |
required |
is_single
|
bool
|
Whether the individual is single. |
required |
is_partnered
|
bool
|
Whether the individual is partnered. |
required |
num_dependent_children
|
int
|
The number of dependent children. |
required |
wep_params
|
WEPParams
|
The parameters for the WEP. |
required |
Returns:
Type | Description |
---|---|
float
|
The weekly WEP entitlement. |
Source code in src/benefits.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|