From d57502eca06875814f75677dd87296aafaf4ce96 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 17:50:10 -0400 Subject: [PATCH 1/5] Start DSCR formula --- bpfin/financials/scenario.py | 75 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index c606285..0982ea3 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -8,15 +8,9 @@ from bpfin.utilbills.bill_lib import form_bill_year, annualizing_projection class Scenario(): - def __init__(self, - analysis_date, - commission_date, - construction_cost, - bill_overview, - prior_annual_bill_table, - other_debt_service, - prior_income_statement_table, - prior_balance_sheet_table, + def __init__(self, analysis_date, commission_date, construction_cost, + bill_overview, prior_annual_bill_table, other_debt_service, + prior_income_statement_table, prior_balance_sheet_table, loan_input_list): """ other_debt_service (dict): dictionary of debt service values per year @@ -28,8 +22,10 @@ class Scenario(): self.prior_annual_bill_table = copy.deepcopy(prior_annual_bill_table) self.other_debt_service = copy.deepcopy(other_debt_service) - self.prior_income_statement_table = copy.deepcopy(prior_income_statement_table) - self.prior_balance_sheet_table = copy.deepcopy(prior_balance_sheet_table) + self.prior_income_statement_table = copy.deepcopy( + prior_income_statement_table) + self.prior_balance_sheet_table = copy.deepcopy( + prior_balance_sheet_table) self.post_income_statement_table = None self.post_balance_sheet_table = None @@ -38,16 +34,11 @@ class Scenario(): bill_overview=copy.deepcopy(bill_overview), prior_annual_bill_table=copy.deepcopy(prior_annual_bill_table), analysis_date=copy.deepcopy(analysis_date), - commissioning_date=copy.deepcopy(commission_date) - ) + commissioning_date=copy.deepcopy(commission_date)) self.scheduled_loan_list = None - def prelim_anlaysis(self, - prior_month_bill, - percent_saving_dict, - full_saving_dict, - growth_rate_flag, - req_dscr, + def prelim_anlaysis(self, prior_month_bill, percent_saving_dict, + full_saving_dict, growth_rate_flag, req_dscr, customer_preference): """ growth_rate_flag (float): indicating assumed growth rate, -2.0 == cagr, -1.0 == historical average @@ -61,22 +52,32 @@ class Scenario(): full_saving_dict=full_saving_dict) # generate post_saving income_statement_table object - post_annual_bill_table = copy.deepcopy(self.saving_overview.get_post_annual_bill_table()) - post_income_statement_table = copy.deepcopy(self.prior_income_statement_table) - post_income_statement_table.project(growth_rate_flag, self.analysis_date, post_annual_bill_table) + post_annual_bill_table = copy.deepcopy( + self.saving_overview.get_post_annual_bill_table()) + post_income_statement_table = copy.deepcopy( + self.prior_income_statement_table) + post_income_statement_table.project( + growth_rate_flag, self.analysis_date, post_annual_bill_table) self.post_income_statement_table = post_income_statement_table # generate post_saving balance_sheet_table object - post_saving_noi_dict = copy.deepcopy(self.post_income_statement_table.get_noi_dict()) - post_balance_sheet_table = copy.deepcopy(self.prior_balance_sheet_table) + post_saving_noi_dict = copy.deepcopy( + self.post_income_statement_table.get_noi_dict()) + post_balance_sheet_table = copy.deepcopy( + self.prior_balance_sheet_table) post_balance_sheet_table.project_balance_sheet( self.analysis_date, self.other_debt_service, post_saving_noi_dict) self.post_balance_sheet_table = post_balance_sheet_table # allocate loan and get loan schedules - first_year_saving = copy.deepcopy(self.saving_overview.get_total_first_year_saving()) - first_year_noi = copy.deepcopy(self.post_income_statement_table.get_first_year_noi(self.commission_date)) - first_year_cash = copy.deepcopy(self.post_balance_sheet_table.get_first_year_cash(self.commission_date)) + first_year_saving = copy.deepcopy( + self.saving_overview.get_total_first_year_saving()) + first_year_noi = copy.deepcopy( + self.post_income_statement_table.get_first_year_noi( + self.commission_date)) + first_year_cash = copy.deepcopy( + self.post_balance_sheet_table.get_first_year_cash( + self.commission_date)) # print('first year =', first_year_saving, first_year_noi, first_year_cash) # print(self.loan_list.loan_list[0].institute) @@ -93,14 +94,16 @@ class Scenario(): def get_post_energy_bill(self): proforma_year = form_bill_year(self.analysis_date['proforma_start'], self.analysis_date['proforma_duration']) - post_annual_bill_table = copy.deepcopy(self.saving_overview.get_post_annual_bill_table()) + post_annual_bill_table = copy.deepcopy( + self.saving_overview.get_post_annual_bill_table()) utility_type_list = ['electricity', 'gas', 'oil', 'water'] post_energy_bill = {} for year in proforma_year: current_total_energy_bill = 0 for utility_type in utility_type_list: - current_total_energy_bill += post_annual_bill_table[utility_type][year] + current_total_energy_bill += post_annual_bill_table[ + utility_type][year] post_energy_bill[year] = current_total_energy_bill return post_energy_bill @@ -133,17 +136,25 @@ class Scenario(): graph_dict = {} proforma_bill = self.get_post_energy_bill() annual_debt_service = self.get_annual_debt_service() - prior_annual_bill = self.prior_income_statement_table.get_total_energy_dict() + prior_annual_bill = self.prior_income_statement_table.get_total_energy_dict( + ) net_saving_dict = {} print(prior_annual_bill) for year in prior_annual_bill: - net_saving_dict[year] = prior_annual_bill[year] - proforma_bill[year] - annual_debt_service[year] + net_saving_dict[ + year] = prior_annual_bill[year] - proforma_bill[year] - annual_debt_service[year] graph_dict = { 'energy_expenses': proforma_bill, 'total_loan': annual_debt_service, - 'net_savings': net_saving_dict} + 'net_savings': net_saving_dict + } return graph_dict + def get_dscr(self, analysis_date): + + pro_forma_years = form_bill_year(analysis_date['proforma_start'], + analysis_date['proforma_duration']) + # ***** ugly test that can be a guide for front end dev ***** # growth_toggle = 0.01 -- GitLab From fa8cf987bc44a76be70d394272f66d53823213f1 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 18:10:25 -0400 Subject: [PATCH 2/5] dscr push --- bpfin/financials/scenario.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index 0982ea3..5412ccf 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -150,11 +150,32 @@ class Scenario(): } return graph_dict - def get_dscr(self, analysis_date): + def get_dscr(self, analysis_date, noi_dict, cash_dict, savings_dict, + debt_dict): pro_forma_years = form_bill_year(analysis_date['proforma_start'], analysis_date['proforma_duration']) + dscr_dict = {} + + for year in pro_forma_years: + storing_dscr = {} + if year in debt_dict and debt_dict[year] != 0: + if year in noi_dict: + storing_dscr['NOI DSCR'] = noi_dict[year] / debt_dict[year] + storing_dscr['NOI DSCR'] = None + if year in cash_dict: + storing_dscr['Cash DSCR'] = cash_dict[year] / debt_dict[ + year] + storing_dscr['Cash DSCR'] = None + if year in savings_dict: + storing_dscr['Savings DSCR'] = savings_dict[ + year] / debt_dict[year] + storing_dscr['Savings DSCR'] = None + dscr_dict[year] = storing_dscr + + return dscr_dict + # ***** ugly test that can be a guide for front end dev ***** # growth_toggle = 0.01 -- GitLab From d4ee9f1b7321c62677c3ac2bf4465506071aec4d Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 18:49:04 -0400 Subject: [PATCH 3/5] Push --- bpfin/financials/scenario.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index 5412ccf..e15ca92 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -156,23 +156,28 @@ class Scenario(): pro_forma_years = form_bill_year(analysis_date['proforma_start'], analysis_date['proforma_duration']) - dscr_dict = {} + dscr_dict = {'noi_dict': {}, 'cash_dict': {}, 'savings_dict': {}} for year in pro_forma_years: - storing_dscr = {} + noi_temp_dict = {} + cash_temp_dict = {} + savings_temp_dict = {} if year in debt_dict and debt_dict[year] != 0: if year in noi_dict: - storing_dscr['NOI DSCR'] = noi_dict[year] / debt_dict[year] - storing_dscr['NOI DSCR'] = None + noi_temp_dict['NOI DSCR'] = noi_dict[year] / debt_dict[ + year] + noi_temp_dict['NOI DSCR'] = -1 if year in cash_dict: - storing_dscr['Cash DSCR'] = cash_dict[year] / debt_dict[ + cash_temp_dict['Cash DSCR'] = noi_dict[year] / debt_dict[ year] - storing_dscr['Cash DSCR'] = None + noi_temp_dict['Cash DSCR'] = -1 if year in savings_dict: - storing_dscr['Savings DSCR'] = savings_dict[ + savings_temp_dict['Savings DSCR'] = noi_dict[ year] / debt_dict[year] - storing_dscr['Savings DSCR'] = None - dscr_dict[year] = storing_dscr + noi_temp_dict['Savings DSCR'] = -1 + dscr_dict['noi_dict'] = noi_temp_dict + dscr_dict['cash_dict'] = cash_temp_dict + dscr_dict['savings_dict'] = savings_temp_dict return dscr_dict -- GitLab From a1e2dd405c29be81ee8e57eb93318dc28cad0b41 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 19:01:19 -0400 Subject: [PATCH 4/5] change name and dict references --- bpfin/financials/scenario.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index e15ca92..a84f7a9 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -164,17 +164,17 @@ class Scenario(): savings_temp_dict = {} if year in debt_dict and debt_dict[year] != 0: if year in noi_dict: - noi_temp_dict['NOI DSCR'] = noi_dict[year] / debt_dict[ + noi_temp_dict['noi_dscr'] = noi_dict[year] / debt_dict[ year] - noi_temp_dict['NOI DSCR'] = -1 + noi_temp_dict['noi_dscr'] = -1 if year in cash_dict: - cash_temp_dict['Cash DSCR'] = noi_dict[year] / debt_dict[ + cash_temp_dict['cash_dscr'] = cash_dict[year] / debt_dict[ year] - noi_temp_dict['Cash DSCR'] = -1 + noi_temp_dict['cash_dscr'] = -1 if year in savings_dict: - savings_temp_dict['Savings DSCR'] = noi_dict[ + savings_temp_dict['savings_dscr'] = savings_dict[ year] / debt_dict[year] - noi_temp_dict['Savings DSCR'] = -1 + noi_temp_dict['savings_dscr'] = -1 dscr_dict['noi_dict'] = noi_temp_dict dscr_dict['cash_dict'] = cash_temp_dict dscr_dict['savings_dict'] = savings_temp_dict -- GitLab From c8bede7247ec1caaa739750e7d324f1dc53127fa Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 19:03:39 -0400 Subject: [PATCH 5/5] Done --- bpfin/financials/scenario.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index a84f7a9..92a3019 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -164,17 +164,17 @@ class Scenario(): savings_temp_dict = {} if year in debt_dict and debt_dict[year] != 0: if year in noi_dict: - noi_temp_dict['noi_dscr'] = noi_dict[year] / debt_dict[ + noi_temp_dict[year] = noi_dict[year] / debt_dict[ year] - noi_temp_dict['noi_dscr'] = -1 + noi_temp_dict[year] = -1 if year in cash_dict: - cash_temp_dict['cash_dscr'] = cash_dict[year] / debt_dict[ + cash_temp_dict[year] = cash_dict[year] / debt_dict[ year] - noi_temp_dict['cash_dscr'] = -1 + noi_temp_dict[year] = -1 if year in savings_dict: - savings_temp_dict['savings_dscr'] = savings_dict[ + savings_temp_dict[year] = savings_dict[ year] / debt_dict[year] - noi_temp_dict['savings_dscr'] = -1 + noi_temp_dict[year] = -1 dscr_dict['noi_dict'] = noi_temp_dict dscr_dict['cash_dict'] = cash_temp_dict dscr_dict['savings_dict'] = savings_temp_dict -- GitLab