예제 #1
0
 def testRRSPBridgingDeposit(self):
   fund = funds.RRSPBridging()
   fund.amount = 30
   deposited, year_rec = fund.Deposit(15, utils.YearRecord())
   self.assertEqual(deposited, 0)
   self.assertEqual(fund.amount, 30)
   self.assertIn(funds.DepositReceipt(0, funds.FUND_TYPE_BRIDGING),
                 year_rec.deposits)
예제 #2
0
    def OnRetirement(self, year_rec):
        """This deals with events happening at the point of retirement."""

        # Update all incomes
        for income in self.incomes:
            income.OnRetirement(self)

        # Create RRSP bridging fund if needed
        if self.age < world.CPP_EXPECTED_RETIREMENT_AGE:
            requested = (
                world.CPP_EXPECTED_RETIREMENT_AGE - self.age
            ) * world.OAS_BENEFIT * self.strategy.oas_bridging_fraction
            self.funds["wp_rrsp"], self.funds["bridging"] = funds.SplitFund(
                self.funds["wp_rrsp"], funds.RRSPBridging(), requested)
            if self.funds["bridging"].amount < requested:
                top_up_amount = min(self.rrsp_room,
                                    requested - self.funds["bridging"].amount)
                fund_chain = [self.funds["wp_nonreg"], self.funds["wp_tfsa"]]
                # Not using ChainedWithdraw because it can't express strict overflow
                withdrawn, _, year_rec = funds.ChainedTransaction(
                    top_up_amount, fund_chain, (1, 1), (1, 1), year_rec)
                self.funds["bridging"].amount += withdrawn
                year_rec.deposits.append(
                    funds.DepositReceipt(withdrawn, funds.FUND_TYPE_RRSP))
                self.rrsp_room -= withdrawn

            self.bridging_withdrawal_table = world.GenerateCEDDrawdownTable(
                self.age, world.CPP_EXPECTED_RETIREMENT_AGE)

        # Split each fund into a CED and a CD fund
        self.funds["cd_rrsp"], self.funds["ced_rrsp"] = funds.SplitFund(
            self.funds["wp_rrsp"], funds.RRSP(),
            self.strategy.drawdown_ced_fraction * self.funds["wp_rrsp"].amount)
        del self.funds["wp_rrsp"]

        self.funds["cd_tfsa"], self.funds["ced_tfsa"] = funds.SplitFund(
            self.funds["wp_tfsa"], funds.TFSA(),
            self.strategy.drawdown_ced_fraction * self.funds["wp_tfsa"].amount)
        del self.funds["wp_tfsa"]

        self.funds["cd_nonreg"], self.funds["ced_nonreg"] = funds.SplitFund(
            self.funds["wp_nonreg"], funds.NonRegistered(),
            self.strategy.drawdown_ced_fraction *
            self.funds["wp_nonreg"].amount)
        del self.funds["wp_nonreg"]

        self.cd_drawdown_amount = sum(
            fund.amount
            for fund in (self.funds["cd_rrsp"], self.funds["cd_tfsa"],
                         self.funds["cd_nonreg"]
                         )) * self.strategy.initial_cd_fraction / year_rec.cpi

        self.assets_at_retirement = sum(
            fund.amount for fund in self.funds.values()) / year_rec.cpi

        if not self.basic_only:
            self.accumulators.fraction_persons_involuntarily_retired.UpdateOneValue(
                1 if self.age < self.strategy.planned_retirement_age else 0)
예제 #3
0
 def testRRSPBridgingUpdate(self):
   fund = funds.RRSPBridging()
   fund.amount = 20
   year_rec = utils.YearRecord()
   year_rec.growth_rate = 0.2
   year_rec.inflation = 1
   fund.Update(year_rec)
   self.assertEqual(fund.amount, 48)
   self.assertEqual(fund.unrealized_gains, 0)
예제 #4
0
 def testRRSPBridgingWithdraw(self):
   fund = funds.RRSPBridging()
   fund.amount = 20
   withdrawn, gains, year_rec = fund.Withdraw(15, utils.YearRecord())
   self.assertEqual(withdrawn, 15)
   self.assertEqual(fund.amount, 5)
   self.assertEqual(fund.unrealized_gains, 0)
   self.assertIn(funds.WithdrawReceipt(15, 0, funds.FUND_TYPE_BRIDGING),
                 year_rec.withdrawals)
예제 #5
0
def _SetUpChain(tfsa_amount=0, tfsa_room=0,
                rrsp_amount=0, rrsp_room=0,
                bridging_amount=0,
                nonreg_amount=0, nonreg_gains=0):
  year_rec = utils.YearRecord()
  tfsa = funds.TFSA()
  tfsa.amount = tfsa_amount
  year_rec.tfsa_room = tfsa_room
  rrsp = funds.RRSP()
  rrsp.amount = rrsp_amount
  year_rec.rrsp_room = rrsp_room
  bridging = funds.RRSPBridging()
  bridging.amount = bridging_amount
  nonreg = funds.NonRegistered()
  nonreg.amount = nonreg_amount
  nonreg.unrealized_gains = nonreg_gains

  return year_rec, tfsa, rrsp, bridging, nonreg 
예제 #6
0
 def testChainedDeposit(self):
   year_rec = utils.YearRecord()
   tfsa = funds.TFSA()
   year_rec.tfsa_room = 30
   rrsp = funds.RRSP()
   year_rec.rrsp_room = 50
   bridging = funds.RRSPBridging()
   bridging.amount = 60
   nonreg = funds.NonRegistered()
   fund_chain = (tfsa, rrsp, bridging, nonreg)
   proportions = (1, 1, 1, 1)
   deposited, year_rec = funds.ChainedDeposit(100, fund_chain, proportions,
                                              year_rec)
   self.assertEqual(deposited, 100)
   self.assertSequenceEqual(year_rec.deposits,
                           [funds.DepositReceipt(30, funds.FUND_TYPE_TFSA),
                            funds.DepositReceipt(50, funds.FUND_TYPE_RRSP),
                            funds.DepositReceipt(0, funds.FUND_TYPE_BRIDGING),
                            funds.DepositReceipt(20, funds.FUND_TYPE_NONREG)])
   self.assertEqual(tfsa.amount, 30)
   self.assertEqual(rrsp.amount, 50)
   self.assertEqual(bridging.amount, 60)
   self.assertEqual(nonreg.amount, 20)