Welcome to abcFinance’s documentation!

accounting module

abcFinance is an implementation of an double entry book keeping system

Initialize the accounting system with, the name of the residual_account:

accounts = AccountingSystem('equity')

Create stock and flow account:

accounts.make_stock_account([‘cash’, ‘claims’]) accounts.make_flow_account([‘expenditure’])

In order to book give a list of credit and debit tuples. Each tuple should be an account and a value:

accounts.book(
    debit=[('cash', 50), ('claims', 50)],
    credit=[('equity', 100)])

get balance gives you the balance of an account:

assert accounts[‘cash’].get_balance() == (s.DEBIT, 50)

Balance sheet

accounts.book(debit=[(‘expenditure’, 20)], credit=[(‘cash’, 20)])

assert accounts.get_total_assets() == 80, accounts.get_total_assets()

accounts.print_profit_and_loss() print(‘–’) accounts.make_end_of_period()

accounts.print_profit_and_loss()

accounts.print_balance_sheet()

assert accounts[‘equity’].get_balance() == (s.CREDIT, 80)

class accounting.Account[source]

Bases: object

get_balance()[source]
print_balance()[source]
class accounting.AccountingSystem(residual_account_name='equity')[source]

Bases: object

The main class to be initialized

book(debit, credit, text='')[source]

Book a transaction.

Arguments:

debit, list of tuples (‘account’, amount)

credit, list of tuples (‘account’, amount)

text, for booking history

Example:

accounts.book(debit=[('inventory',20)], credit=[('cash',20)], text="Purchase of equipment")
get_total_assets()[source]

Return total assets.

make_end_of_period()[source]

Close flow accounts and credit/debit residual (equity) account

make_flow_account(names)[source]

Create flow accounts.

Args:
names, list of names for the accounts
make_stock_account(names)[source]

Create stock accounts.

Args:
names, list of names for the accounts
print_balance_sheet()[source]

Print a balance sheets

print_profit_and_loss()[source]

Print profit and loss statement

class accounting.s[source]

Bases: enum.Enum

An enumeration.

CREDIT = 1
DEBIT = 0

contractAPI module

abcFinance specifies a contract API. This allows the user to use the full python language to specify contracts.

Both / all contract parties get a copy of the contract.

class contractAPI.Action(action, more_info=None)[source]

Bases: object

An action has to properties. The action to be executed and further information. This could be for example whether the action is obligatory or not.

Example:

Action(('pay', 50, 'UBS'), 'compulsory')

The action property and more_info, can have any content the tuple (‘pay’, 50, ‘UBV’) is just and example.

action = None

self.action, action to be executed,

more_info = None

self.more_info, further information

class contractAPI.Contract(issuing_party, *_, **__)[source]

Bases: object

A contract is a tree or sequence of Action`s. A contract must implement :method:`get_action, which gives the next action given the current time and relevant state. Further it must implement :method:`action_executed`, which is lets the contract know that an action has been is executed.

Optionally is_terminanted should return whether the contract is terminated.

In order to use a contract with a book keeping system :method:`valuation` needs to return the valuation

action_executed(obligation)[source]

Let the contract know that a particular obligation has been executed. This is used by the agent that execute the obligation on his copy and by the receiving agent on his copy of the contract.

Example:

self.num_excecuted_payments += 1
get_actions(party, time, *_, **__)[source]

Returns a list of actions that have to or could be executed now arguments are the current time and any state informations that are necessary to decide which actions have to could be taken.

Example:

if self.issuing_party == party:
    if self.num_excecuted_payments < self.number_of_payments_required:
        return [Action(('pay', self.amount), 'at_least_3_times')]
else:
    return []
is_terminanted()[source]

Whether the contract is terminated.

Example:

if.num_excecuted_payments >= self.number_of_payments_required:
    return True
else:
    return False
last_valuation()[source]
sign(party)[source]

Signs the contract and sets the self.counter_party property

valuation(party, time, *_, **__)[source]

returns a valuation of the contract. Arguments:

party, the party for whom the valuation is made time, current time other state variables necessary for the valuation

Indices and tables