Esempio n. 1
0
def test_simulation_creation():

    # Building population and profiles dataframes 
    # with ones everywhere
    population_dataframe = create_testing_population_dataframe(year_start=2001, year_end=2061)

    profiles_dataframe = create_constant_profiles_dataframe(population_dataframe, tax=1)

    r = 0
    g = 0
    simulation = Simulation()  
    simulation.set_population(population_dataframe)
    simulation.set_profiles(profiles_dataframe)
    simulation.set_population_projection(year_length=200, method="constant")
    
#    simulation.set_tax_projection(rate = g, method="per_capita")
    simulation.set_tax_projection(rate = g, method="aggregate")
    
    simulation.set_growth_rate(g)
    simulation.set_discount_rate(r)        
    simulation.create_cohorts()
    
    cohorts = simulation.cohorts
    pv =  cohorts.aggregate_generation_present_value("tax")

    assert  pv.get_value((0,0,2007), "tax") == 54
    assert  pv.get_value((0,0,2008), "tax") == 53
Esempio n. 2
0
def test_generation_extraction():
    # Creating a fake cohort
    n = 0.00
    r = 0.00
    g = 0.05
    population = create_testing_population_dataframe(year_start=2001,
                                                     year_end=2061,
                                                     rate=n)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    cohort = DataCohorts(population)
    # Applying projection methods
    year_length = 199
    method = 'stable'
    cohort.population_project(year_length, method=method)
    cohort.fill(profile)
    typ = None
    cohort.proj_tax(g, r, typ, method='per_capita')
    cohort = AccountingCohorts(cohort)
    cohort._types = ['tax']

    #Extracting generations
    start = 2030
    age = 0
    generation = cohort.extract_generation(start, typ='tax', age=age)
    count = age
    while count <= 100 & start + count <= array(
            list(generation.index_sets['year'])).max():
        assert abs((1 + g)**(count + (start - 2001)) +
                   generation.get_value((count, 1,
                                         start + count), 'tax')) == 0.0
        count += 1
Esempio n. 3
0
def test_generation_extraction():
    # Creating a fake cohort
    n = 0.00
    r = 0.00
    g = 0.05
    population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    
    cohort = DataCohorts(population)
    # Applying projection methods
    year_length = 199
    method = 'stable'   
    cohort.population_project(year_length, method = method)  
    cohort._fill(profile)
    typ = None
    cohort.proj_tax(g, r, typ,  method = 'per_capita')
    cohort = AccountingCohorts(cohort)
    cohort._types = ['tax']
    
    #Extracting generations
    start = 2030
    age = 0
    generation = cohort.extract_generation(start, typ = 'tax', age = age)
    count = age
    while count <= 100 & start + count <= array(list(generation.index_sets['year'])).max():
        assert abs((1+g)**(count+(start-2001)) + generation.get_value((count, 1, start+count), 'tax')) == 0.0
        count +=1
Esempio n. 4
0
def test_filter_value():
    """
    Testing the method to filter data from a given cohort
    """
    #Generate a testing cohort with 5% population and economy growth
    n = 0.05
    population = create_testing_population_dataframe(year_start=2001,
                                                     year_end=2061,
                                                     rate=n)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    cohort = DataCohorts(population)
    cohort._fill(profile)
    r = 0.0
    g = 0.05
    column = None
    cohort.proj_tax(g, r, column, method='per_capita')
    #Testing restrictions
    cohort_filtered = cohort.filter_value(age=list(range(0, 100, 1)),
                                          year=list(range(2001, 2060, 5)),
                                          typ='tax')
    count = 2001
    while count <= 2060:
        assert abs(
            cohort_filtered.get_value((0, 1, count), 'tax') +
            (1 + g)**(count - 2001)) == 0.0
        count += 5
Esempio n. 5
0
def test_fill_cohort():   
    population = create_empty_population_dataframe(2001, 2061)
    profiles = create_constant_profiles_dataframe(population, tax = -1, subsidies = 0.5)
    cohorts_test = DataCohorts(data = population, columns = ['pop'])
    cohorts_test.fill(profiles, year = None)
    test_value = cohorts_test.get_value((0,0,2060), 'tax')
    assert test_value == -1
Esempio n. 6
0
def test_column_combination():
    year_start = 2001
    pop_dataframe = create_empty_population_dataframe(year_start, 2061)
#     print pop_dataframe
    profiles_dataframe = create_constant_profiles_dataframe(pop_dataframe, tax=-1.0, sub=0.5)
#     print profiles_dataframe
    profiles_dataframe['net'] = profiles_dataframe.sum(axis=1) 
#     print profiles_dataframe['net']
    test_value = profiles_dataframe.get_value((0,0,2001), 'net')
