Skip to content

Instantly share code, notes, and snippets.

@alonsosilvaallende
Created November 28, 2022 19:26
Show Gist options
  • Save alonsosilvaallende/f6b5c4308eb53e078a7aa8263be4a58d to your computer and use it in GitHub Desktop.
Save alonsosilvaallende/f6b5c4308eb53e078a7aa8263be4a58d to your computer and use it in GitHub Desktop.
Annual_Income_Taxes.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMmLchsHybudJP+RWgNqTcG",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/alonsosilvaallende/f6b5c4308eb53e078a7aa8263be4a58d/annual_income_taxes.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"import numpy as np"
],
"metadata": {
"id": "5SKJ5I_lqSa0"
},
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "jFt5FHJAn8OH"
},
"outputs": [],
"source": [
"# Tax brackets taken from https://www.service-public.fr/particuliers/vosdroits/F1419\n",
"def impot(s):\n",
" T1 = 10225\n",
" T2 = 26070\n",
" T3 = 74545\n",
" T4 = 160336\n",
" total = 0\n",
" if s>T1 and s<=T2:\n",
" total = (s-T1)*0.11\n",
" elif s>T2 and s<=T3:\n",
" total = (T2-T1)*0.11 + (s-T2)*0.3\n",
" elif s>T3 and s<=T4:\n",
" total = (T2-T1)*0.11 + (T3-T2)*0.3 + (s-T3)*0.41\n",
" elif s>T4:\n",
" total = (T2-T1)*0.11 + (T3-T2)*0.3 + (T4-T3)*0.41 + (s-T4)*0.45\n",
" return total"
]
},
{
"cell_type": "code",
"source": [
"def impot_total(NetFiscal1, NetFiscal2, Nombre_de_parts):\n",
" # Abattement fiscal: https://www.impots.gouv.fr/particulier/questions/comment-puis-je-beneficier-de-la-deduction-forfaitaire-de-10\n",
" nf1 = np.round(NetFiscal1*.9)\n",
" nf2 = np.round(NetFiscal2*.9)\n",
" if nf1 == 0 and nf2 == 0:\n",
" return 0\n",
" else:\n",
" # Plafonnement des demi-parts: https://bofip.impots.gouv.fr/bofip/2494-PGP.html/identifiant%3DBOI-IR-LIQ-20-20-20-20220516\n",
" a = 2*impot((nf1+nf2)/2)-1592*2*(Nombre_de_parts-2)\n",
" b = Nombre_de_parts * impot((nf1+nf2)/Nombre_de_parts)\n",
" return np.round(np.max([a,b]))"
],
"metadata": {
"id": "-LEG34eJoIfK"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": [
"Nombre_de_parts = 2 #@param {type:\"slider\", min:1, max:4, step:0.5}\n",
"Net_Fiscal_1 = 50000 #@param {type:\"number\"}\n",
"Net_Fiscal_2 = 0 #@param {type:\"number\"}\n",
"if Net_Fiscal_1 is None or Net_Fiscal_2 is None or Net_Fiscal_1<0 or Net_Fiscal_2<0:\n",
" print('Provide a positive number and try again.')"
],
"metadata": {
"id": "IR9UEnqepH6n"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(\"Taxes :\", impot_total(Net_Fiscal_1, Net_Fiscal_2, Nombre_de_parts))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JchRMr0Bp-3F",
"outputId": "8932ce18-e8b5-419b-904f-45c5f5e40872"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Taxes : 2700.0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"print(\"Annual income taxes for 1 single:\", impot_total(Net_Fiscal_1,0,1))\n",
"print(\"Annual income taxes for 2 single:\", impot_total(0,Net_Fiscal_2,1))\n",
"print(\"Annual income taxes for 1 and 2 married:\", impot_total(Net_Fiscal_1,Net_Fiscal_2,2))\n",
"print(\"Annual income taxes for 1 and 2 married with 1 children:\", impot_total(Net_Fiscal_1,Net_Fiscal_2,2.5))\n",
"print(\"Annual income taxes for 1 and 2 married with 2 children:\", impot_total(Net_Fiscal_1,Net_Fiscal_2,3))\n",
"print(\"Annual income taxes for 1 and 2 married with 3 children:\", impot_total(Net_Fiscal_1,Net_Fiscal_2,4))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tujf522uqc1I",
"outputId": "98f8ce52-ac26-4b5b-b393-5139b7e88334"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Annual income taxes for 1 single: 7422.0\n",
"Annual income taxes for 2 single: 0\n",
"Annual income taxes for 1 and 2 married: 2700.0\n",
"Annual income taxes for 1 and 2 married with 1 children: 2138.0\n",
"Annual income taxes for 1 and 2 married with 2 children: 1576.0\n",
"Annual income taxes for 1 and 2 married with 3 children: 451.0\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment