def test__calculate_current_date(self): income_tax_calc = IncomeTaxCalc() self.assertEquals(income_tax_calc.current_date, dt.date.today()) some_date = dt.date(2016, 12, 24) income_tax_calc.current_date = some_date income_tax_calc._calculate_current_date() self.assertEquals(income_tax_calc.current_date, some_date)
def test__calculate_national_income_tax_bracket(self): income_tax_calc = IncomeTaxCalc() self.assertEquals(income_tax_calc.national_income_tax_bracket, income_tax_calc._NATIONAL_INCOME_TAX_TABLE[0]) income_tax_calc.taxable_income = 50000000 income_tax_calc._calculate_national_income_tax_bracket() self.assertEquals(income_tax_calc.national_income_tax_bracket, income_tax_calc._NATIONAL_INCOME_TAX_TABLE[-1])
def test__calculate_national_income_tax_rate(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.national_income_tax_bracket = { 'bounds': [40000000 + 1, float('inf')], 'rate': 0.45, 'previous_brackets_sum': 13204000 } income_tax_calc._calculate_national_income_tax_rate() self.assertEquals(income_tax_calc.national_income_tax_rate, 0.45)
def test__calculate_taxable_income(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.total_income_for_tax = 10000000 income_tax_calc.deduction_total = 4000000 income_tax_calc._calculate_taxable_income() self.assertEquals(income_tax_calc.taxable_income, 6000000) income_tax_calc.total_income_for_tax = 4000000 income_tax_calc.deduction_total = 10000000 income_tax_calc._calculate_taxable_income() self.assertEquals(income_tax_calc.taxable_income, 0)
def test__calculate_local_income_tax(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.taxable_income = 10000000 income_tax_calc.is_resident_for_tax_purposes = False income_tax_calc._calculate_local_income_tax() self.assertEquals(income_tax_calc.local_income_tax, 0) income_tax_calc.is_resident_for_tax_purposes = True income_tax_calc._calculate_local_income_tax() self.assertEquals(income_tax_calc.local_income_tax, 1000000)
def test__calculate_deduction_total(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.medical_expense = 2500000 # Above max deduction of 2000000 income_tax_calc.social_security_expense = 1000000 income_tax_calc.life_insurance_premium = 200000 income_tax_calc.deduction_dependents = 1140000 expected = 2000000 + 1000000 + 200000 + 1140000 + 380000 income_tax_calc._calculate_deduction_total() self.assertEquals(income_tax_calc.deduction_total, expected)
def test__calculate_income_tax_shield(self): real_estate_calc = RealEstateCalc() real_estate_calc._calculate_income_tax_shield() self.assertEquals(real_estate_calc.income_tax_shield, 0) real_estate_calc.income_tax_calculator = IncomeTaxCalc() real_estate_calc.income_tax = 9000000 real_estate_calc.income_tax_calculator.total_income_tax = 10000000 real_estate_calc._calculate_income_tax_shield() self.assertEquals(real_estate_calc.income_tax_shield, 1000000) real_estate_calc.income_tax_calculator = IncomeTaxCalc() real_estate_calc.income_tax = 11000000 real_estate_calc.income_tax_calculator.total_income_tax = 10000000 real_estate_calc._calculate_income_tax_shield() self.assertEquals(real_estate_calc.income_tax_shield, 0)
def test__calculate_net_income_after_tax(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.total_income = 20000000 income_tax_calc.total_income_tax = 7000000 income_tax_calc.social_security_expense = 3000000 income_tax_calc._calculate_net_income_after_tax() self.assertEquals(income_tax_calc.net_income_after_tax, 10000000)
def test__calculate_employment_income_deduction(self): income_tax_calc = IncomeTaxCalc() self.assertEquals(income_tax_calc.employment_income_deduction, 0) income_tax_calc.employment_income_after_rent_program = 11000000 income_tax_calc._calculate_employment_income_deduction() self.assertEquals(income_tax_calc.employment_income_deduction, 2150000) income_tax_calc.employment_income_after_rent_program = 100000000 income_tax_calc._calculate_employment_income_deduction() self.assertEquals(income_tax_calc.employment_income_deduction, 2200000)
def test__calculate_total_income(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.employment_income = 10000000 income_tax_calc.other_income = 1000000 income_tax_calc._calculate_total_income() self.assertEquals(income_tax_calc.total_income, 11000000)
def test__calculate_effective_tax_rate(self): income_tax_calc = IncomeTaxCalc() self.assertEquals(income_tax_calc.effective_tax_rate, 0) income_tax_calc.net_income_after_tax = 10000000 income_tax_calc.total_income = 20000000 income_tax_calc._calculate_effective_tax_rate() self.assertEquals(income_tax_calc.effective_tax_rate, 0.5)
def test__calculate_social_security_expense(self): income_tax_calc = IncomeTaxCalc(social_security_expense=200000) self.assertEquals(income_tax_calc.social_security_expense, 200000) income_tax_calc.social_security_expense = None income_tax_calc.employment_income_after_rent_program = 10000000 income_tax_calc._calculate_social_security_expense() self.assertEquals(income_tax_calc.social_security_expense, 1195230)
def test__calculate_all_fields(self): """A basic regression test to confirm that all required functions are called as part of calculate_all_fields""" income_tax_calc = IncomeTaxCalc( employment_income=20000000, rent=2400000, is_rent_program=True, other_income=1000000, life_insurance_premium=30000, medical_expense=10000, number_of_dependents=2, social_security_expense=None, tax_deduction=100000, is_resident_for_tax_purposes=True, ) self.assertAlmostEqual(income_tax_calc.effective_tax_rate, 0.281, places=3)
def test__calculate_income_tax(self): real_estate_calc = RealEstateCalc() real_estate_calc._calculate_income_tax() self.assertEquals(real_estate_calc.income_tax, 0) real_estate_calc.calc_date = dt.date(year=2017, month=1, day=1) real_estate_calc.net_income_taxable = 1000000 # Set up tax calculator income_tax_calc = IncomeTaxCalc(employment_income=20000000, rent=2400000, is_rent_program=True, other_income=1000000, life_insurance_premium=30000, medical_expense=10000, number_of_dependents=2, social_security_expense=None, tax_deduction=100000, is_resident_for_tax_purposes=True, current_date=dt.date(year=2016, month=1, day=1)) income_tax_calc_before = copy.deepcopy(income_tax_calc) real_estate_calc.income_tax_calculator = income_tax_calc real_estate_calc._calculate_income_tax() self.assertEquals(real_estate_calc.income_tax, 4803596.6) # Confirm tax calc is unmodified self.assertEquals(income_tax_calc_before.__dict__, real_estate_calc.income_tax_calculator.__dict__) # Confirm deduction is used real_estate_calc.home_loan_deduction = 300000 real_estate_calc._calculate_income_tax() self.assertEquals(real_estate_calc.income_tax, 4503596.6)
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 test__calculate_national_income_tax(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.taxable_income = 50000000 income_tax_calc.national_income_tax_bracket = { 'bounds': [40000000 + 1, float('inf')], 'rate': 0.45, 'previous_brackets_sum': 13204000 } income_tax_calc.national_income_tax_rate = 0.45 income_tax_calc.current_date = dt.date(year=2040, month=12, day=25) income_tax_calc._calculate_national_income_tax() expected = int(4499999.55 + 13204000) self.assertEquals(income_tax_calc.national_income_tax, expected) income_tax_calc.current_date = dt.date(year=2016, month=12, day=25) income_tax_calc._calculate_national_income_tax() expected = int((4499999.55 + 13204000) * 1.021) self.assertEquals(income_tax_calc.national_income_tax, expected)
def test__calculate_deduction_dependents(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.number_of_dependents = 3 income_tax_calc._calculate_deduction_dependents() self.assertEquals(income_tax_calc.deduction_dependents, 1140000)
def test__calculate_total_income_tax(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.national_income_tax = 3000000 income_tax_calc.local_income_tax = 1000000 income_tax_calc._calculate_total_income_tax() self.assertEquals(income_tax_calc.total_income_tax, 4000000) income_tax_calc.tax_deduction = 500000 income_tax_calc._calculate_total_income_tax() self.assertEquals(income_tax_calc.total_income_tax, 3500000) income_tax_calc.tax_deduction = 5000000 income_tax_calc._calculate_total_income_tax() self.assertEquals(income_tax_calc.total_income_tax, 0)
def test__calculate_employment_income_for_tax(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.employment_income_after_rent_program = 10000000 income_tax_calc.employment_income_deduction = 1000000 income_tax_calc._calculate_employment_income_for_tax() self.assertEquals(income_tax_calc.employment_income_for_tax, 7800000)
def test__calculate_employment_income_after_rent_program(self): income_tax_calc = IncomeTaxCalc() income_tax_calc.employment_income = 10000000 income_tax_calc.other_income = 1000000 income_tax_calc.rent = 150000 * 12 income_tax_calc.is_rent_program = False income_tax_calc._calculate_employment_income_after_rent_program() self.assertEquals(income_tax_calc.employment_income_after_rent_program, income_tax_calc.employment_income) income_tax_calc.is_rent_program = True income_tax_calc._calculate_employment_income_after_rent_program() expected = 10000000 - 150000 * 12 * 0.95 self.assertEquals(income_tax_calc.employment_income_after_rent_program, expected)
import json import pprint as pp from japanrealestate.incometaxcalc import IncomeTaxCalc from japanrealestate.realestatecalc import RealEstateCalc with open('config1.json') as config_file: config = json.load(config_file) itc_params = config['income_tax_calc_params'] income_tax_calc = IncomeTaxCalc( employment_income=itc_params['employment_income'], rent=itc_params['rent'], is_rent_program=itc_params['is_rent_program'], other_income=itc_params['other_income'], life_insurance_premium=itc_params['life_insurance_premium'], medical_expense=itc_params['medical_expense'], number_of_dependents=itc_params['number_of_dependents'], social_security_expense=itc_params['social_security_expense'], tax_deduction=itc_params['tax_deduction'], is_resident_for_tax_purposes=itc_params['is_resident_for_tax_purposes']) print('*************** Income Tax Calculation ***************** ') pp.pprint(income_tax_calc.__dict__) rc_params = config['real_estate_calc_params'] real_estate_calc = RealEstateCalc( purchase_date=rc_params['purchase_date'], purchase_price=rc_params['purchase_price'],
def test__calculate_all_fields(self): """ A regression test to confirm that all required functions are called as part of calculate_all_fields. This is a pretty ugly test, lazily written by setting up a sample calculator and debugging it manually to ensure all functions are called and then hard-coding the expected values (such that if the functions are no longer called the test will fail). """ income_tax_calc = IncomeTaxCalc( employment_income=20000000, rent=2400000, is_rent_program=True, other_income=1000000, life_insurance_premium=30000, medical_expense=10000, number_of_dependents=2, social_security_expense=None, tax_deduction=100000, is_resident_for_tax_purposes=True, current_date=dt.date(year=2016, month=1, day=1) ) real_estate_calc = RealEstateCalc( purchase_date=dt.date(2017, 1, 24), purchase_price=100000000, building_to_land_ratio=0.7, size=100, age=0, mortgage_loan_to_value=0.9, bank_valuation_to_actual=1, mortgage_tenor=30, mortgage_rate=0.01, mortgage_initiation_fees=10000, agent_fee_variable=0.03, agent_fee_fixed=20000, other_transaction_fees=0.01, # Parameters associated with ongoing concern monthly_fees=20000, property_tax_rate=0.01, maintenance_per_m2=1000, useful_life=47, calc_year=32, income_tax_calculator=income_tax_calc, # Parameters associated with renting out the real estate gross_rental_yield=0.04, renewal_income_rate=None, rental_management_rental_fee=None, rental_management_renewal_fee=None, # Parameters associated with final disposal is_primary_residence=0, is_resident_for_tax_purposes=True, sale_price=47000000, ) expected = { 'acquisition_cost': 104261600, 'age': 0, 'agent_fee_fixed': 20000, 'agent_fee_variable': 0.03, 'bank_valuation_to_actual': 1, 'book_value': 46919170.0, 'building_to_land_ratio': 0.7, 'calc_date': dt.date(2049, 1, 24), 'calc_year': 32, 'capital_gains': 0, 'capital_gains_tax': 0, 'capital_gains_tax_primary_residence_deduction': 0, 'capital_gains_tax_rate': 0.2, 'cumulative_net_income': -27992342, 'depreciated_building_value': 22519170.0, 'depreciation': 1608510, 'depreciation_annual': 1608510, 'depreciation_cumulative': 53080830, 'depreciation_percentage': 0.02127659574468085, 'depreciation_years': 47, 'equity_value': 46919170.0, 'gross_rental_yield': 0.04, 'home_loan_deduction': 0, 'income_tax': 4633082, 'income_tax_calculator': income_tax_calc, 'income_tax_real_estate': 310108, 'income_tax_shield': 0, 'is_primary_residence': 0, 'is_resident_for_tax_purposes': True, 'maintenance_expense': 100000, 'maintenance_per_m2': 1000, 'monthly_fees': 20000, 'monthly_fees_annualized': 240000, 'mortgage': real_estate_calc.mortgage, 'mortgage_amount_outstanding': 0, 'mortgage_initiation_fees': 10000, 'mortgage_loan_to_value': 0.9, 'mortgage_rate': 0.01, 'mortgage_tenor': 30, 'net_income_after_taxes': 2165558, 'net_income_before_taxes': 2475666, 'net_profit_on_realestate': 2721658, 'net_income_taxable': 867156, 'other_transaction_fees': 0.01, 'property_tax_expense': 1000000, 'property_tax_rate': 0.01, 'purchase_agent_fee': 3261600, 'purchase_date': dt.date(2017, 1, 24), 'purchase_initial_outlay': 14271600, 'purchase_other_transaction_fees': 1000000, 'purchase_price': 100000000, 'purchase_price_and_fees': 104271600, 'purchase_price_building': 75600000.0, 'purchase_price_financed': 90000000, 'purchase_price_land': 24400000.0, 'renewal_income': 166666, 'renewal_income_rate': 0.041666666666666664, 'renovation_cost': 0, 'rental_income': 4000000, 'rental_management_renewal_expense': 135000, 'rental_management_renewal_fee': 0.03125, 'rental_management_rental_expense': 216000, 'rental_management_rental_fee': 0.05, 'rental_management_total_expense': 351000, 'sale_agent_fee': 1544400, 'sale_other_transaction_fees': 470000, 'sale_price': 47000000, 'sale_proceeds_after_fees': 44985600, 'sale_proceeds_net': 44985600, 'size': 100, 'total_expense': 1691000, 'total_income': 4166666, 'useful_life': 47, } expected_keys = list(expected.keys()) actual = real_estate_calc.__dict__ actual_keys = list(actual.keys()) actual_keys.sort() expected_keys.sort() # Confirm same keys self.assertEquals(actual_keys, expected_keys) # Confirm mortgage is not None (i.e. it was set up) self.assertIsNotNone(real_estate_calc.mortgage) # Confirm values match expected all_match = True for key, value in actual.items(): expected_value = expected[key] if isinstance(value, Number): # noinspection PyTypeChecker value = round(value, 5) expected_value = round(expected_value, 5) if value != expected_value: all_match = False print("{} with value {} does not match the expected value of {}".format(key, value, expected_value)) self.assertEquals(all_match, True)
from japanrealestate.incometaxcalc import IncomeTaxCalc from japanrealestate.realestatecalc import RealEstateCalc import csv """ This is an example of using the calculators to do due diligence on some property. The calculator is run over several years and output is printed to CSV files. """ # Let's do the due diligence assuming a salary of 20m and also assuming no salary # This lets us see how the property behaves if we earn a decent income and also if we are unemployed decent_income_tax_calc = IncomeTaxCalc( employment_income=20000000, is_resident_for_tax_purposes=True, ) zero_income_tax_calc = IncomeTaxCalc() output_file_name_to_income_tax_calc = { 'example_csv_output_20m_salary.csv': decent_income_tax_calc, 'example_csv_output_0_salary.csv': zero_income_tax_calc, } # The property details come from the agent # We do not specify a sales price so the model will resort to book value, which is a conservative estimate assuming # no capital gains and that the property depreciates to zero value over its useful life real_estate_calc = RealEstateCalc( purchase_price=68000000, building_to_land_ratio=0.3, size=62.06, age=18,