#     print test_value
    assert test_value == -0.5
Esempio n. 7
0
def test_column_combination():
    year_start = 2001
    pop_dataframe = create_empty_population_dataframe(year_start, 2061)
    #     print pop_dataframe
    profiles_dataframe = create_constant_profiles_dataframe(pop_dataframe, tax=-1.0, sub=0.5)
    #     print profiles_dataframe
    profiles_dataframe["net"] = profiles_dataframe.sum(axis=1)
    #     print profiles_dataframe['net']
    test_value = profiles_dataframe.get_value((0, 0, 2001), "net")
    #     print test_value
    assert test_value == -0.5
Esempio n. 8
0
def test_comparison():

    population_dataframe = create_testing_population_dataframe(year_start=2001,
                                                               year_end=2261,
                                                               population=2)
    profiles_dataframe = create_constant_profiles_dataframe(
        population_dataframe, tax=1)

    r = 0.00
    g = 0.00
    n = 0.00

    simulation = Simulation()
    simulation.population = population_dataframe
    simulation.population_alt = population_dataframe

    simulation.profiles = profiles_dataframe

    net_gov_wealth = -10
    net_gov_spending = 0
    taxes_list = ['tax']
    payments_list = ['sub']

    simulation.set_population_projection(year_length=simulation.year_length,
                                         method="exp_growth")
    simulation.set_tax_projection(method="per_capita", rate=g)
    simulation.set_growth_rate(g)
    simulation.set_discount_rate(r)
    simulation.set_population_growth_rate(n)
    simulation.set_gov_wealth(net_gov_wealth)
    simulation.set_gov_spendings(net_gov_spending, default=True)
    simulation.create_cohorts()
    simulation.create_present_values(typ='tax')

    simulation.cohorts_alt = simulation.cohorts

    simulation.cohorts_alt.loc[
        [x == 2102 for x in simulation.cohorts_alt.index.get_level_values(2)],
        'tax'] = (-100)
    simulation.create_present_values(typ='tax', default=False)

    ipl_base = simulation.compute_ipl(typ='tax')
    ipl_alt = simulation.compute_ipl(typ='tax', default=False, precision=False)

    #Saving the decomposed ipl:
    to_save = simulation.break_down_ipl(typ='tax', default=False, threshold=60)

    #     to_save = age_class_pv
    xls = "C:/Users/Utilisateur/Documents/GitHub/ga/src/countries/france/sources/Carole_Bonnet/choc_test_alt.xlsx"

    to_save.to_excel(xls, 'ipl')
    print ipl_base
    print ipl_alt
    assert ipl_base == -105232
Esempio n. 9
0
def test_compute_net_transfers():
    population = create_empty_population_dataframe(2001, 2061)
    profiles = create_constant_profiles_dataframe(population, tax = 1, subsidies = 0.5)
    tax = ['tax']
    subsidy = ['subsidies']
    cohorts_test = DataCohorts(data = population, columns = ['pop'])
    cohorts_test.fill(profiles, year = None)
    cohorts_test.compute_net_transfers(taxes_list = tax, payments_list = subsidy)
    test_value = cohorts_test.get_value((0,0,2060), 'net_transfers')
    assert test_value == 0.5
    
    pass
Esempio n. 10
0
def test_tax_projection_aggregated():
    n = 1
    population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    g = 0.5
    r = 0.0 
    cohort = DataCohorts(population)
    cohort.fill(profile)
    typ = None
    cohort.proj_tax(g, r, typ,  method = 'aggregate')
    test_value = cohort.get_value((0,1,2002), 'tax')
    test_value2 = cohort.get_value((0,1,2002), 'sub')
    assert test_value2 < 0.5 and test_value > -1
Esempio n. 11
0
def test_comparison():
    
    population_dataframe = create_testing_population_dataframe(year_start=2001, year_end=2261, population=2)
    profiles_dataframe = create_constant_profiles_dataframe(population_dataframe, tax=1)
    
    r = 0.00
    g = 0.00
    n = 0.00
    
    simulation = Simulation()    
    simulation.population = population_dataframe
    simulation.population_alt = population_dataframe
    
    simulation.profiles = profiles_dataframe
    
    net_gov_wealth = -10
    net_gov_spending = 0
    taxes_list = ['tax']
    payments_list = ['sub']
    
    simulation.set_population_projection(year_length=simulation.year_length, method="exp_growth")
    simulation.set_tax_projection(method="per_capita", rate=g)
    simulation.set_growth_rate(g)
    simulation.set_discount_rate(r)
    simulation.set_population_growth_rate(n)
    simulation.set_gov_wealth(net_gov_wealth)
    simulation.set_gov_spendings(net_gov_spending, default=True)
    simulation.create_cohorts()
    simulation.create_present_values(typ='tax')
    
    simulation.cohorts_alt = simulation.cohorts
    
    simulation.cohorts_alt.loc[[x==2102 for x in simulation.cohorts_alt.index.get_level_values(2)], 'tax'] = (-100)
    simulation.create_present_values(typ='tax', default=False)
    
    ipl_base = simulation.compute_ipl(typ='tax')
    ipl_alt = simulation.compute_ipl(typ='tax', default=False, precision=False)
    
    #Saving the decomposed ipl:
    to_save = simulation.break_down_ipl(typ='tax', default=False, threshold=60)
       
