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
def junk(): population = read_csv('C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\France\sources\data_fr\pop.csv', sep=',') # print population.columns population = population.set_index(['age', 'sex']) population = population.stack() population = population.reset_index() population['level_2'] = population.level_2.convert_objects(convert_numeric=True) population['year'] = population['level_2'] population['pop'] = population[0] del population['level_2'] del population[0] population = population.set_index(['age', 'sex', 'year']) #Remove the years 2007 and beyond to ensure integrity when combined with INSEE data year = list(range(1991, 2007, 1)) filter_year = array([x in year for x in population.index.get_level_values(2)]) population = population.iloc[filter_year, :] #Loading insee data projection = HDFStore('C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\France\sources\data_fr\proj_pop_insee\proj_pop.h5', 'r') projection_dataframe = projection['/projpop0760_FECbasESPbasMIGbas'] # <-Do not know the precise meaning of this. For testing only #Combining concatened = concat([population, projection_dataframe], verify_integrity = True) concatened = concatened.reset_index() concatened['year'] = concatened.year.convert_objects(convert_numeric=True) concatened = concatened.set_index(['age', 'sex', 'year']) #Saving as HDF5 file export = HDFStore('neo_population.h5') export.append('pop', concatened, data_columns = concatened.columns) export.close() export = HDFStore('neo_population.h5', 'r') print export #Creating the simulation object net_payments = Simulation() net_payments.set_population(population) France = 'France' net_payments.set_country(France) r = 0.0 g = 0.01 net_payments.set_discount_rate(r) net_payments.set_growth_rate(g) # print net_payments # print net_payments.growth_rate, net_payments.discount_rate, net_payments.country net_payments.load_population("neo_population.h5", 'pop') net_payments.load_profiles("C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\profiles.h5", "profiles.h5") year_length = 100 net_payments.set_population_projection(year_length = year_length, method = "exp_growth", rate = 0.02) net_payments.set_tax_projection(method = "per_capita", typ = None, rate = g, discount_rate = r) net_payments.create_cohorts() #Creating a column with total taxes paid. for typ in net_payments._types: net_payments['total'] += hstack(net_payments[typ]) print net_payments['total']
concatened = concat([population, projection_dataframe], verify_integrity=True) concatened = concatened.reset_index() concatened["year"] = concatened.year.convert_objects(convert_numeric=True) concatened = concatened.set_index(["age", "sex", "year"]) # Saving as HDF5 file export = HDFStore("neo_population.h5") export.append("pop", concatened, data_columns=concatened.columns) export.close() export = HDFStore("neo_population.h5", "r") print export # Creating the simulation object net_payments = Simulation() net_payments.set_population(population) France = "France" net_payments.set_country(France) r = 0.0 g = 0.01 net_payments.set_discount_rate(r) net_payments.set_growth_rate(g) # print net_payments # print net_payments.growth_rate, net_payments.discount_rate, net_payments.country net_payments.load_population("neo_population.h5", "pop") net_payments.load_profiles("C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\profiles.h5", "profiles.h5") year_length = 100 net_payments.set_population_projection(year_length=year_length, method="exp_growth", rate=0.02) net_payments.set_tax_projection(method="per_capita", typ=None, rate=g, discount_rate=r)
#Combining concatened = concat([population, projection_dataframe], verify_integrity=True) concatened = concatened.reset_index() concatened['year'] = concatened.year.convert_objects(convert_numeric=True) concatened = concatened.set_index(['age', 'sex', 'year']) #Saving as HDF5 file export = HDFStore('neo_population.h5') export.append('pop', concatened, data_columns=concatened.columns) export.close() export = HDFStore('neo_population.h5', 'r') print export #Creating the simulation object net_payments = Simulation() net_payments.set_population(population) France = 'France' net_payments.set_country(France) r = 0.0 g = 0.01 net_payments.set_discount_rate(r) net_payments.set_growth_rate(g) # print net_payments # print net_payments.growth_rate, net_payments.discount_rate, net_payments.country net_payments.load_population("neo_population.h5", 'pop') net_payments.load_profiles( "C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\profiles.h5", "profiles.h5") year_length = 100
def junk(): population = read_csv( 'C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\France\sources\data_fr\pop.csv', sep=',') # print population.columns population = population.set_index(['age', 'sex']) population = population.stack() population = population.reset_index() population['level_2'] = population.level_2.convert_objects( convert_numeric=True) population['year'] = population['level_2'] population['pop'] = population[0] del population['level_2'] del population[0] population = population.set_index(['age', 'sex', 'year']) #Remove the years 2007 and beyond to ensure integrity when combined with INSEE data year = list(range(1991, 2007, 1)) filter_year = array( [x in year for x in population.index.get_level_values(2)]) population = population.iloc[filter_year, :] #Loading insee data projection = HDFStore( 'C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\France\sources\data_fr\proj_pop_insee\proj_pop.h5', 'r') projection_dataframe = projection[ '/projpop0760_FECbasESPbasMIGbas'] # <-Do not know the precise meaning of this. For testing only #Combining concatened = concat([population, projection_dataframe], verify_integrity=True) concatened = concatened.reset_index() concatened['year'] = concatened.year.convert_objects(convert_numeric=True) concatened = concatened.set_index(['age', 'sex', 'year']) #Saving as HDF5 file export = HDFStore('neo_population.h5') export.append('pop', concatened, data_columns=concatened.columns) export.close() export = HDFStore('neo_population.h5', 'r') print export #Creating the simulation object net_payments = Simulation() net_payments.set_population(population) France = 'France' net_payments.set_country(France) r = 0.0 g = 0.01 net_payments.set_discount_rate(r) net_payments.set_growth_rate(g) # print net_payments # print net_payments.growth_rate, net_payments.discount_rate, net_payments.country net_payments.load_population("neo_population.h5", 'pop') net_payments.load_profiles( "C:\Users\Utilisateur\Documents\GitHub\ga\src\countries\profiles.h5", "profiles.h5") year_length = 100 net_payments.set_population_projection(year_length=year_length, method="exp_growth", rate=0.02) net_payments.set_tax_projection(method="per_capita", typ=None, rate=g, discount_rate=r) net_payments.create_cohorts() #Creating a column with total taxes paid. for typ in net_payments._types: net_payments['total'] += hstack(net_payments[typ]) print net_payments['total']