Ejemplo n.º 1
0
    def setUp_decimal(self):
        """ Sets up variables based on Decimal inputs. """
        super().setUp_decimal()

        self.AccountType = RRSP
        self.constants = constants.ConstantsCanada(high_precision=Decimal)

        # Ensure that inflation_adjustments covers the entire range of
        # self.constants.RRSP_ACCRUAL_MAX and the years where self.owner is
        # 71-95 (plus a few extra for testing)
        min_year = min(min(self.constants.RRSP_ACCRUAL_MAX),
                       self.owner.birth_date.year +
                       min(self.constants.RRSP_RRIF_WITHDRAWAL_MIN))
        max_year = max(max(self.constants.RRSP_ACCRUAL_MAX),
                       self.owner.birth_date.year +
                       max(self.constants.RRSP_RRIF_WITHDRAWAL_MIN)) + 2
        self.extend_inflation_adjustments(
            min_year, max_year, high_precision=Decimal)

        self.initial_contribution_room = Decimal(100)
        # Use a value that won't result in a deduction exceeding the
        # inflation-adjusted RRSPAccrualMax (~$25,000 in 2017)
        self.owner.income = Decimal(100000)  # -> $18,000 accrual
        # Ensure there are no raises so income is the same in each year:
        self.owner.raise_rate_function = lambda _: Decimal(0)
        self.owner.gross_income = Decimal(100000)
        self.owner.spouse = Person(
            self.initial_year, "Spouse", "2 February 1998",
            gross_income=Decimal(50000),
            retirement_date=self.owner.retirement_date,
            high_precision=Decimal)
Ejemplo n.º 2
0
    def setUp(self):
        """ Sets up class to use Canadian default values. """
        # Override settings/forecaster types to use Canadian subclasses.
        # (This is conditional so that subclasses can assign their own
        # objects before calling super().setUp())
        if not hasattr(self, 'settings'):
            self.settings = SettingsCanada()
        if not hasattr(self, 'forecaster_type'):
            self.forecaster_type = ForecasterCanada
        # Let the superclass handle setup:
        super().setUp()

        self.constants = constants.ConstantsCanada()

        # Override tax_treatment to use TaxCanada object:
        self.tax_treatment = TaxCanada(
            inflation_adjust=self.scenario.inflation_adjust,
            province=self.settings.tax_province, constants=self.constants)
        # The AccountTransactionStrategy settings for ForecasterCanada
        # don't include an Account object; replace it with an
        # otherwise-identical TaxableAccount, which is represented in
        # the settings.
        self.account = TaxableAccount(
            owner=self.person,
            balance=self.account.balance,
            rate=self.account.rate,
            nper=self.account.nper)
Ejemplo n.º 3
0
    def setUp(self):
        """ Sets up variables for testing TFSAs. """
        super().setUp()
        self.AccountType = TFSA
        self.constants = constants.ConstantsCanada()

        # Ensure that inflation_adjustments covers the entire range of
        # self.constants.TFSAAnnualAccrual
        min_year = min(self.constants.TFSA_ANNUAL_ACCRUAL)
        max_year = max(self.constants.TFSA_ANNUAL_ACCRUAL) + 10
        self.extend_inflation_adjustments(min_year, max_year)
    def setUp_decimal(self):
        """ Sets up variables based on Decimal inputs. """
        super().setUp_decimal()

        self.constants = constants.ConstantsCanada(high_precision=Decimal)

        self.AccountType = RegisteredAccount

        # Randomly generate inflation adjustments based on inflation
        # rates of 1%-20%. Add a few extra years on to the end for
        # testing purposes.
        self.inflation_adjustments = {self.initial_year: 1}

        def inflation_adjust(target_year, base_year):
            """ Inflation from base_year to target_year """
            return (self.inflation_adjustments[target_year] /
                    self.inflation_adjustments[base_year])

        self.inflation_adjust = inflation_adjust

        # Use a convenient default for contribution room:
        self.contribution_room = 0
