def test_cho(year = 2014): simulation = tax_benefit_system.new_scenario().init_single_entity( axes = [dict(count = 11, max = 24000, min = 0, name = 'chobrut')], period = year, parent1 = dict( birth = datetime.date(year - 40, 1, 1), ), ).new_simulation(debug = True) brut = simulation.get_holder('chobrut').array imposable = simulation.calculate('cho') inversion_reform = inversion_revenus.build_reform(tax_benefit_system) inverse_simulation = inversion_reform.new_scenario().init_single_entity( axes = [dict(count = 11, max = 24000, min = 0, name = 'chobrut')], period = year, parent1 = dict( birth = datetime.date(year - 40, 1, 1), ), ).new_simulation(debug = True) inverse_simulation.get_holder('chobrut').delete_arrays() inverse_simulation.get_or_new_holder('choi').array = imposable.copy() new_brut = inverse_simulation.calculate('chobrut') assert_near(new_brut, brut, error_margin = 1)
def net_plot(revenu, count = 11, max_revenu = 5000, min_revenu = 0): year = 2014 period = periods.period("{}-01".format(year)) if revenu == 'chomage': brut_name = 'chobrut' net_name = 'chonet' elif revenu == 'retraite': brut_name = 'rstbrut' net_name = 'rstnet' elif revenu == 'salaire': brut_name = 'salaire_de_base' net_name = 'salaire_net' else: return single_entity_kwargs = dict( axes = [[ dict(count = count, max = max_revenu, min = min_revenu, name = brut_name) ]], period = period, parent1 = dict( birth = datetime.date(year - 40, 1, 1), ), ) simulation = tax_benefit_system.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) smic_horaire = simulation.legislation_at(period.start).cotsoc.gen.smic_h_b smic_mensuel = smic_horaire * 35 * 52 / 12 brut = simulation.get_holder(brut_name).array simulation.get_or_new_holder('contrat_de_travail').array = brut < smic_mensuel # temps plein ou temps partiel simulation.get_or_new_holder('heures_remunerees_volume').array = brut // smic_horaire # temps plein ou temps partiel net = simulation.calculate(net_name) inversion_reform = inversion_revenus.build_reform(tax_benefit_system) inverse_simulation = inversion_reform.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) inverse_simulation.get_holder(brut_name).delete_arrays() inverse_simulation.get_or_new_holder(net_name).array = net.copy() inverse_simulation.get_or_new_holder('contrat_de_travail').array = brut < smic_mensuel # temps plein ou temps partiel inverse_simulation.get_or_new_holder('heures_remunerees_volume').array = ( (brut // smic_horaire) * (brut < smic_mensuel) ) print inverse_simulation.get_or_new_holder('contrat_de_travail').array print inverse_simulation.get_or_new_holder('heures_remunerees_volume').array new_brut = inverse_simulation.calculate(brut_name) pyplot.subplot(2, 1, 1) pyplot.plot(brut, net, 'ro', label = "direct") pyplot.plot(new_brut, net, 'db', label = "inversed") pyplot.legend() pyplot.subplot(2, 1, 2) pyplot.plot(brut, new_brut - brut, 'r-') pyplot.show() assert_near(new_brut, brut, absolute_error_margin = 1)
def check_sal(type_sal, year = 2014): period = periods.period("{}-01".format(year)) single_entity_kwargs = dict( axes = [dict(count = 101, max = 2000, min = 40, name = 'salaire_de_base')], # TODO: min = 0 period = period, parent1 = dict( birth = datetime.date(year - 40, 1, 1), type_sal = type_sal, ), ) simulation = tax_benefit_system.new_scenario().init_single_entity( **single_entity_kwargs ).new_simulation(debug = False) brut = simulation.get_holder('salaire_de_base').array smic_horaire = simulation.legislation_at(period.start).cotsoc.gen.smic_h_b smic_mensuel = smic_horaire * 35 * 52 / 12 brut = simulation.get_holder('salaire_de_base').array simulation.get_or_new_holder('contrat_de_travail').array = brut < smic_mensuel # temps plein ou temps partiel simulation.get_or_new_holder('heures_remunerees_volume').array = brut // smic_horaire # temps plein ou partiel imposable = simulation.calculate('salaire_imposable') inversion_reform = inversion_revenus.build_reform(tax_benefit_system) inverse_simulation = inversion_reform.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) inverse_simulation.get_holder('salaire_de_base').delete_arrays() inverse_simulation.get_or_new_holder('salaire_imposable_pour_inversion').array = imposable.copy() inverse_simulation.get_or_new_holder('contrat_de_travail').array = brut < smic_mensuel # temps plein ou partiel inverse_simulation.get_or_new_holder('heures_remunerees_volume').array = ( (brut // smic_horaire) * (brut < smic_mensuel) ) new_brut = inverse_simulation.calculate('salaire_de_base') assert_near(new_brut, brut, absolute_error_margin = 1)
def test_parametric_reform(): reform = ir_100_tranche_1(tax_benefit_system) scenario = reform.new_scenario().init_single_entity( axes=[ dict( count=3, name='salaire_imposable', max=100000, min=0, ), ], period=simulation_period, parent1=dict(date_naissance=datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(reference=True) assert_near(reference_simulation.calculate('impots_directs'), [0, -7889.20019531, -23435.52929688], absolute_error_margin=.01) reform_simulation = scenario.new_simulation() assert_near( reform_simulation.calculate('impots_directs'), [0, -13900.20019531, -29446.52929688], absolute_error_margin=.0001, )
def test_rst(year=2014): simulation = tax_benefit_system.new_scenario().init_single_entity( axes=[dict(count=11, max=24000, min=0, name='rstbrut')], period=year, parent1=dict(birth=datetime.date(year - 40, 1, 1), ), ).new_simulation(debug=True) brut = simulation.get_holder('rstbrut').array imposable = simulation.calculate('rst') inverse_simulation = simulation.clone(debug=True) inverse_simulation.get_holder('rstbrut').delete_arrays() inverse_simulation.get_or_new_holder('rsti').array = imposable.copy() new_brut = inverse_simulation.calculate('rstbrut') assert_near(new_brut, brut, error_margin=1)
def brut_plot(revenu, count = 11, max_revenu = 5000, min_revenu = 0): year = 2014 period = periods.period("{}-01".format(year)) if revenu == 'chomage': brut_name = 'chobrut' imposable_name = 'cho' inversible_name = 'choi' elif revenu == 'retraite': brut_name = 'rstbrut' imposable_name = 'rst' inversible_name = 'rsti' elif revenu == 'salaire': brut_name = 'salaire_de_base' imposable_name = 'sal' inversible_name = 'sali' else: return single_entity_kwargs = dict( axes = [dict(count = count, max = max_revenu, min = min_revenu, name = brut_name)], period = period, parent1 = dict( birth = datetime.date(year - 40, 1, 1), ), ) simulation = tax_benefit_system.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) brut = simulation.get_holder(brut_name).array imposable = simulation.calculate(imposable_name) inversion_reform = inversion_revenus.build_reform(tax_benefit_system) inverse_simulation = inversion_reform.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) inverse_simulation.get_holder(brut_name).delete_arrays() inverse_simulation.get_or_new_holder(inversible_name).array = imposable.copy() new_brut = inverse_simulation.calculate(brut_name) pyplot.subplot(2, 1, 1) pyplot.plot(brut, imposable, 'ro', label = "direct") pyplot.plot(new_brut, imposable, 'db', label = "inversed") pyplot.legend() pyplot.subplot(2, 1, 2) pyplot.plot(brut, new_brut - brut, 'r-') pyplot.show() assert_near(new_brut, brut, absolute_error_margin = 1)
def check_sal(type_sal, year = 2014): simulation = tax_benefit_system.new_scenario().init_single_entity( axes = [dict(count = 11, max = 24000, min = 0, name = 'salbrut')], period = year, parent1 = dict( birth = datetime.date(year - 40, 1, 1), type_sal = type_sal, ), ).new_simulation(debug = False) brut = simulation.get_holder('salbrut').array imposable = simulation.calculate('sal') inverse_simulation = simulation.clone(debug = True) inverse_simulation.get_holder('salbrut').delete_arrays() inverse_simulation.get_or_new_holder('sali').array = imposable.copy() new_brut = inverse_simulation.calculate('salbrut') assert_near(new_brut, brut, error_margin = 1)
def test_parametric_reform(): def modify_legislation_json(reference_legislation_json_copy): # FIXME update_legislation is deprecated. reform_legislation_json = reforms.update_legislation( legislation_json = reference_legislation_json_copy, path = ('children', 'ir', 'children', 'bareme', 'brackets', 0, 'rate'), period = simulation_period, value = 1, ) return reform_legislation_json simulation_year = 2013 simulation_period = periods.period('year', simulation_year) Reform = reforms.make_reform( key = 'ir_100_tranche_1', name = u"Imposition à 100% dès le premier euro et jusqu'à la fin de la 1ère tranche", reference = tax_benefit_system, ) reform = Reform() reform.modify_legislation_json(modifier_function = modify_legislation_json) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 3, name = 'salaire_imposable', max = 100000, min = 0, ), ], period = simulation_period, parent1 = dict(date_naissance = datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(reference = True) assert_near(reference_simulation.calculate('impo'), [0, -7889.20019531, -23435.52929688], absolute_error_margin = .01) reform_simulation = scenario.new_simulation() assert_near(reform_simulation.calculate('impo'), [0, -13900.20019531, -29446.52929688], absolute_error_margin = .0001)
def test_parametric_reform(): simulation_year = 2013 simulation_period = periods.period('year', simulation_year) reference_legislation_json = tax_benefit_system.legislation_json reform_legislation_json = reforms.update_legislation( legislation_json = reference_legislation_json, path = ('children', 'ir', 'children', 'bareme', 'brackets', 0, 'rate'), period = simulation_period, value = 1, ) Reform = reforms.make_reform( legislation_json = reform_legislation_json, # name = u'IR_100_tranche_1', name = u"Imposition à 100% dès le premier euro et jusqu'à la fin de la 1ère tranche", reference = tax_benefit_system, ) reform = Reform() scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 3, name = 'sal', max = 100000, min = 0, ), ], period = simulation_period, parent1 = dict(birth = datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(debug = True, reference = True) assert_near(reference_simulation.calculate('impo'), [0, -7889.20019531, -23435.52929688], error_margin = .01) reform_simulation = scenario.new_simulation(debug = True) assert_near(reform_simulation.calculate('impo'), [0, -13900.20019531, -29446.52929688], error_margin = .0001)
def test_rst(year = 2014): period = periods.period("{}-01".format(year)) single_entity_kwargs = dict( axes = [dict(count = 101, max = 2000, min = 0, name = 'rstbrut')], period = period, parent1 = dict( birth = datetime.date(year - 40, 1, 1), ), ) simulation = tax_benefit_system.new_scenario().init_single_entity( **single_entity_kwargs ).new_simulation(debug = True) brut = simulation.get_holder('rstbrut').array imposable = simulation.calculate('rst') inversion_reform = inversion_revenus.build_reform(tax_benefit_system) inverse_simulation = inversion_reform.new_scenario().init_single_entity( **single_entity_kwargs).new_simulation(debug = True) inverse_simulation.get_holder('rstbrut').delete_arrays() inverse_simulation.get_or_new_holder('rsti').array = imposable.copy() new_brut = inverse_simulation.calculate('rstbrut') assert_near(new_brut, brut, absolute_error_margin = 1)
def test_parametric_reform(): reform = ir_100_tranche_1(tax_benefit_system) scenario = reform.new_scenario().init_single_entity( axes = [ dict( count = 3, name = 'salaire_imposable', max = 100000, min = 0, ), ], period = simulation_period, parent1 = dict(date_naissance = datetime.date(simulation_year - 40, 1, 1)), ) reference_simulation = scenario.new_simulation(reference = True) assert_near(reference_simulation.calculate('impo'), [0, -7889.20019531, -23435.52929688], absolute_error_margin = .01) reform_simulation = scenario.new_simulation() assert_near(reform_simulation.calculate('impo'), [0, -13900.20019531, -29446.52929688], absolute_error_margin = .0001)