#     to_save = age_class_pv
    xls = os.path.join(SRC_PATH, 'test_comparison.xlsx')

    to_save.to_excel(xls, 'ipl')
    print ipl_base
    print ipl_alt
    assert ipl_base == -105232
Esempio n. 12
0
def test_tax_projection():

    population = create_empty_population_dataframe(2001, 2061)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    g = 0.05
    r = 0
    cohort = DataCohorts(population)
    year_length = 200
    method = 'stable'
    cohort.population_project(year_length, method=method)
    cohort._fill(profile)
    typ = None
    cohort.proj_tax(g, r, typ, method='per_capita')
    #    print cohort
    test_value = cohort.get_value((0, 1, 2002), 'tax')
    test_value2 = cohort.get_value((0, 1, 2002), 'sub')
    #    print test_value, test_value2
    # TODO: I don't understand the following <- Just wanted to check if the for loop works by changing the value of typ in the test
    assert test_value2 > 0.5 and test_value < -1
Esempio n. 13
0
def test_create_age_class():
    """
    Testing the method to regroup age classes
    """
    population = create_testing_population_dataframe(2001, 2003)
    profile = create_constant_profiles_dataframe(population, tax = 1.0, sub=-0.5) 

    cohort = DataCohorts(population)
    cohort._fill(profile)
    cohort2 = cohort.per_capita_generation_present_value('tax', discount_rate=0)
    print cohort2.head()
    print cohort2.tail()
    step = 5.0
    age_class = cohort2.create_age_class(step = step, typ='tax')
    print age_class.tail(10)
    count = 0
    while count < 100:
        assert age_class.get_value((count, 1, 2001), 'tax') == 2, 'valeur obtenue %f' %(age_class.get_value((count, 1, 2001), 'tax'))
        count += step
Esempio n. 14
0
def test_tax_projection():

    population = create_empty_population_dataframe(2001, 2061)
    profile = create_constant_profiles_dataframe(population, tax = -1, sub=0.5) 
    g = 0.05
    r = 0
    cohort = DataCohorts(population)
    year_length = 200
    method = 'stable'   
    cohort.population_project(year_length, method = method)
    cohort.fill(profile)
    typ = None
    cohort.proj_tax(g, r, typ,  method = 'per_capita')
#    print cohort
    test_value = cohort.get_value((0,1,2002), 'tax')
    test_value2 = cohort.get_value((0,1,2002), 'sub')
#    print test_value, test_value2
    # TODO: I don't understand the following <- Just wanted to check if the for loop works by changing the value of typ in the test
    assert test_value2 > 0.5 and test_value < -1
Esempio n. 15
0
def test_create_age_class():
    """
    Testing the method to regroup age classes
    """
    population = create_testing_population_dataframe(2001, 2003)
    profile = create_constant_profiles_dataframe(population, tax=1.0, sub=-0.5)

    cohort = DataCohorts(population)
    cohort.fill(profile)
    cohort2 = cohort.per_capita_generation_present_value('tax',
                                                         discount_rate=0)
    print cohort2.head()
    print cohort2.tail()
    step = 5.0
    age_class = cohort2.create_age_class(step=step)
    print age_class.tail(10)
    count = 0
    while count < 100:
        assert age_class.get_value((count, 1, 2001), 'tax') == 2
        count += step
Esempio n. 16
0
def test_filter_value():
    """
    Testing the method to filter data from a given cohort
    """
    # Generate a testing cohort with 5% population and economy growth
    n = 0.05
    population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n)
    profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5)
    cohort = DataCohorts(population)
    cohort._fill(profile)
    r = 0.0
    g = 0.05
    column = None
    cohort.proj_tax(g, r, column, method="per_capita")
    # Testing restrictions
    cohort_filtered = cohort.filter_value(age=list(range(0, 100, 1)), year=list(range(2001, 2060, 5)), typ="tax")
    count = 2001
    while count <= 2060:
        assert abs(cohort_filtered.get_value((0, 1, count), "tax") + (1 + g) ** (count - 2001)) == 0.0
        count += 5