def testNonRegisteredUpdateNegativeGrowthNegativeUnrealizedGains(self):
     fund = funds.NonRegistered()
     fund.amount = 20
     fund.unrealized_gains = -10
     year_rec = utils.YearRecord()
     year_rec.growth_rate = -0.4
     fund.Update(year_rec)
     self.assertEqual(fund.amount, 12)
     self.assertAlmostEqual(fund.unrealized_gains, -13.6)
     self.assertAlmostEqual(year_rec.tax_receipts[0].gross_gain, -4.4)
     self.assertEqual(year_rec.tax_receipts[0].fund_type,
                      funds.FUND_TYPE_NONREG)
     self.assertEqual(len(year_rec.tax_receipts), 1)
 def testNonRegisteredUpdateGainsDecrementPastZero(self):
     fund = funds.NonRegistered()
     fund.amount = 20
     fund.unrealized_gains = 10
     year_rec = utils.YearRecord()
     year_rec.growth_rate = -0.6
     fund.Update(year_rec)
     self.assertEqual(fund.amount, 8)
     self.assertAlmostEqual(fund.unrealized_gains, -0.4)
     self.assertAlmostEqual(year_rec.tax_receipts[0].gross_gain, -1.6)
     self.assertEqual(year_rec.tax_receipts[0].fund_type,
                      funds.FUND_TYPE_NONREG)
     self.assertEqual(len(year_rec.tax_receipts), 1)
 def testNonRegisteredUpdateZeroGrowth(self):
     fund = funds.NonRegistered()
     fund.amount = 20
     fund.unrealized_gains = 10
     year_rec = utils.YearRecord()
     year_rec.growth_rate = 0
     fund.Update(year_rec)
     self.assertEqual(fund.amount, 20)
     self.assertAlmostEqual(fund.unrealized_gains, 8)
     self.assertAlmostEqual(year_rec.tax_receipts[0].gross_gain, 2)
     self.assertEqual(year_rec.tax_receipts[0].fund_type,
                      funds.FUND_TYPE_NONREG)
     self.assertEqual(len(year_rec.tax_receipts), 1)
Beispiel #4
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 
Beispiel #5
0
 def testChainedWithdrawForcedWithdrawWantZero(self):
   rrsp = funds.RRSP()
   rrsp.amount = 100
   rrsp.forced_withdraw = 20
   nonreg = funds.NonRegistered()
   fund_chain = (rrsp, nonreg)
   proportions = (0, 1)
   withdrawn, gains, year_rec = funds.ChainedWithdraw(0, fund_chain,
                                                      proportions,
                                                      utils.YearRecord())
   self.assertEqual(withdrawn, 0)
   self.assertEqual(gains, 0)
   self.assertSequenceEqual(
       year_rec.withdrawals,
       [funds.WithdrawReceipt(20, 0, funds.FUND_TYPE_RRSP)])
   self.assertSequenceEqual(
       year_rec.deposits, [funds.DepositReceipt(20, funds.FUND_TYPE_NONREG)])
   self.assertEqual(rrsp.amount, 80)
   self.assertEqual(nonreg.amount, 20)
Beispiel #6
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)
 def testChainedWithdrawPartialInsufficientFunds(self):
     rrsp = funds.RRSP()
     rrsp.amount = 20
     tfsa = funds.TFSA()
     tfsa.amount = 20
     nonreg = funds.NonRegistered()
     nonreg.amount = 40
     nonreg.unrealized_gains = 20
     fund_chain = (rrsp, tfsa, nonreg)
     proportions = (0.1, 0.5, 1)
     withdrawn, gains, year_rec = funds.ChainedWithdraw(
         60, fund_chain, proportions, utils.YearRecord())
     self.assertEqual(withdrawn, 60)
     self.assertEqual(gains, 17)
     self.assertSequenceEqual(year_rec.withdrawals, [
         funds.WithdrawReceipt(6, 0, funds.FUND_TYPE_RRSP),
         funds.WithdrawReceipt(20, 0, funds.FUND_TYPE_TFSA),
         funds.WithdrawReceipt(34, 17, funds.FUND_TYPE_NONREG)
     ])
     self.assertEqual(rrsp.amount, 14)
     self.assertEqual(tfsa.amount, 0)
     self.assertEqual(nonreg.amount, 6)
 def testChainedWithdrawForcedWithdraw(self):
     rrsp = funds.RRSP()
     rrsp.amount = 20
     rrsp.forced_withdraw = 10
     tfsa = funds.TFSA()
     tfsa.amount = 50
     nonreg = funds.NonRegistered()
     nonreg.amount = 30
     nonreg.unrealized_gains = 15
     fund_chain = (rrsp, tfsa, nonreg)
     proportions = (0.1, 0.5, 1)
     withdrawn, gains, year_rec = funds.ChainedWithdraw(
         60, fund_chain, proportions, utils.YearRecord())
     self.assertEqual(withdrawn, 60)
     self.assertEqual(gains, 12.5)
     self.assertSequenceEqual(year_rec.withdrawals, [
         funds.WithdrawReceipt(10, 0, funds.FUND_TYPE_RRSP),
         funds.WithdrawReceipt(25, 0, funds.FUND_TYPE_TFSA),
         funds.WithdrawReceipt(25, 12.5, funds.FUND_TYPE_NONREG)
     ])
     self.assertEqual(rrsp.amount, 10)
     self.assertEqual(tfsa.amount, 25)
     self.assertEqual(nonreg.amount, 5)
 def testChainedWithdrawInsufficientFunds(self):
     # TODO check if this is correct behaviour, or if we need more complicated
     # logic for insufficient funds at the end of the chain
     rrsp = funds.RRSP()
     rrsp.amount = 20
     tfsa = funds.TFSA()
     tfsa.amount = 50
     nonreg = funds.NonRegistered()
     nonreg.amount = 20
     nonreg.unrealized_gains = 10
     fund_chain = (rrsp, tfsa, nonreg)
     proportions = (0.1, 0.5, 1)
     withdrawn, gains, year_rec = funds.ChainedWithdraw(
         60, fund_chain, proportions, utils.YearRecord())
     self.assertEqual(withdrawn, 53)
     self.assertEqual(gains, 10)
     self.assertSequenceEqual(year_rec.withdrawals, [
         funds.WithdrawReceipt(6, 0, funds.FUND_TYPE_RRSP),
         funds.WithdrawReceipt(27, 0, funds.FUND_TYPE_TFSA),
         funds.WithdrawReceipt(20, 10, funds.FUND_TYPE_NONREG)
     ])
     self.assertEqual(rrsp.amount, 14)
     self.assertEqual(tfsa.amount, 23)
     self.assertEqual(nonreg.amount, 0)