def testAccumulatorBundleMerge(self):
        sim_years = world.AVG_DISABILITY_AGE - world.START_AGE
        bundle1 = utils.AccumulatorBundle()
        bundle1.UpdateConsumption(200,
                                  year=sim_years + world.BASE_YEAR,
                                  is_retired=True,
                                  period=person.RETIRED)
        bundle2 = utils.AccumulatorBundle()
        bundle2.UpdateConsumption(100,
                                  year=world.BASE_YEAR + 1,
                                  is_retired=False,
                                  period=person.EMPLOYED)
        bundle1.Merge(bundle2)

        self.assertEqual(bundle1.lifetime_consumption_summary.mean, 150)
        self.assertHistogramsEqual(bundle1.lifetime_consumption_hist.bins,
                                   [(100, 1), (200, 1)])
        self.assertAlmostEqual(
            bundle1.discounted_lifetime_consumption_summary.n, 2)

        self.assertEqual(bundle1.working_consumption_summary.n, 1)
        self.assertEqual(bundle1.working_consumption_hist.bins, [(100, 1)])

        self.assertEqual(bundle1.retired_consumption_summary.n, 1)
        self.assertHistogramsEqual(bundle1.retired_consumption_hist.bins,
                                   [(200, 1)])
        self.assertEqual(bundle1.pre_disability_retired_consumption_summary.n,
                         1)
Example #2
0
    def __init__(self,
                 strategy,
                 gender=FEMALE,
                 basic_only=False,
                 real_values=True):
        self.year = world.BASE_YEAR
        self.age = world.START_AGE
        self.gender = gender
        self.strategy = strategy
        self.cpi = 1  # Ignoring factor of 100 and StatsCan rounding rules here.
        self.cpi_history = []
        self.basic_only = basic_only
        self.real_values = real_values
        self.employed_last_year = True
        self.retired = False
        # CAUTION: GIS must be the last income in the list.
        self.incomes = [
            incomes.Earnings(),
            incomes.EI(),
            incomes.CPP(),
            incomes.OAS(),
            incomes.GIS()
        ]
        self.funds = {
            "wp_tfsa": funds.TFSA(),
            "wp_rrsp": funds.RRSP(),
            "wp_nonreg": funds.NonRegistered()
        }
        self.involuntary_retirement_random = random.random()
        self.tfsa_room = world.TFSA_INITIAL_CONTRIBUTION_LIMIT
        self.rrsp_room = world.RRSP_INITIAL_LIMIT
        self.capital_loss_carry_forward = 0

        self.accumulators = utils.AccumulatorBundle()
        self.has_been_ruined = False
        self.has_received_gis = False
        self.has_experienced_income_under_lico = False

        # The following hold real dollar amounts
        self.assets_at_retirement = 0
        self.total_retirement_withdrawals = 0
        self.total_lifetime_withdrawals = 0
        self.total_working_savings = 0

        self.positive_earnings_years = 0
        self.positive_savings_years = 0
        self.ei_years = 0
        self.gis_years = 0
        self.gross_income_below_lico_years = 0
        self.no_assets_years = 0

        self.period_years = {
            EMPLOYED: 0,
            UNEMPLOYED: 0,
            RETIRED: 0,
            INVOLUNTARILY_RETIRED: 0
        }
Example #3
0
  def testAccumulatorBundleUpdateConsumptionWorking(self):
    bundle = utils.AccumulatorBundle()
    bundle.UpdateConsumption(100, year=world.BASE_YEAR+1, is_retired=False, period=person.EMPLOYED)

    self.assertEqual(bundle.lifetime_consumption_summary.mean, 100)
    self.assertHistogramsEqual(bundle.lifetime_consumption_hist.bins, [(100, 1)])
    self.assertAlmostEqual(bundle.discounted_lifetime_consumption_summary.mean, 97)

    self.assertEqual(bundle.working_consumption_summary.mean, 100)
    self.assertHistogramsEqual(bundle.working_consumption_hist.bins, [(100, 1)])

    self.assertEqual(bundle.retired_consumption_summary.n, 0)
    self.assertEqual(bundle.retired_consumption_hist.bins, [])
    self.assertEqual(bundle.pre_disability_retired_consumption_summary.n, 0)
Example #4
0
  def testAccumulatorBundleUpdateConsumptionRetiredPostDisability(self):
    sim_years = world.AVG_DISABILITY_AGE - world.START_AGE + 1
    bundle = utils.AccumulatorBundle()
    bundle.UpdateConsumption(100, year=sim_years + world.BASE_YEAR, is_retired=True, period=person.RETIRED)

    self.assertEqual(bundle.lifetime_consumption_summary.mean, 100)
    self.assertHistogramsEqual(bundle.lifetime_consumption_hist.bins, [(100, 1)])
    self.assertAlmostEqual(bundle.discounted_lifetime_consumption_summary.mean, 100 * 0.97 ** sim_years)

    self.assertEqual(bundle.working_consumption_summary.n, 0)
    self.assertEqual(bundle.working_consumption_hist.bins, [])

    self.assertEqual(bundle.retired_consumption_summary.mean, 100)
    self.assertHistogramsEqual(bundle.retired_consumption_hist.bins, [(100, 1)])
    self.assertEqual(bundle.pre_disability_retired_consumption_summary.n, 0)