risk_propagation.bank module

Configuration of a bank

class risk_propagation.bank.Bank(name, transactions=None, n_periods=1)[source]

Bases: object

Class containing the configuration of a single bank

__init__(name, transactions=None, n_periods=1)[source]

Initializes a bank instance

Parameters:
  • name (str) – name of the bank

  • transactions (list[ndarray[tuple[int, ...], dtype[object_]]] | None) – optional dataframe with transactions to process

__str__()[source]
Return type:

str

Returns:

string representation of the bank

property accounts: set[str]

The collection of account labels of this bank

Returns:

set of account labels of this bank

property accounts_dict: Accounts

The collection of accounts of this bank

Returns:

the accounts of this bank

encrypt(public_key)[source]

Encrypts risk scores of all accounts of this bank

Parameters:

public_key (DistributedPaillier | Paillier) – the public key used in the encryption

Return type:

None

property external_accounts: set[str]

The collection of external accounts, i.e. accounts of this bank that are involved in a transaction with an account from another bank.

This set changes when the period changes.

Returns:

set of external accounts of this bank

get_imported_risk_scores(account_keys=None)[source]

Gets the encrypted risk scores of the imported accounts. If the account has no encrypted risk score no entry is added.

Parameters:

account_keys (set[str] | None) – the scores to retrieve

Return type:

dict[str, PaillierCiphertext]

Returns:

dict of encrypted risk scores

get_risk_scores(account_keys=None)[source]

Gets the accounts risk scores

Parameters:

account_keys (set[str] | None) – the scores to retrieve

Return type:

dict[str, PaillierCiphertext]

Returns:

dict of risk scores

property name: str

The name of the bank

Returns:

the name of the bank instance

process_accounts(array)[source]

Initialises the accounts belonging to this bank

Parameters:

array (ndarray[tuple[int, ...], dtype[object_]]) – an array containing the accounts with risk scores

Return type:

None

process_transactions(array)[source]

Processes the transaction array

Parameters:

array (list[ndarray[tuple[int, ...], dtype[object_]]]) – array with the following columns and types; “id_source” (unicode at most 100 char), “id_destination” (unicode at most 100 char), “bank_source” (unicode at most 100 char), “bank_destination (unicode at most 100 char)”, “amount” (int32)

Raises:

ValueError – raised when provided array does not contain the correct columns

Return type:

None

property risk_scores: dict[str, PaillierCiphertext]

A dictionary of risk scores per account of this bank. If the account has a risk score.

Returns:

a dictionary of all risk scores of this bank

set_current_period(period_z)[source]

Set the period z that should be used for the next iteration(s).

Parameters:

period_z (int) – the period that should be used.

Return type:

None

set_risk_score(account, risk_score, external=False)[source]

Sets the risk score of an account in this bank

Parameters:
  • account (str) – the name of the account

  • risk_score (PaillierCiphertext) – the new risk score

  • external (bool) – optional boolean, set to true for imported scores

Return type:

None