def test__calculate_monthly_payment(self): loan = Mortgage() self.assertEquals(loan.monthly_payment, 0) loan.amortization_schedule = np.asarray([5] * 12) loan._calculate_monthly_payment() self.assertEquals(loan.monthly_payment, 5)
def test__calculate_net_income_taxable(self): real_estate_calc = RealEstateCalc() # Not primary residence, no mortgage real_estate_calc.is_primary_residence = False real_estate_calc.total_income = 1500000 real_estate_calc.total_expense = 300000 real_estate_calc.depreciation = 200000 real_estate_calc.mortgage = None real_estate_calc._calculate_net_income_taxable() self.assertEquals(real_estate_calc.net_income_taxable, 1000000) # Mortgage but already matured real_estate_calc.mortgage = Mortgage( principal=20e6, tenor=10, rate=0.01, ) real_estate_calc.calc_year = 10 real_estate_calc._calculate_net_income_taxable() self.assertEquals(real_estate_calc.net_income_taxable, 1000000) # Mortgage and still active real_estate_calc.calc_year = 9 real_estate_calc._calculate_net_income_taxable() self.assertEquals(real_estate_calc.net_income_taxable, 1000000 - 11344) # Primary residence real_estate_calc.is_primary_residence = True real_estate_calc._calculate_net_income_taxable() self.assertEquals(real_estate_calc.net_income_taxable, 0)
def test__calculate_loan_periods(self): loan = Mortgage() loan.tenor = 1 loan._calculate_loan_periods() np.testing.assert_array_equal(loan.loan_periods, list(range(1, 13, 1))) loan.tenor = 2 loan._calculate_loan_periods() np.testing.assert_array_equal(loan.loan_periods, list(range(1, 25, 1)))
def test__calculate_all_fields(self): """A basic regression test to confirm that all required functions are called as part of calculate_all_fields""" loan = Mortgage(principal=200e3, tenor=30, rate=0) expected = [200000 / 30 / 12] * 30 * 12 np.testing.assert_almost_equal(loan.amortization_schedule, expected, decimal=2) self.assertAlmostEquals(loan.monthly_payment, 200000 / 30 / 12, places=2) loan = Mortgage(principal=200e3, tenor=30, rate=6.5 / 100) expected = [1264.14] * 30 * 12 np.testing.assert_almost_equal(loan.amortization_schedule, expected, decimal=2) self.assertAlmostEquals(loan.monthly_payment, 1264.14, places=2)
def test__calculate_amortization_schedule(self): loan = Mortgage() loan.tenor = 1 loan.interest_schedule = np.asarray(range(1, 13, 1)) loan.principal_schedule = np.asarray(range(12, 0, -1)) loan._calculate_amortization_schedule() expected = [13] * 12 np.testing.assert_array_equal(loan.amortization_schedule, expected)
def test__calculate_mortgage_amount_outstanding(self): real_estate_calc = RealEstateCalc() self.assertEquals(real_estate_calc.mortgage_amount_outstanding, 0) real_estate_calc.mortgage = Mortgage(principal=24000000, tenor=2, rate=0) real_estate_calc.calc_year = 0 real_estate_calc._calculate_mortgage_amount_outstanding() self.assertEquals(real_estate_calc.mortgage_amount_outstanding, 12000000) real_estate_calc.calc_year = 1 real_estate_calc._calculate_mortgage_amount_outstanding() self.assertEquals(real_estate_calc.mortgage_amount_outstanding, 0)
def test__calculate_net_income_before_taxes(self): real_estate_calc = RealEstateCalc() real_estate_calc.total_income = 5000000 real_estate_calc.total_expense = 3000000 real_estate_calc._calculate_net_income_before_taxes() self.assertEquals(real_estate_calc.net_income_before_taxes, 2000000) # Active mortgage real_estate_calc.mortgage = Mortgage() # Create a dummy mortgage and override values real_estate_calc.mortgage.monthly_payment = 100000 real_estate_calc.mortgage.tenor = 10 real_estate_calc.calc_year = 9 real_estate_calc._calculate_net_income_before_taxes() self.assertEquals(real_estate_calc.net_income_before_taxes, 2000000 - 12 * 100000) # Mortgage already paid off real_estate_calc.calc_year = 10 real_estate_calc._calculate_net_income_before_taxes() self.assertEquals(real_estate_calc.net_income_before_taxes, 2000000)
def test__calculate_total_expense(self): real_estate_calc = RealEstateCalc() real_estate_calc.maintenance_expense = 100000 real_estate_calc.monthly_fees_annualized = 200000 real_estate_calc.rental_management_total_expense = 300000 real_estate_calc.property_tax_expense = 400000 real_estate_calc._calculate_total_expense() self.assertEquals(real_estate_calc.total_expense, 1000000) # Active mortgage real_estate_calc.mortgage = Mortgage( ) # Create a dummy mortgage and override values real_estate_calc.mortgage.monthly_payment = 100000 real_estate_calc.mortgage.tenor = 10 real_estate_calc.calc_year = 9 real_estate_calc._calculate_total_expense() self.assertEquals(real_estate_calc.total_expense, 2200000) # Mortgage already paid off real_estate_calc.calc_year = 10 real_estate_calc._calculate_total_expense() self.assertEquals(real_estate_calc.total_expense, 1000000)
def test__calculate_home_loan_deduction(self): real_estate_calc = RealEstateCalc() real_estate_calc.mortgage = Mortgage( principal=60e6, tenor=30, rate=0.01, ) # Brand new and qualifying real_estate_calc.is_primary_residence = True real_estate_calc.size = 60 real_estate_calc.calc_year = 9 real_estate_calc.income_tax_calculator = IncomeTaxCalc() real_estate_calc.income_tax_calculator.taxable_income = 20000000 real_estate_calc.age = 0 real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 400000) # Not brand new and qualifying real_estate_calc.age = 1 real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 200000) # Qualifying but mortgage loan was small real_estate_calc.mortgage = Mortgage( principal=1e6, tenor=11, rate=0.01, ) real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 192077) # Test some disqualifications real_estate_calc.is_primary_residence = False real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.is_primary_residence = True real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.size = 50 real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.size = 60 real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.calc_year = 10 # Still less than mortgage tenor but can't deduct for more than 10 years real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.calc_year = 9 real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.income_tax_calculator.taxable_income = 30000000 real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.income_tax_calculator.taxable_income = 20000000 real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0) itc = real_estate_calc.income_tax_calculator real_estate_calc.income_tax_calculator = None real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.income_tax_calculator = itc real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0) mortgage = real_estate_calc.mortgage real_estate_calc.mortgage = None real_estate_calc._calculate_home_loan_deduction() self.assertEquals(real_estate_calc.home_loan_deduction, 0) real_estate_calc.mortgage = mortgage real_estate_calc._calculate_home_loan_deduction() self.assertNotEquals(real_estate_calc.home_loan_deduction, 0)
def _calculate_mortgage(self): if self.purchase_price_financed > 0: self.mortgage = Mortgage(principal=self.purchase_price_financed, tenor=self.mortgage_tenor, rate=self.mortgage_rate)
def test__calculate_principal_schedule(self): loan = Mortgage() loan.principal = 200e3 loan.tenor = 30 loan.loan_periods = np.arange(30 * 12) + 1 loan.rate = 0 loan._calculate_principal_schedule() expected = [200000 / 30 / 12] * 30 * 12 self.assertEquals(loan.principal_schedule, expected) loan.rate = 6.5 / 100 loan._calculate_principal_schedule() # Assert size, first element, last element, and sum self.assertEquals(len(loan.principal_schedule), 30 * 12) self.assertAlmostEquals(loan.principal_schedule[0], 180.80, places=2) self.assertAlmostEquals(loan.principal_schedule[-1], 1257.33, places=2) self.assertAlmostEquals(sum(loan.principal_schedule), 200e3, places=2)
def test__calculate_interest_schedule(self): loan = Mortgage() loan.principal = 200e3 loan.tenor = 30 loan.loan_periods = np.arange(30 * 12) + 1 loan.rate = 0 loan._calculate_interest_schedule() expected = [0] * 30 * 12 np.testing.assert_array_equal(loan.interest_schedule, expected) loan.rate = 6.5 / 100 loan._calculate_interest_schedule() # Assert size, first element, last element, and sum self.assertEquals(len(loan.interest_schedule), 30 * 12) self.assertAlmostEquals(loan.interest_schedule[0], 1083.33, places=2) self.assertAlmostEquals(loan.interest_schedule[-1], 6.81, places=2) self.assertAlmostEquals(sum(loan.interest_schedule), 255088.98, places=2)