risk_propagation.bank module

Configuration of a bank

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

Bases: object

Class containing the configuration of a single bank

__init__(name, transactions=None)[source]

Initializes a bank instance

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

  • transactions (Optional[ndarray[Any, dtype[object_]]]) – 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 (Union[DistributedPaillier, Paillier]) – the public key used in the encryption

Return type:

None

property external_accounts: Set[str]

The collection of external accounts

Returns:

set of external accounts of this bank

get_imported_risk_scores(account_keys=None)[source]

Gets the imported accounts risk scores

Parameters:

account_keys (Optional[Set[str]]) – the scores to retrieve

Return type:

Dict[str, PaillierCiphertext]

Returns:

dict of risk scores

get_risk_scores(account_keys=None)[source]

Gets the accounts risk scores

Parameters:

account_keys (Optional[Set[str]]) – 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, delta=0.5)[source]

Initialises the accounts belonging to this bank

Parameters:
  • array (ndarray[Any, dtype[object_]]) – an array containing the accounts with risk scores

  • delta (float) – the delta to be used

Return type:

None

process_transactions(array)[source]

Processes the transaction array

Parameters:

array (ndarray[Any, 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

Returns:

a dictionary of all risk scores of this bank

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