Esempio n. 1
0
 def testChainedDepositInsufficientRoom(self):
   year_rec = utils.YearRecord()
   tfsa = funds.TFSA()
   year_rec.tfsa_room = 30
   rrsp = funds.RRSP()
   year_rec.rrsp_room = 50
   fund_chain = (tfsa, rrsp)
   proportions = (1, 1)
   deposited, year_rec = funds.ChainedDeposit(100, fund_chain, proportions,
                                              year_rec)
   self.assertEqual(deposited, 80)
   self.assertSequenceEqual(year_rec.deposits,
                            [funds.DepositReceipt(30, funds.FUND_TYPE_TFSA),
                             funds.DepositReceipt(50, funds.FUND_TYPE_RRSP)])
   self.assertEqual(tfsa.amount, 30)
   self.assertEqual(rrsp.amount, 50)
Esempio n. 2
0
 def testChainedDepositProportions(self):
   year_rec = utils.YearRecord()
   tfsa = funds.TFSA()
   year_rec.tfsa_room = 30
   rrsp = funds.RRSP()
   year_rec.rrsp_room = 30
   nonreg = funds.NonRegistered()
   fund_chain = (tfsa, rrsp, nonreg)
   proportions = (0.2, 0.5, 1)
   deposited, year_rec = funds.ChainedDeposit(100, fund_chain, proportions,
                                              year_rec)
   self.assertEqual(deposited, 100)
   self.assertSequenceEqual(year_rec.deposits,
                            [funds.DepositReceipt(20, funds.FUND_TYPE_TFSA),
                             funds.DepositReceipt(30, funds.FUND_TYPE_RRSP),
                             funds.DepositReceipt(50, funds.FUND_TYPE_NONREG)])
   self.assertEqual(tfsa.amount, 20)
   self.assertEqual(rrsp.amount, 30)
   self.assertEqual(nonreg.amount, 50)
Esempio n. 3
0
    def MeddleWithCash(self, year_rec):
        """This performs all operations on subject's cash pile"""
        cash = 0

        # Get money from incomes. GIS is excluded and done after withdrawals
        for income in self.incomes[:-1]:
            amount, taxable, year_rec = income.GiveMeMoney(year_rec)
            cash += amount

        # Update RRSP room
        earnings = sum(receipt.amount for receipt in year_rec.incomes
                       if receipt.income_type == incomes.INCOME_TYPE_EARNINGS)
        self.rrsp_room += min(
            earnings * world.RRSP_ACCRUAL_FRACTION,
            utils.Indexed(world.RRSP_LIMIT, year_rec.year, 1 + world.PARGE) *
            year_rec.cpi)
        year_rec.rrsp_room = self.rrsp_room

        # Do withdrawals
        if self.retired:
            # Bridging
            if "bridging" in self.funds and self.age < world.CPP_EXPECTED_RETIREMENT_AGE:
                bridging_withdrawal_amount = self.bridging_withdrawal_table[
                    self.age] * self.funds["bridging"].amount
                withdrawn, gains, year_rec = self.funds["bridging"].Withdraw(
                    bridging_withdrawal_amount, year_rec)
                cash += withdrawn
                self.total_retirement_withdrawals += withdrawn / year_rec.cpi

            # CD drawdown strategy
            proportions = (self.strategy.drawdown_preferred_rrsp_fraction,
                           self.strategy.drawdown_preferred_tfsa_fraction, 1)
            fund_chain = [
                self.funds["cd_rrsp"], self.funds["cd_tfsa"],
                self.funds["cd_nonreg"]
            ]
            year_rec.cd_drawdown_request = self.cd_drawdown_amount * year_rec.cpi
            withdrawn, gains, year_rec = funds.ChainedWithdraw(
                year_rec.cd_drawdown_request, fund_chain, proportions,
                year_rec)
            cash += withdrawn
            year_rec.cd_drawdown_amount = withdrawn
            self.total_retirement_withdrawals += withdrawn / year_rec.cpi

            # CED drawdown_strategy
            fund_chain = [
                self.funds["ced_rrsp"], self.funds["ced_tfsa"],
                self.funds["ced_nonreg"]
            ]
            year_rec.ced_drawdown_request = sum(
                f.amount for f in fund_chain) * world.CED_PROPORTION[self.age]
            withdrawn, gains, year_rec = funds.ChainedWithdraw(
                year_rec.ced_drawdown_request, fund_chain, proportions,
                year_rec)
            cash += withdrawn
            year_rec.ced_drawdown_amount = withdrawn
            self.total_retirement_withdrawals += withdrawn / year_rec.cpi
        else:
            target_cash = utils.Indexed(
                world.YMPE, year_rec.year, 1 + world.PARGE
            ) * year_rec.cpi * self.strategy.savings_threshold * world.EARNINGS_YMPE_FRACTION
            if cash < target_cash:
                # Attempt to withdraw difference from savings
                amount_to_withdraw = target_cash - cash
                proportions = (
                    self.strategy.working_period_drawdown_tfsa_fraction,
                    self.strategy.working_period_drawdown_nonreg_fraction, 1)
                fund_chain = [
                    self.funds["wp_tfsa"], self.funds["wp_nonreg"],
                    self.funds["wp_rrsp"]
                ]
                withdrawn, gains, year_rec = funds.ChainedWithdraw(
                    amount_to_withdraw, fund_chain, proportions, year_rec)
                cash += withdrawn
            else:
                # Save
                earnings_to_save = max(earnings - target_cash,
                                       0) * self.strategy.savings_rate
                proportions = (self.strategy.savings_rrsp_fraction,
                               self.strategy.savings_tfsa_fraction, 1)
                fund_chain = [
                    self.funds["wp_rrsp"], self.funds["wp_tfsa"],
                    self.funds["wp_nonreg"]
                ]
                deposited, year_rec = funds.ChainedDeposit(
                    earnings_to_save, fund_chain, proportions, year_rec)
                cash -= deposited
                if deposited > 0:
                    self.positive_savings_years += 1

        # Update funds
        for fund in self.funds.values():
            fund.Update(year_rec)

        # update the Person's view of RRSP and TFSA room
        self.tfsa_room = year_rec.tfsa_room
        self.rrsp_room = year_rec.rrsp_room

        # Calculate EI premium and CPP contributions
        year_rec = self.CalcPayrollDeductions(year_rec)

        # Now we try to get money from GIS because year_rec is populated with the needed values.
        income = self.incomes[-1]  # GIS is last in this list
        amount, taxable, year_rec = income.GiveMeMoney(year_rec)
        cash += amount

        # Pay income taxes
        year_rec.taxes_payable = self.CalcIncomeTax(year_rec)
        cash -= year_rec.taxes_payable

        # Update incomes
        for income in self.incomes:
            income.AnnualUpdate(year_rec)

        # Pay sales tax
        non_hst_consumption = min(cash, world.SALES_TAX_EXEMPTION)
        hst_consumption = cash - non_hst_consumption
        year_rec.consumption = hst_consumption / (
            1 + world.HST_RATE) + non_hst_consumption
        year_rec.sales_taxes = hst_consumption * world.HST_RATE

        return year_rec