{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Evolution du taux effectif en fonction du salaire et du capital\n", "\n", "Derni\u00e8re version du notebook : https://github.com/fmassot/openfisca-web-notebook/" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Libs \u00e0 importer\n", "%matplotlib inline\n", "import collections\n", "import json\n", "import requests\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from scipy import interpolate" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 344 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Simulation avec OpenFisca\n", "\n", "API : http://api.openfisca.fr/api/1/simulate\n", "\n", "\n", "On calcule avec OpenFisca les revenus et de cotisations pour une personne avec un salaire imposable sur [1000, 100 000] et un capital en action [0, 100 000].\n", "\n", "#### D\u00e9finition des simulations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# SIMULATIONS pour un revenu imposable allant de REVENU_MIN \u00e0 REVENU_MAX et un capital en action allant de REVENU_MIN \u00e0 REVENU_MAX\n", "OPENFISCA_API = \"http://api.openfisca.fr/api/1/simulate\"\n", "CAPITAL_MIN = 0\n", "CAPITAL_MAX = 100000\n", "SALI_MIN = 1000\n", "SALI_MAX = CAPITAL_MAX\n", "COUNT = 200\n", "\n", "simulation = dict(\n", " decomposition = [\n", " dict(code = 'salsuperbrut', title = 'Salaire super brut'),\n", " dict(code = 'salnet', title = 'Salaire net'),\n", " dict(code = 'sali', title = 'Salaire imposable'),\n", " dict(code = 'revdisp', title = 'Revenu disponible'),\n", " dict(code = 'cotsoc_noncontrib', title = 'Cotisations sociales non contributives'),\n", " dict(code = 'cotsal_contrib', title = 'Cotisations sociales salariales contributives'),\n", " dict(code = 'cotsal_noncontrib', title = 'Cotisations sociales salariales contributives'),\n", " dict(code='cotpat_main_d_oeuvre', title='cotpat_main_d_oeuvre'),\n", " dict(code = 'cotpat_contrib', title = 'Cotisations pa contributives'),\n", " dict(code = 'cotpat_noncontrib', title = 'Cotisations pa non contributives'),\n", " dict(code = 'irpp', title = 'irpp'),\n", " dict(code = 'csg', title = 'csg'),\n", " dict(code = 'crds', title = 'crds'),\n", " dict(code = 'f2dc', title = 'f2dc'),\n", " dict(code = 'rev_cap_bar', title = 'rev_cap_bar'),\n", " ],\n", " scenarios = [\n", " dict(\n", " axes = [\n", " dict(\n", " count = COUNT,\n", " max = SALI_MAX,\n", " min = SALI_MIN,\n", " name = 'sali',\n", " ),\n", " dict(\n", " count = COUNT+1,\n", " max = CAPITAL_MAX,\n", " min = CAPITAL_MIN,\n", " name = 'f2dc',\n", " )\n", " ],\n", " test_case = dict(\n", " familles = [\n", " dict(\n", " parents = ['ind0'],\n", " ),\n", " ],\n", " foyers_fiscaux = [\n", " dict(\n", " declarants = ['ind0'],\n", " ),\n", " ],\n", " individus = [\n", " dict(\n", " activite = u'Actif occup\u00e9',\n", " birth = 1970,\n", " cadre = True,\n", " id = 'ind0',\n", " statmarit = u'C\u00e9libataire',\n", " ),\n", " ],\n", " menages = [\n", " dict(\n", " personne_de_reference = 'ind0',\n", " ),\n", " ],\n", " ),\n", " year = 2013,\n", " ),\n", " ],\n", " )" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 345 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Appel de l'API OpenFisca" ] }, { "cell_type": "code", "collapsed": false, "input": [ "headers = {'Content-Type': 'application/json','User-Agent': 'OpenFisca-Notebook'}\n", "response = requests.post('http://api.openfisca.fr/api/1/simulate', data=json.dumps(simulation), headers=headers)\n", "variables = response.json(object_pairs_hook = collections.OrderedDict)['value']" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 346 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Calcul du revenu total, du taux effectif, etc." ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Cr\u00e9ation d'une dataframe pour stocker les r\u00e9sultats et ajouter des variables calcul\u00e9es.\n", "df = pd.DataFrame(dict([(var['code'], var['values']) for var in variables]))\n", "df['revenu_total'] = df['salsuperbrut']+df['f2dc']\n", "df['part_salaire'] = df['salsuperbrut']/df['revenu_total']\n", "df['part_capital'] = df['f2dc']/df['revenu_total']\n", "df['taux_effectif'] = 1 - df['revdisp']/df['revenu_total']\n", "df['taux_sali'] = 1 - df['sali']/df['revenu_total']\n", "df['taux_salnet'] = 1 - df['salnet']/df['revenu_total']\n", "df['taux_noncontrib'] = - (df['csg'] + df['crds'] + df['irpp'] + df['cotpat_noncontrib'] + df['cotsal_noncontrib'])/df['revenu_total']" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 347 }, { "cell_type": "code", "collapsed": false, "input": [ "df[['revenu_total', 'taux_effectif', 'f2dc', 'salsuperbrut']].head(n=20)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " | revenu_total | \n", "taux_effectif | \n", "f2dc | \n", "salsuperbrut | \n", "
---|---|---|---|---|
0 | \n", "1385.405151 | \n", "-3.240972 | \n", "0 | \n", "1385.405151 | \n", "
1 | \n", "2073.951416 | \n", "-1.981557 | \n", "0 | \n", "2073.951416 | \n", "
2 | \n", "2762.497803 | \n", "-1.349955 | \n", "0 | \n", "2762.497803 | \n", "
3 | \n", "3452.429443 | \n", "-0.969774 | \n", "0 | \n", "3452.429443 | \n", "
4 | \n", "4140.976074 | \n", "-0.716659 | \n", "0 | \n", "4140.976074 | \n", "
5 | \n", "4830.907715 | \n", "-0.535406 | \n", "0 | \n", "4830.907715 | \n", "
6 | \n", "5519.454102 | \n", "-0.399693 | \n", "0 | \n", "5519.454102 | \n", "
7 | \n", "6209.385742 | \n", "-0.293897 | \n", "0 | \n", "6209.385742 | \n", "
8 | \n", "6897.932617 | \n", "-0.209412 | \n", "0 | \n", "6897.932617 | \n", "
9 | \n", "7587.862793 | \n", "-0.140137 | \n", "0 | \n", "7587.862793 | \n", "
10 | \n", "8276.410156 | \n", "-0.082516 | \n", "0 | \n", "8276.410156 | \n", "
11 | \n", "8966.340820 | \n", "-0.033655 | \n", "0 | \n", "8966.340820 | \n", "
12 | \n", "9654.888672 | \n", "0.008145 | \n", "0 | \n", "9654.888672 | \n", "
13 | \n", "10344.820312 | \n", "0.044449 | \n", "0 | \n", "10344.820312 | \n", "
14 | \n", "11033.366211 | \n", "0.076153 | \n", "0 | \n", "11033.366211 | \n", "
15 | \n", "11723.297852 | \n", "0.104185 | \n", "0 | \n", "11723.297852 | \n", "
16 | \n", "12411.843750 | \n", "0.129054 | \n", "0 | \n", "12411.843750 | \n", "
17 | \n", "13101.776367 | \n", "0.151351 | \n", "0 | \n", "13101.776367 | \n", "
18 | \n", "13790.322266 | \n", "0.171379 | \n", "0 | \n", "13790.322266 | \n", "
19 | \n", "14480.252930 | \n", "0.189537 | \n", "0 | \n", "14480.252930 | \n", "
20 rows \u00d7 4 columns
\n", "