diff --git a/bpfin/utilbills/BPFINPATH b/bpfin/financials/__init__.py similarity index 100% rename from bpfin/utilbills/BPFINPATH rename to bpfin/financials/__init__.py diff --git a/bpfin/financials/cash_balance.py b/bpfin/financials/cash_balance.py new file mode 100644 index 0000000000000000000000000000000000000000..f8759ea628447f86aceb1205dedbbfecfac5103f --- /dev/null +++ b/bpfin/financials/cash_balance.py @@ -0,0 +1,19 @@ +def cash_balance(cash_dictionary): + + cash_balance_dictionary = {} + + bank_statement = {} + + for my_date, value_tuple in cash_dictionary.items(): + if value_tuple[1] is True: + cash_balance_dictionary[my_date.year] = value_tuple[0] + else: + # check if year (key) not is present in bank_statement + if my_date.year not in bank_statement: + bank_statement[my_date.year] = [] + bank_statement[my_date.year].append(value_tuple[0]) + + for year, value in bank_statement.items(): + if year not in cash_balance_dictionary: + cash_balance_dictionary[year] = sum(value)/len(value) + return cash_balance_dictionary diff --git a/bpfin/tests/test_financials/test_cash_balance.py b/bpfin/tests/test_financials/test_cash_balance.py new file mode 100644 index 0000000000000000000000000000000000000000..9a33d9af2d207e6b489111e72f6337dcb38b0037 --- /dev/null +++ b/bpfin/tests/test_financials/test_cash_balance.py @@ -0,0 +1,15 @@ +from bpfin.financials.cash_balance import cash_balance +from datetime import date + + +def test_cash_balance(): + input_dictionary = { + date(2014, 11, 1): (500, False), + date(2015, 12, 31): (600, True), + date(2016, 11, 11): (500, False), + date(2016, 10, 10): (400, False) + } + output_cash_balance = {2014: 500.0, 2015: 600, 2016: 450.0} + result = cash_balance(input_dictionary) + + assert result == output_cash_balance