def test_decimal(self): """ Tests a Forecast with Decimal inputs. """ # Convert values to Decimal: self.setUp_decimal() # This test is based on test_multi_year: # Build a two-year forecast. Should contribute $360 each year. # No tax refunds or withdrawals. self.scenario = Scenario(self.initial_year, 2) self.tax_forecast_dummy.tax_adjustment = Decimal(0) forecast = Forecast( income_forecast=self.income_forecast_dummy, living_expenses_forecast=self.living_expenses_forecast_dummy, # NOTE: Saving forecast is not a dummy because we # want to actually contribute to savings accounts: saving_forecast=self.saving_forecast, withdrawal_forecast=self.null_forecast, tax_forecast=self.tax_forecast_dummy, scenario=self.scenario, high_precision=Decimal) results = [ # pylint: disable=no-member # Pylint has trouble with attributes added via metaclass forecast.principal_history[self.initial_year], forecast.principal_history[self.initial_year + 1], self.account.balance_at_time('end') ] target = [Decimal(0), Decimal(360), Decimal(720)] for first, second in zip(results, target): self.assertAlmostEqual(first, second, places=2)
def test_update_available(self): """ Test the mechanics of the update_available method. We don't want to test the underlying SubForecast classes, so just use end-to-end dummies. """ # A 1-year forecast with no withdrawals. Should earn $1200 # in income, spend $840 on living expenses, save the remaining # $360, and withdraw $600. forecast = Forecast( income_forecast=self.income_forecast_dummy, living_expenses_forecast=self.living_expenses_forecast_dummy, saving_forecast=self.saving_forecast_dummy, withdrawal_forecast=self.withdrawal_forecast_dummy, tax_forecast=self.tax_forecast_dummy, scenario=self.scenario) results = [ sum(forecast.income_forecast.available_in.values(), 0), sum(forecast.living_expenses_forecast.available_in.values()), sum(forecast.saving_forecast.available_in.values()), sum(forecast.withdrawal_forecast.available_in.values()), sum(forecast.tax_forecast.available_in.values()), sum(forecast.tax_forecast.available_out.values()) ] target = [0, 1200, 360, 0, 600, 600] for first, second in zip(results, target): self.assertAlmostEqual(first, second, places=2)
def test_multi_year(self): """ Tests a multi-year forecast. """ # Build a two-year forecast. Should contribute $360 each year. # No tax refunds or withdrawals. self.scenario = Scenario(self.initial_year, 2) self.tax_forecast_dummy.tax_adjustment = 0 forecast = Forecast( income_forecast=self.income_forecast_dummy, living_expenses_forecast=self.living_expenses_forecast_dummy, # NOTE: Saving forecast is not a dummy because we # want to actually contribute to savings accounts: saving_forecast=self.saving_forecast, withdrawal_forecast=self.null_forecast, tax_forecast=self.tax_forecast_dummy, scenario=self.scenario) results = [ # pylint: disable=no-member # Pylint has trouble with attributes added via metaclass forecast.principal_history[self.initial_year], forecast.principal_history[self.initial_year + 1], self.account.balance_at_time('end') ] target = [0, 360, 720] for first, second in zip(results, target): self.assertAlmostEqual(first, second, places=2)
def test_payment(self): """ Tests tax payment carryovers """ # Set up a forecast where we pay $100 in taxes owing in the # middle of year 2, with no other transactions: self.scenario.num_years = 2 self.tax_forecast_dummy.tax_adjustment = -100 trans_time = 0.5 self.tax_forecast_dummy.tax_payment_timing = Timing(trans_time) forecast = Forecast(income_forecast=self.null_forecast, living_expenses_forecast=self.null_forecast, saving_forecast=self.null_forecast, withdrawal_forecast=self.null_forecast, tax_forecast=self.tax_forecast_dummy, scenario=self.scenario) # Now confirm that the refund was in fact received: self.assertEqual(forecast.available[trans_time], -100) # And confirm that there were no other non-zero transactions: self.assertTrue( all(value == 0 for timing, value in forecast.available.items() if timing != trans_time))
def test_refund(self): """ Tests tax refund carryovers """ # Set up a forecast where we receive a $100 refund in the middle # of year 2, with no other transactions: self.scenario.num_years = 2 self.tax_forecast_dummy.tax_adjustment = Money(100) trans_time = Decimal(0.5) self.tax_forecast_dummy.tax_refund_timing = Timing(trans_time) forecast = Forecast( income_forecast=self.null_forecast, living_expenses_forecast=self.null_forecast, saving_forecast=self.null_forecast, withdrawal_forecast=self.null_forecast, tax_forecast=self.tax_forecast_dummy, scenario=self.scenario) # Now confirm that the refund was in fact received: self.assertEqual(forecast.available[trans_time], Money(100)) # And confirm that there were no other non-zero transactions: self.assertTrue(all( value == 0 for timing, value in forecast.available.items() if timing != trans_time))