diff --git a/bpfin/financials/monthly_saving.py b/bpfin/financials/monthly_saving.py new file mode 100644 index 0000000000000000000000000000000000000000..0f2ee41c66a42cac81d23c06eb05e0a673dc1638 --- /dev/null +++ b/bpfin/financials/monthly_saving.py @@ -0,0 +1,26 @@ +import datetime +from bpfin.utilbills.bill_lib import cal_last_day + + +def monthly_saving(commissioning_date, proforma_date, prior_saving_list, post_saving_list): + """ + Calculate monthly saving on usage, or on charge, considering the commissioning date. + Args: + commissioning_date (date): the date that construction work finished, saving starts at NEXT month + proforma_date (list): list of dates, months of pro-forma time period + prior_saving_list (list): list of float, usage or charge without (prior to) savings + post_saving_list (list): list of float, usage or charge with (post to) savings + Return: + list: list of float, monthly saving values on usage or charge + """ + saving_start_date = datetime.date( + commissioning_date.year, + commissioning_date.month, + cal_last_day(commissioning_date.year, commissioning_date.month)) + saving_dict = {} + for date, prior, post in zip(proforma_date, prior_saving_list, post_saving_list): + if date > saving_start_date: + saving_dict[date] = prior - post + else: + saving_dict[date] = 0 + return list(saving_dict.values()) diff --git a/bpfin/tests/test_financials/test_monthly_saving.py b/bpfin/tests/test_financials/test_monthly_saving.py new file mode 100644 index 0000000000000000000000000000000000000000..c9ad36722fcf762d13a8f334a9b9d5c6fd580a2c --- /dev/null +++ b/bpfin/tests/test_financials/test_monthly_saving.py @@ -0,0 +1,25 @@ +import datetime +from bpfin.financials.monthly_saving import monthly_saving + + +def test_monthly_saving(): + input_proforma_date = [ + datetime.date(2017, 1, 31), + datetime.date(2017, 2, 28), + datetime.date(2017, 3, 31), + datetime.date(2017, 4, 30), + datetime.date(2017, 5, 31), + datetime.date(2017, 6, 30), + datetime.date(2017, 7, 31), + datetime.date(2017, 8, 31), + datetime.date(2017, 9, 30), + datetime.date(2017, 10, 31), + datetime.date(2017, 11, 30), + datetime.date(2017, 12, 31), ] + input_commissioning_date = datetime.date(2017, 3, 14) + input_prior_list = [100] * 12 + post_post_list = [100, 90, 80, 70, 60, 50, 40, 30, 40, 50, 60, 70] + + out_put_list = [0, 0, 0, 30, 40, 50, 60, 70, 60, 50, 40, 30] + result_list = monthly_saving(input_commissioning_date, input_proforma_date, input_prior_list, post_post_list) + assert out_put_list == result_list diff --git a/bpfin/utilbills/data_generation.py b/bpfin/utilbills/data_generation.py index d7219d8e2c0fc2fe1f8801489536159c4b77ca76..3f8da74081bbe57af83b8257a26e6c9ad78c52d5 100644 --- a/bpfin/utilbills/data_generation.py +++ b/bpfin/utilbills/data_generation.py @@ -1,9 +1,16 @@ +# import datetime +# import copy # from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough # from bpfin.utilbills.bill_prior_proj_rough import bill_prior_proj_rough +# from bpfin.financials.monthly_saving import monthly_saving +# from bpfin.lib import other as lib # from bpfin.utilbills import bill_lib as bl +# from bpfin.financials import financial_lib as fl # from bpfin.tests.testdata import sample_data as db + + # raw_bill = db.raw_bill # norm_bill = bill_month_normalize_rough(raw_bill) # prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, db.analysis_date, db.inflation_coeff_dict) @@ -11,3 +18,29 @@ # print(annual_bill_electricity) + +# prior_energy_bill = db.bill_overview_organized +# raw_income_input = db.raw_income_input + +# IS_prior = fl.Income_Statement_Table(raw_income_input, prior_energy_bill) +# IS_prior.project(-2.0, db.analysis_date, prior_energy_bill) + +# post_energy_bill = copy.deepcopy(db.bill_overview_organized) +# saving_list = monthly_saving(datetime.date(2018, 1, 1), db.proforma_date_to, db.prior_proj_rough_charge, db.post_proj_rough_charge) +# # print(saving_list) +# post_saving_e_bill = lib.sublist( +# db.prior_proj_rough_charge, +# saving_list +# ) +# # print(post_saving_e_bill) + +# post_energy_bill['electricity'] = bl.annualizing_projection( +# db.post_bill_rough['date_to'], post_saving_e_bill) + +# IS_post = fl.Income_Statement_Table(raw_income_input, post_energy_bill) +# IS_post.project(-2.0, db.analysis_date, post_energy_bill) + +# prior_noi = (IS_prior.get_noi_dict().values()) +# post_noi = (IS_post.get_noi_dict().values()) + +# print(lib.sublist(post_noi, prior_noi))