示例#1
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
示例#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
示例#3
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
示例#4
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
示例#5
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
示例#6
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
示例#7
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
示例#8
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
示例#9
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
示例#10
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