Esempio n. 1
0
def test_tdd():
    accounts = Ledger('equity')

    accounts.make_stock_accounts(['cash', 'claims', 'inventory'])
    accounts.make_flow_accounts(['expenditure', 'revenue', 'cost of goods sold', 'depreciation'])

    accounts.book(
        debit=[('cash', 50), ('claims', 50)],
        credit=[('equity', 100)],
        text="Start with owners' equity, partially paid in")

    assert accounts._check_debit_eq_credit()
    assert accounts.get_total_assets() == 100

    assert accounts['cash'].get_balance() == (AccountSide.DEBIT, 50)
    assert accounts['claims'].get_balance() == (AccountSide.DEBIT, 50)
    assert accounts['equity'].get_balance() == (AccountSide.CREDIT, 100)

    #print('Initial balance')
    #accounts.print_balance_sheet()

    #print('Some purchases and operating expenses')
    accounts.book(debit=[('expenditure', 20)], credit=[('cash', 20)],text="General expenses")
    assert accounts.get_total_assets() == 80, accounts.get_total_assets()
    accounts.book(debit=[('inventory',20)],credit=[('cash',20)],text="Purchase of equipment")
    accounts.book(debit=[('depreciation',2)],credit=[('inventory',2)],text="Depreciation")
    #accounts.print_profit_and_loss()

    #print('Balance sheet after first period')
    accounts.book_end_of_period()
    #accounts.print_balance_sheet()
    assert accounts['equity'].get_balance() == (AccountSide.CREDIT, 78)
    assert accounts['cash'].get_balance() == (AccountSide.DEBIT, 10),accounts['cash'].get_balance()

    #print('Profitable sale')
    accounts.book(debit=[('cash',40)],credit=[('revenue',40)],text="Sale of goods")
    accounts.book(debit=[('cost of goods sold',10)],credit=[('inventory',10)],text="Sale of goods")
    #accounts.print_profit_and_loss()
    assert accounts['inventory'].get_balance() == (AccountSide.DEBIT, 8)

    #print('Balance sheet after second period')
    accounts.book_end_of_period()
    #accounts.print_balance_sheet()
    assert accounts['equity'].get_balance() == (AccountSide.CREDIT, 108)
Esempio n. 2
0
from abcFinance import Ledger, Account, AccountSide

""" ---------------------------------------------------------------------------
Initialize agents
"""
bank = Ledger(residual_account_name="equity")
household = Ledger(residual_account_name="equity")
bank_owner = Ledger(residual_account_name="equity")

bank.make_stock_accounts(['loans','reserves','deposits'])
household.make_stock_accounts(['money holdings','loan liabilities'])
bank_owner.make_stock_accounts(['money holdings','participations'])

bank.make_flow_accounts(['income','expenses'])
household.make_flow_accounts(['income','expenses'])
bank_owner.make_flow_accounts(['income','expenses'])

""" ---------------------------------------------------------------------------
Initialize balance sheets (outside money endowments)
"""
household.book(debit=[('money holdings',100)],credit=[('equity',100)],text='Initial endowment')
bank.book(debit=[('reserves',100)],credit=([('deposits',100)]),text='Initial endowment')
""" ---------------------------------------------------------------------------
Granting of a loan
"""
bank.book(debit=[('loans',100)],credit=[('deposits',100)],text='Loan granting')
household.book(debit=[('money holdings',100)],credit=[('loan liabilities',100)],text='Take out loan')
""" ---------------------------------------------------------------------------
Interest payment
"""
bank.book(debit=[('deposits',5)],credit=[('income',5)],text='Interest payment')
Esempio n. 3
0
def test_banking():
    bank = Ledger(residual_account_name="equity")
    household = Ledger(residual_account_name="equity")

    bank.make_stock_accounts(['reserves','claims','security holdings','deposits','wholesale refinancing'])
    household.make_stock_accounts(['money holdings','loan liabilities'])
    bank.make_flow_accounts(['interest income','interest expense'])
    household.make_flow_accounts(['income','expenses'])

    """ ---------------------------------------------------------------------------
    Initialize balance sheets (outside money endowments)
    """
    household.book(debit=[('money holdings',100)],credit=[('equity',100)],text='Initial endowment')
    bank.book(debit=[('reserves',100)],credit=([('deposits',100)]),text='Initial endowment')
    print('Bank initial balance sheet')
    bank.print_balance_sheet()
    print('Household initial balance sheet')
    household.print_balance_sheet()

    """ ---------------------------------------------------------------------------
    Granting of a loan
    """
    bank.book(debit=[('claims',10)],credit=[('deposits',10)],text='Loan')
    household.book(debit=[('money holdings',10)],credit=[('loan liabilities',10)],text='Loan')
    print('Bank balance sheet after granting a loan')
    bank.print_balance_sheet()
    print('Household balance sheet after granting a loan')
    household.print_balance_sheet()

    """ ---------------------------------------------------------------------------
    Interest payment
    """
    bank.book(debit=[('deposits',1)],credit=[('interest income',1)],text='Interest payment')
    household.book(debit=[('expenses',1)],credit=[('money holdings',1)],text='Interest payment')
    print('Bank PnL after interest payment')
    bank.print_profit_and_loss()
    print('Household PnL after interest payment')
    household.print_profit_and_loss()
    bank.book_end_of_period()
    household.book_end_of_period()

    print('Bank balance sheet after interest payment')
    bank.print_balance_sheet()
    print('Household balance sheet after interest payment')
    household.print_balance_sheet()

    """ ---------------------------------------------------------------------------
    Principal repayment
    """
    bank.book(debit=[('deposits',10)],credit=[('claims',10)],text='Principal repayment')
    household.book(debit=[('loan liabilities',10)],credit=[('money holdings',10)],text='Principal repayment')
    print('Bank balance sheet after principal repayment')
    bank.print_balance_sheet()
    print('Household balance sheet after principal repayment')
    household.print_balance_sheet()

    """ ---------------------------------------------------------------------------
    Dividend payment
    """
    bank.book(debit=[('equity',1)],credit=[('deposits',1)],text='Dividend payment')
    household.book(debit=[('money holdings',1)],credit=[('income',1)],text='Dividend payment')
    print('Bank PnL after interest payment')
    bank.print_profit_and_loss()
    print('Household PnL after interest payment')
    household.print_profit_and_loss()
    bank.book_end_of_period()
    household.book_end_of_period()
    print('Bank balance sheet after dividend payment')
    bank.print_balance_sheet()
    print('Household balance sheet after dividend payment')
    household.print_balance_sheet()
Esempio n. 4
0
    'Deferred revenue',
    'Liabilities associated with assets classified as held for sale',
    # Equity
    'Share capital'
])

corporation.make_flow_accounts([
    # Continuing operations
    'Revenue',
    'Cost of goods sold',
    'Cost of services provided',
    # = Gross profit
    'Depreciation and amortisation',
    'Administrative expenses',
    'Other income',
    'Other gains/losses',
    # = Operationg profit
    'Finance income',
    'Finance costs',
    'Net income from at-equity investments',
    # = Profit before income tax
    'Income tax expense',
    # = Profit from continuing operations
    'Net income from discontinued operations'
    # Profit for the period
])

bank.make_asset_accounts([
    # Assets
    'Cash and central bank reserves',
    'Loans and advances to banks',
    'Loans and advances to customers',