diff --git a/bpfin/financials/financial_income.py b/bpfin/financials/financial_income.py index e5d193dca259fdc02f9f34138171ecc81feb8497..ef3c8b2bb0413dd0004be3ba7540952ba16ad15d 100644 --- a/bpfin/financials/financial_income.py +++ b/bpfin/financials/financial_income.py @@ -167,7 +167,7 @@ class Income_Statement_Next(): if growth_rate_flag == -2.0: # growth_rate_flag == cagr growth_rate = characters['cagr'] else: - growth_rate = growth_rate_flag # growth_rate_flag == 0.00, 0.01, ... + growth_rate = growth_rate_flag/100 # growth_rate_flag == 0.00, 1.0, 2.0 ... current_revenue = last_revenue * (1 + growth_rate) self.revenue = current_revenue self.electric_opex = annual_bill_table[UTILITY_TYPE_LIST[0]][self.year] @@ -478,15 +478,6 @@ class Income_Statement_Table(): total_energy_dict[year] += self.annual_bill_table[utility][year] return total_energy_dict - # what is this??? no description, and it calls wrong attribute - # def get_utility_opex_dict(self, energy_utility_opex): - # bill_dict = {} - # for current_income_statement in self.table: - # bill_dict[current_income_statement. - # year] = current_income_statement.energy_utility_opex - - # return bill_dict - def validate_growth_rate_flag(growth_rate_flag): """ diff --git a/bpfin/financials/loan.py b/bpfin/financials/loan.py index d18e18b331d17c35730e99f0d5b0d2ae5ba045b2..de20ac9cdaf6bfea88010334fd7913c0af72b0bd 100644 --- a/bpfin/financials/loan.py +++ b/bpfin/financials/loan.py @@ -213,13 +213,3 @@ class Loan_List(): def get_downpayment(self): return self.downpayment - -# ****** ugly tests Loan and Loan_List class ********** -# loan_list = Loan_List(db.loan_input_list) -# allocated = loan_list.get_schedule( -# db.customer_preference, -# db.scenario, -# db.req_dscr, -# datetime.date(2017, 1, 12)) -# print(allocated[0].terms) -# print(allocated[0].principal_end_balance) diff --git a/bpfin/tests/test_financials/test_financial_income.py b/bpfin/tests/test_financials/test_financial_income.py index f92f4279aa0abd2492f9a3a577ccbf5761816b36..89b2e51acac10ca1883d893837f2ae373c8a6f48 100644 --- a/bpfin/tests/test_financials/test_financial_income.py +++ b/bpfin/tests/test_financials/test_financial_income.py @@ -1,6 +1,7 @@ from bpfin.lib.other import UTILITY_TYPE_LIST +from datetime import date from bpfin.tests.testdata import feature_data as db -from bpfin.financials.financial_income import validate_growth_rate_flag +from bpfin.financials.financial_income import validate_growth_rate_flag, Income_Statement_Next, Income_Statement_Table, convert_income_statement_class def test_validate_growth(): @@ -9,29 +10,166 @@ def test_validate_growth(): for (growth, validation) in zip(input_list, output_list): assert validation == validate_growth_rate_flag(growth) -# Income_Statement_Table is tested in test_back_end_call.py -# def test_Income_Statement_Table(): -# input_raw_income_input = db.raw_income_input -# input_annual_bill_table = db.bill_overview_organized -# output_cagr = 0.05409255338945984 -# output_hist_table = db.income_statement_full -# output_average_table = db.income_statement_average -# output_noi_dict = db.noi_dict_average -# output_single_year = db.income_statement_2017_avg -# output_first_year_noi = 33165.377210606544 - -# IS_table = Income_Statement_Table( -# input_raw_income_input, -# input_annual_bill_table, -# db.analysis_date) -# IS_table.project(-1.0, db.bill_overview_organized) - -# assert IS_table.get_cagr() == output_cagr # test get_cagr -# assert IS_table.get_hist_table() == output_hist_table # test get_hist_table -# assert IS_table.get_average() == output_average_table # test get_average -# assert IS_table.get_noi_dict() == output_noi_dict # test get_noi_dict -# assert IS_table.get_single_year( -# 2017) == output_single_year # test get_single_year -# print(IS_table.get_single_year(2018)) -# assert IS_table.get_first_year_noi(datetime.date(2017, 3, 14)) == output_first_year_noi +def test_Income_Statement_Next_average(): + characters = { + 'start_year': 2014, + 'end_year': 2016, + 'cagr': 0.05, + 'other_utility_percent': 0.020, # == 2.0% + 'non_utility_expense_percent': 0.15, # == 3.5% + 'revenue_average': 10005.00, + } + annual_bill_table = { + UTILITY_TYPE_LIST[0]: {2014: 1000, 2015: 1000, 2016: 1000, 2017: 1000}, + UTILITY_TYPE_LIST[1]: {2014: 2000, 2015: 2000, 2016: 2000, 2017: 2000}, + UTILITY_TYPE_LIST[2]: {2014: 500, 2015: 500, 2016: 500, 2017: 500}, + UTILITY_TYPE_LIST[3]: {2014: 500, 2015: 500, 2016: 500, 2017: 500}, + } + output_income_statement = Income_Statement_Next( + year = 2017, + last_revenue = 10000, + growth_rate_flag = -1, + characters = characters, + annual_bill_table = annual_bill_table, + ) + + output_statement = convert_income_statement_class(output_income_statement) + result_statement = { + 'year': 2017, + 'revenue': 10005.0, + 'utility_expense': 4200.1, + 'energy_opex': 4000, + 'electric_opex': 1000, + 'gas_opex': 2000, + 'oil_opex': 500, + 'water_opex': 500, + 'other_utility': 200.1, + 'non_utility_expense': 1500.75, + 'net_non_energy_opex': 1700.85, + 'total_opex': 5700.85, + 'noi': 4304.15, + } + assert output_statement == result_statement + +def test_Income_Statement_Table_1(): + raw_income_input = { + 2014: { + 'revenue': 9523.8095238095, + 'utility_expense': 4190.4761904762, + 'non_utility_expense': 1426.5714285714, + }, + 2015: { + 'revenue': 9991.1904761905, + 'utility_expense': 4199.8238095238, + 'non_utility_expense': 1498.6785714286, + }, + 2016: { + 'revenue': 10500.0000000000, + 'utility_expense': 4210.0000000000, + 'non_utility_expense': 1577.0000000000, + } + } + annual_bill_table = { + UTILITY_TYPE_LIST[0]: {2014: 1000, 2015: 1000, 2016: 1000, 2017: 1000, 2018: 1000, 2019: 1000}, + UTILITY_TYPE_LIST[1]: {2014: 2000, 2015: 2000, 2016: 2000, 2017: 2000, 2018: 2000, 2019: 2000}, + UTILITY_TYPE_LIST[2]: {2014: 500, 2015: 500, 2016: 500, 2017: 500, 2018: 500, 2019: 500}, + UTILITY_TYPE_LIST[3]: {2014: 500, 2015: 500, 2016: 500, 2017: 500, 2018: 500, 2019: 500}, + } + output_table = Income_Statement_Table( + raw_income_input=raw_income_input, + annual_bill_table = annual_bill_table, + analysis_date = { + 'proforma_start': date(2014, 1, 1), + 'proforma_duration': 6}, + ) + output_table.project( + growth_rate_flag = 2, + annual_bill_table = annual_bill_table, + ) + result_characters = { + 'start_year': 2014, + 'end_year': 2016, + 'cagr': 0.05000000000000138, + 'other_utility_percent': 0.020000000000000007, + 'non_utility_expense_percent': 0.15, + 'revenue_average': 10005.0} + assert output_table.characters == result_characters + result_table_2019 = { + 'electric_opex': 1000, + 'energy_opex': 4000, + 'gas_opex': 2000, + 'net_non_energy_opex': 1894.2562800000003, + 'noi': 5248.427720000001, + 'non_utility_expense': 1671.4026000000001, + 'oil_opex': 500, + 'other_utility': 222.8536800000001, + 'revenue': 11142.684000000001, + 'total_opex': 5894.2562800000005, + 'utility_expense': 4222.85368, + 'water_opex': 500, + 'year': 2019 + } + assert output_table.get_single_year(2019) == result_table_2019 + +def test_Income_Statement_Table_2(): + raw_income_input = { + 2014: { + 'revenue': 9523.8095238095, + 'utility_expense': 4190.4761904762, + 'non_utility_expense': 1426.5714285714, + }, + 2015: { + 'revenue': 9991.1904761905, + 'utility_expense': 4199.8238095238, + 'non_utility_expense': 1498.6785714286, + }, + 2016: { + 'revenue': 10500.0000000000, + 'utility_expense': 4210.0000000000, + 'non_utility_expense': 1577.0000000000, + } + } + annual_bill_table = { + UTILITY_TYPE_LIST[0]: {2014: 1000, 2015: 1000, 2016: 1000, 2017: 1000, 2018: 1000, 2019: 1000}, + UTILITY_TYPE_LIST[1]: {2014: 2000, 2015: 2000, 2016: 2000, 2017: 2000, 2018: 2000, 2019: 2000}, + UTILITY_TYPE_LIST[2]: {2014: 500, 2015: 500, 2016: 500, 2017: 500, 2018: 500, 2019: 500}, + UTILITY_TYPE_LIST[3]: {2014: 500, 2015: 500, 2016: 500, 2017: 500, 2018: 500, 2019: 500}, + } + output_table = Income_Statement_Table( + raw_income_input=raw_income_input, + annual_bill_table = annual_bill_table, + analysis_date = { + 'proforma_start': date(2014, 1, 1), + 'proforma_duration': 6}, + ) + output_table.project( + growth_rate_flag = -2, + annual_bill_table = annual_bill_table, + ) + result_characters = { + 'start_year': 2014, + 'end_year': 2016, + 'cagr': 0.05000000000000138, + 'other_utility_percent': 0.020000000000000007, + 'non_utility_expense_percent': 0.15, + 'revenue_average': 10005.0} + assert output_table.characters == result_characters + result_table_2019 = { + 'year': 2019, + 'revenue': 12155.06250000005, + 'utility_expense': 4243.1012500000015, + 'energy_opex': 4000, + 'electric_opex': 1000, + 'oil_opex': 500, + 'gas_opex': 2000, + 'water_opex': 500, + 'other_utility': 243.10125000000107, + 'non_utility_expense': 1823.2593750000074, + 'net_non_energy_opex': 2066.3606250000084, + 'total_opex': 6066.360625000008, + 'noi': 6088.701875000041, + } + assert output_table.get_single_year(2019) == result_table_2019 + +# Income_Statement_Table is also tested in test_back_end_call.py diff --git a/bpfin/tests/test_financials/test_loan.py b/bpfin/tests/test_financials/test_loan.py index a3ef64f934de82bc97e5dc16251011b120841e6d..4fbcb017d629ca4f5d35a380906f2896ed690168 100644 --- a/bpfin/tests/test_financials/test_loan.py +++ b/bpfin/tests/test_financials/test_loan.py @@ -97,3 +97,18 @@ def test_Loan_List_2(): 28000.0, 100000.0) assert output_loan1_end_balance == result_loan_list[0].principal_end_balance + + +# ****** ugly tests Loan and Loan_List class ********** +# loan_list = Loan_List(db.raw_loan_input_list) +# allocated = loan_list.get_schedule( +# db.customer_preference, +# db.cost_estimation, +# db.req_dscr, +# datetime.date(2017, 1, 12), +# 28000.0, +# 28000.0, +# 100000.0 +# ) +# print(allocated[0].terms) +# print(allocated[0].principal_end_balance)