Ejemplo n.º 5
0
    def setUp_decimal(self):
        """ Sets up class to use Canadian default values. """
        # This handles almost everything:
        super().setUp_decimal()

        self.settings = SettingsCanada(high_precision=Decimal)
        self.constants = constants.ConstantsCanada(high_precision=Decimal)

        # Override tax_treatment to use TaxCanada object:
        self.tax_treatment = TaxCanada(
            inflation_adjust=self.scenario.inflation_adjust,
            province=self.settings.tax_province,
            high_precision=Decimal,
            constants=self.constants)
        # The AccountTransactionStrategy settings for ForecasterCanada
        # don't include an Account object; replace it with an
        # otherwise-identical TaxableAccount, which is represented in
        # the settings.
        self.account = TaxableAccount(
            owner=self.person,
            balance=self.account.balance,
            rate=self.account.rate,
            nper=self.account.nper,
            high_precision=Decimal)
Ejemplo n.º 6
0
    def setUp_decimal(self):  # pylint: disable=invalid-name
        """ Sets up mutable variables for each test call. """
        # Set up constants:
        self.initial_year = 2000
        self.constants = constants.ConstantsCanada(high_precision=Decimal)

        # Modify constants to make math easier:
        # Build some brackets with nice round numbers:
        self.constants.TAX_BRACKETS = {
            'Federal': {
                self.initial_year: {
                    Decimal(0): Decimal('0.1'),
                    Decimal(100): Decimal('0.2'),
                    Decimal(10000): Decimal('0.3')
                }
            },
            'BC': {
                self.initial_year: {
                    Decimal(0): Decimal('0.25'),
                    Decimal(1000): Decimal('0.5'),
                    Decimal(100000): Decimal('0.75')
                }
            }
        }
        self.constants.TAX_PERSONAL_DEDUCTION = {
            'Federal': {
                self.initial_year: Decimal('100')
            },
            'BC': {
                self.initial_year: Decimal('1000')
            }
        }
        self.constants.TAX_CREDIT_RATE = {
            'Federal': {
                self.initial_year: Decimal('0.1')
            },
            'BC': {
                self.initial_year: Decimal('0.25')
            }
        }
        self.constants.TAX_PENSION_CREDIT = {
            'Federal': {
                self.initial_year: Decimal('100')
            },
            'BC': {
                self.initial_year: Decimal('1000')
            }
        }
        # It's convenient (and accurate!) to use the same values
        # for the spousal amount and the personal deduction:
        self.constants.TAX_SPOUSAL_AMOUNT = (
            self.constants.TAX_PERSONAL_DEDUCTION)

        # Build 100 years of inflation adjustments.
        growth_factor = Decimal(32)
        year_range = range(self.initial_year, self.initial_year + 100)
        self.inflation_adjustments = {
            year: 1 + (year - self.initial_year) / growth_factor
            for year in year_range
        }

        # Set to default province:
        self.province = 'BC'
        self.tax = TaxCanada(self.inflation_adjustments,
                             province='BC',
                             constants=self.constants)

        # Set up some people to test on:
        # Person1 makes $100,000/yr, has a taxable account with $500,000
        # taxable income, and an RRSP with $500,000 in taxable income.
        self.person1 = Person(self.initial_year,
                              "Tester 1",
                              self.initial_year - 20,
                              retirement_date=self.initial_year + 45,
                              gross_income=100000)
        self.taxable_account1 = TaxableAccount(owner=self.person1,
                                               acb=0,
                                               balance=Decimal(1000000),
                                               rate=Decimal('0.05'),
                                               nper=1)
        self.taxable_account1.add_transaction(-Decimal(1000000), when='start')
        # NOTE: by using an RRSP here, a pension income tax credit will
        # be applied by TaxCanadaJurisdiction. Be aware of this if you
        # want to test this output against a generic Tax object with
        # Canadian brackets.
        self.rrsp = RRSP(self.person1,
                         inflation_adjust=self.inflation_adjustments,
                         contribution_room=0,
                         balance=Decimal(500000),
                         rate=Decimal('0.05'),
                         nper=1,
                         constants=self.constants)
        self.rrsp.add_transaction(-Decimal(500000), when='start')

        # Person2 makes $50,000/yr and has a taxable account with
        # $5000 taxable income.
        self.person2 = Person(self.initial_year,
                              "Tester 2",
                              self.initial_year - 18,
                              retirement_date=self.initial_year + 47,
                              gross_income=50000)
        self.taxable_account2 = TaxableAccount(owner=self.person2,
                                               acb=0,
                                               balance=Decimal(10000),
                                               rate=Decimal('0.05'),
                                               nper=1)
        self.taxable_account2.add_transaction(-Decimal(10000), when='start')