diff --git a/docs/book/programs/gov/hmrc/income_tax.ipynb b/docs/book/programs/gov/hmrc/income-tax.ipynb
similarity index 88%
rename from docs/book/programs/gov/hmrc/income_tax.ipynb
rename to docs/book/programs/gov/hmrc/income-tax.ipynb
index 67bdaebee..16416afc1 100644
--- a/docs/book/programs/gov/hmrc/income_tax.ipynb
+++ b/docs/book/programs/gov/hmrc/income-tax.ipynb
@@ -22,7 +22,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"cellView": "form",
"colab": {
@@ -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": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Category | \n",
+ " Description | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " Tax Allowances | \n",
+ " Amount of income an individual can earn before... | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " Tax Charges | \n",
+ " Liabilities imposed when certain conditions or... | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " Tax Rates | \n",
+ " Percentage of income taken as tax. There are d... | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " Tax Reliefs | \n",
+ " Provisions to reduce tax liability. Examples i... | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "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",
@@ -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"
@@ -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"
]
},
{
@@ -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": {
@@ -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": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Variable Name | \n",
+ " Label | \n",
+ " Reference | \n",
+ " Unit | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " personal_allowance | \n",
+ " Personal Allowance for the year | \n",
+ " [Income Tax Act 2007 s. 35] | \n",
+ " currency-GBP | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " blind_persons_allowance | \n",
+ " Blind Person's Allowance for the year (not sim... | \n",
+ " [Income Tax Act 2007 s. 38] | \n",
+ " currency-GBP | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "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",
@@ -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"
]
},
{
@@ -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,