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 banktransactions (
Optional
[List
[ndarray
[Any
,dtype
[object_
]]]]) – optional dataframe with transactions to process
- 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, 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 (
Optional
[Set
[str
]]) – 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 (
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)[source]¶
Initialises the accounts belonging to this bank
- Parameters:
array (
ndarray
[Any
,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
[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. If the account has a risk score.
- Returns:
a dictionary of all risk scores of this bank