Esempio n. 1
0
def test_dsct():
    population = create_empty_population_dataframe(2001, 2061)
    cohorts = Cohorts(data = population, columns = ['pop']) 
    cohorts.gen_dsct(0.05)
    test_value = cohorts.get_value((0,0,2060), 'dsct')
#    print test_value
    assert test_value <= 1
Esempio n. 2
0
def test_fr():

    #
    #
    #
    ############################################################
    ## load data
    ############################################################

    # load population data

    DIR = '../data_fr/proj_pop_insee'
    store = HDFStore(os.path.join(DIR, 'proj_pop.h5'))
    pop = store['projpop0760_FECcentESPcentMIGcent']
    store.close()
    profiles = Cohorts(data=pop, columns=['pop'])

    DIR = '../data_fr'
    store = HDFStore(os.path.join(DIR, 'profiles.h5'))
    vars = store['profiles']
    store.close()
    profiles.fill(vars)
    # set r and g
    r = 0.060
    g = 0.012

    # create discount factor and growth rate

    # print out.to_string()
    # print coh.totaux(['year', 'age'], pivot = True).to_string()

    profiles.gen_grth(g)
    profiles.gen_dsct(r)
    #    profiles.to_percap()

    #    profiles.to_csv('out.csv')
    # profiles['typ1'].unstack(level = 'year').to_csv('out.csv')
    #print profiles['typ1'].unstack(level = 'year').head().to_string()
    #print profiles['grth']
    #print profiles['tva']
    var = 'educ'
    pv_g = profiles.pv_ga(var)
    y = 2060
    a = 4
    #    print (profiles.ix[a,1,y][var]*profiles.ix[a,1,y]['pop']*profiles.ix[a,1,y]['grth']*profiles.ix[a,1,y]['dsct'])
    #    print pvf[2060].head()
    #    print pvf.index
    #    print pv_g[2060].head()
    p = profiles.pv_percap(var)
    print p.index.names
    print p.ix[:, 0, 2007].to_string()
    print p
Esempio n. 3
0
def test_fr():
        
#    
#    
#    
    ############################################################
    ## load data
    ############################################################
    
    # load population data

    DIR= '../data_fr/proj_pop_insee'
    store = HDFStore(os.path.join(DIR,'proj_pop.h5'))
    pop = store['projpop0760_FECcentESPcentMIGcent']
    store.close()
    profiles = Cohorts(data = pop, columns = ['pop'])
    
    DIR= '../data_fr'
    store = HDFStore(os.path.join(DIR,'profiles.h5'))
    vars = store['profiles']
    store.close()
    profiles.fill(vars)
    # set r and g
    r = 0.060
    g = 0.012
    
    # create discount factor and growth rate
    
    # print out.to_string()
    # print coh.totaux(['year', 'age'], pivot = True).to_string()
    
    profiles.gen_grth(g)
    profiles.gen_dsct(r)
#    profiles.to_percap()

#    profiles.to_csv('out.csv')
    # profiles['typ1'].unstack(level = 'year').to_csv('out.csv')
    #print profiles['typ1'].unstack(level = 'year').head().to_string()
    #print profiles['grth']
    #print profiles['tva']
    var = 'educ'
    pv_g =  profiles.pv_ga(var)
    y = 2060
    a = 4
#    print (profiles.ix[a,1,y][var]*profiles.ix[a,1,y]['pop']*profiles.ix[a,1,y]['grth']*profiles.ix[a,1,y]['dsct'])
#    print pvf[2060].head()
#    print pvf.index
#    print pv_g[2060].head()
    p = profiles.pv_percap(var)
    print p.index.names
    print p.ix[:,0,2007].to_string()
    print p
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 = Cohorts(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_us():    
    ############################################"
    ## set simulation parameters
    ############################################"
    
    # set path to data
    DIR= 'data_us'
    
    # number of types (tax or transfer)
    nb_type = 17
    
    # define aggregate scenario
    agg_scenar = 'aggmed' # can be in ('agglow', 'aggmed', 'agghigh')
    
    # define population scenario
    pop_scenar = 'popmed' # can be in ('popmed', 'pophigh', 'poplow')
    
    ############################################################
    ## load data
    ############################################################
    
    # load population data
    datafile = os.path.join(DIR, pop_scenar +'.csv')
    profiles = Cohorts()
    profiles.set_population_from_csv(datafile)
    
    
    # load relative profiles and fill Cohorte
    datafile = os.path.join(DIR, 'rp.csv')
    data = read_csv(datafile, index_col = [0,1])
    for i in range(1, nb_type + 1):
        var = 'typ%i'%i
        profiles.new_type(var)
        for sex in profiles.index_sets['sex']:
            profiles.fill(data.ix[sex, i], var, sex)
    
    # load aggregate data (year x types)
    datafile = os.path.join(DIR, agg_scenar+'.csv')
    agg = read_csv(datafile, index_col = 0)
    profiles.add_agg(agg)    
    
    # set r and g
    r = 0.060
    g = 0.012
    
    # create discount factor and growth rate
    
    # print out.to_string()
    # print coh.totaux(['year', 'age'], pivot = True).to_string()
    
    profiles.gen_grth(g)
    profiles.gen_dsct(r)
    profiles.to_percap()
    
    # profiles['typ1'].unstack(level = 'year').to_csv('out.csv')
    #print profiles['typ1'].unstack(level = 'year').head().to_string()
    
    print profiles.pv_ga('typ1')
Esempio n. 6
0
def test_us():
    ############################################"
    ## set simulation parameters
    ############################################"

    # set path to data
    DIR = 'data_us'

    # number of types (tax or transfer)
    nb_type = 17

    # define aggregate scenario
    agg_scenar = 'aggmed'  # can be in ('agglow', 'aggmed', 'agghigh')

    # define population scenario
    pop_scenar = 'popmed'  # can be in ('popmed', 'pophigh', 'poplow')

    ############################################################
    ## load data
    ############################################################

    # load population data
    datafile = os.path.join(DIR, pop_scenar + '.csv')
    profiles = Cohorts()
    profiles.set_population_from_csv(datafile)

    # load relative profiles and fill Cohorte
    datafile = os.path.join(DIR, 'rp.csv')
    data = read_csv(datafile, index_col=[0, 1])
    for i in range(1, nb_type + 1):
        var = 'typ%i' % i
        profiles.new_type(var)
        for sex in profiles.index_sets['sex']:
            profiles.fill(data.ix[sex, i], var, sex)

    # load aggregate data (year x types)
    datafile = os.path.join(DIR, agg_scenar + '.csv')
    agg = read_csv(datafile, index_col=0)
    profiles.add_agg(agg)

    # set r and g
    r = 0.060
    g = 0.012

    # create discount factor and growth rate

    # print out.to_string()
    # print coh.totaux(['year', 'age'], pivot = True).to_string()

    profiles.gen_grth(g)
    profiles.gen_dsct(r)
    profiles.to_percap()

    # profiles['typ1'].unstack(level = 'year').to_csv('out.csv')
    #print profiles['typ1'].unstack(level = 'year').head().to_string()

    print profiles.pv_ga('typ1')