Skip to content

Commit

Permalink
Add Nikhil's comments and edits
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Sep 21, 2023
1 parent d10c94e commit ab1ba13
Showing 1 changed file with 194 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"cellView": "form",
"colab": {
Expand All @@ -33,26 +33,71 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| Category | Description |\n",
"+================+=================================================================================================================================================================================================+\n",
"| Tax Allowances | Amount of income an individual can earn before they start paying tax. Examples include Personal Allowance, Marriage Allowance, Blind Person’s Allowance, and Dividend Allowance. |\n",
"+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| Tax Charges | Liabilities imposed when certain conditions or thresholds are met. For example, charges apply when income exceeds the personal allowance or in cases like the High-Income Child Benefit Charge. |\n",
"+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| Tax Rates | Percentage of income taken as tax. There are different rates like Basic, Higher, and Additional rates. Dividends have their own rates. |\n",
"+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| Tax Reliefs | Provisions to reduce tax liability. Examples include reliefs for Pension Contributions, Charitable Donations, and Work-Related Expenses. |\n",
"+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"
]
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Category</th>\n",
" <th>Description</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Tax Allowances</td>\n",
" <td>Amount of income an individual can earn before...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Tax Charges</td>\n",
" <td>Liabilities imposed when certain conditions or...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Tax Rates</td>\n",
" <td>Percentage of income taken as tax. There are d...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Tax Reliefs</td>\n",
" <td>Provisions to reduce tax liability. Examples i...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Category Description\n",
"0 Tax Allowances Amount of income an individual can earn before...\n",
"1 Tax Charges Liabilities imposed when certain conditions or...\n",
"2 Tax Rates Percentage of income taken as tax. There are d...\n",
"3 Tax Reliefs Provisions to reduce tax liability. Examples i..."
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# @title\n",
"from tabulate import tabulate\n",
"import pandas as pd\n",
"\n",
"headers = [\"Category\", \"Description\"]\n",
"data = [\n",
Expand All @@ -62,13 +107,17 @@
" [\"Tax Reliefs\", \"Provisions to reduce tax liability. Examples include reliefs for Pension Contributions, Charitable Donations, and Work-Related Expenses.\"]\n",
"]\n",
"\n",
"print(tabulate(data, headers=headers, tablefmt=\"grid\"))\n"
"df = pd.DataFrame(data, columns=headers)\n",
"df\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ER87IhZtVPL6"
"id": "ER87IhZtVPL6",
"tags": [
"hide-input"
]
},
"source": [
"# Legislation"
Expand Down Expand Up @@ -141,8 +190,8 @@
"id": "VaL6XOutgEU4"
},
"source": [
"# Methodology:\n",
" Income tax logic can be found in policyengine-uk/policyengine_uk/variables/gov/hmrc/income_tax."
"## Methodology\n",
"\n"
]
},
{
Expand All @@ -157,7 +206,41 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" earned_income_tax<2022, (default)> = [19432.]\n",
" pays_scottish_income_tax<2022, (default)> = [0.]\n",
" earned_taxable_income<2022, (default)> = [67430.]\n",
" earned_taxable_income<2022, (default)> = [67430.]\n"
]
}
],
"source": [
"from policyengine_uk import Simulation\n",
"\n",
"simulation = Simulation(\n",
" situation={\n",
" \"people\": {\n",
" \"person\": {\n",
" \"employment_income\": 80_000,\n",
" \"dividend_income\": 20_000,\n",
" }\n",
" }\n",
" }\n",
")\n",
"simulation.trace = True\n",
"simulation.calculate(\"earned_income_tax\")\n",
"simulation.tracer.print_computation_log(max_depth=2)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"cellView": "form",
"colab": {
Expand All @@ -168,39 +251,90 @@
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| Variable Name | Label | Reference | Unit |\n",
"+============================================+=======================================================+===============================================================+========+\n",
"| personal_allowance | Personal Allowance for the year | Income Tax Act 2007 s. 35 | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| blind_persons_allowance | Blind Person's Allowance for the year (not simulated) | Income Tax Act 2007 s. 38 | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| trading_allowance | Trading Allowance for the year | Income Tax (Trading and Other Income) Act 2005 s. 783AF | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| trading_allowance_deduction | Deduction applied by the trading allowance | Income Tax (Trading and Other Income) Act 2005 s. 783AF | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| property_allowance | Property Allowance for the year | Income Tax (Trading and Other Income) Act 2005 s. 783BF | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| savings_allowance | Savings Allowance for the year | Income Tax Act 2007 s. 12B | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| dividend_allowance | Dividend allowance for the person | Income Tax Act 2007 s. 13A | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| meets_marriage_allowance_income_conditions | Meets Marriage Allowance income conditions | https://www.legislation.gov.uk/ukpga/2007/3/section/55B | |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n",
"| marriage_allowance | Marriage Allowance | https://www.legislation.gov.uk/ukpga/2007/3/part/3/chapter/3A | GBP |\n",
"+--------------------------------------------+-------------------------------------------------------+---------------------------------------------------------------+--------+\n"
]
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Variable Name</th>\n",
" <th>Label</th>\n",
" <th>Reference</th>\n",
" <th>Unit</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>personal_allowance</td>\n",
" <td>Personal Allowance for the year</td>\n",
" <td>[Income Tax Act 2007 s. 35]</td>\n",
" <td>currency-GBP</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>blind_persons_allowance</td>\n",
" <td>Blind Person's Allowance for the year (not sim...</td>\n",
" <td>[Income Tax Act 2007 s. 38]</td>\n",
" <td>currency-GBP</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Variable Name Label \\\n",
"0 personal_allowance Personal Allowance for the year \n",
"1 blind_persons_allowance Blind Person's Allowance for the year (not sim... \n",
"\n",
" Reference Unit \n",
"0 [Income Tax Act 2007 s. 35] currency-GBP \n",
"1 [Income Tax Act 2007 s. 38] currency-GBP "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# @title\n",
"from tabulate import tabulate\n",
"from policyengine_uk.system import system\n",
"\n",
"VARIABLES = [ \n",
" \"personal_allowance\",\n",
" \"blind_persons_allowance\",\n",
"]\n",
"\n",
"variable_data = [system.variables[variable] for variable in VARIABLES]\n",
"\n",
"variables = [\n",
" {\n",
" \"name\": variable.name,\n",
" \"label\": variable.label,\n",
" \"reference\": variable.reference,\n",
" \"unit\": variable.unit\n",
" }\n",
" for variable in variable_data\n",
"]\n",
"\"\"\"\n",
"variables = [\n",
" {\n",
" \"name\": \"personal_allowance\",\n",
" \"label\": \"Personal Allowance for the year\",\n",
" \"reference\": \"Income Tax Act 2007 s. 35\",\n",
Expand Down Expand Up @@ -254,13 +388,14 @@
" \"reference\": \"https://www.legislation.gov.uk/ukpga/2007/3/part/3/chapter/3A\",\n",
" \"unit\": \"GBP\"\n",
" },\n",
"]\n",
"]\"\"\"\n",
"\n",
"headers = [\"Variable Name\", \"Label\", \"Reference\", \"Unit\"]\n",
"table_data = [(v[\"name\"], v[\"label\"], v[\"reference\"], v[\"unit\"]) for v in variables]\n",
"table = tabulate(table_data, headers=headers, tablefmt='grid')\n",
"import pandas as pd\n",
"\n",
"print(table)\n"
"table = pd.DataFrame(table_data, columns=headers)\n",
"table\n"
]
},
{
Expand Down Expand Up @@ -1050,8 +1185,16 @@
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.9.7"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ab1ba13

Please sign in to comment.