bank_book_model
Qt item model for bank book tree views (Banking Book / Trading Book).
Classes:
-
BankBookModel–Tree model for a single bank book (banking or trading).
BankBookModel
BankBookModel(*, include_equity: bool = True)
Bases: QAbstractItemModel
Tree model for a single bank book (banking or trading).
Structure
Assets (bold) ├─ Held-to-Maturity (bold) │ ├─ Bond A │ └─ Bond B └─ Loans & Mortgages (bold) └─ Loan C Liabilities (bold) └─ Deposits Equity (bold) └─ Common Equity
Parameters:
-
(include_equitybool, default:True) –Whether to include the Equity node (False for trading book).
Methods:
-
add_instrument–Add an instrument row under a class group node.
-
clear_instruments–Remove all instrument children from all top-level nodes.
-
closed_instrument_ids–Return instrument_ids of all rows currently marked as closed.
-
columnCount–Return number of columns.
-
data–Return data for the given index and role.
-
find_instrument_by_name–Find an instrument row by name (used for Cash lookup).
-
find_or_create_class_group–Find an existing class group under a side node, or create one.
-
flags–Return item flags for the given index.
-
get_instrument_id–Get the instrument_id for a given index, or None if it's a group/header.
-
headerData–Return header data for the given section and orientation.
-
index–Return a model index for the given row and column.
-
index_for_instrument_id–Return the QModelIndex (column 0) for an instrument row, or invalid if not found.
-
mark_instrument_closed–Set or clear the closed flag on an instrument row. Returns True if found and changed.
-
parent–Return the parent index of the given index.
-
remove_instrument–Remove an instrument row by its instrument_id. Returns True if found.
-
rowCount–Return number of rows under parent.
-
update_instrument_value–Update the value column for an instrument. Returns True if found.
Attributes:
-
assets(_Row) –The Assets top-level node.
-
equity(_Row | None) –The Equity top-level node, or None for trading book.
-
liabilities(_Row) –The Liabilities top-level node.
assets
property
assets: _Row
The Assets top-level node.
equity
property
equity: _Row | None
The Equity top-level node, or None for trading book.
liabilities
property
liabilities: _Row
The Liabilities top-level node.
add_instrument
add_instrument(
group: _Row,
name: str,
value: float | None,
instrument_id: str,
) -> None
Add an instrument row under a class group node.
clear_instruments
clear_instruments() -> None
Remove all instrument children from all top-level nodes.
closed_instrument_ids
closed_instrument_ids() -> list[str]
Return instrument_ids of all rows currently marked as closed.
columnCount
columnCount(parent: QModelIndex = _INVALID) -> int
Return number of columns.
data
data(index: QModelIndex, role: int = DisplayRole) -> Any
Return data for the given index and role.
find_instrument_by_name
find_instrument_by_name(name: str) -> _Row | None
Find an instrument row by name (used for Cash lookup).
find_or_create_class_group
find_or_create_class_group(
side_node: _Row, class_label: str
) -> _Row
Find an existing class group under a side node, or create one.
flags
flags(index: QModelIndex = _INVALID) -> ItemFlag
Return item flags for the given index.
get_instrument_id
get_instrument_id(index: QModelIndex) -> str | None
Get the instrument_id for a given index, or None if it's a group/header.
headerData
headerData(
section: int,
orientation: Orientation,
role: int = DisplayRole,
) -> Any
Return header data for the given section and orientation.
index
index(
row: int, column: int, parent: QModelIndex = _INVALID
) -> QModelIndex
Return a model index for the given row and column.
index_for_instrument_id
index_for_instrument_id(instrument_id: str) -> QModelIndex
Return the QModelIndex (column 0) for an instrument row, or invalid if not found.
mark_instrument_closed
mark_instrument_closed(
instrument_id: str, closed: bool = True
) -> bool
Set or clear the closed flag on an instrument row. Returns True if found and changed.
When transitioning to closed, the value column is cleared to None so
the tree shows a blank cell instead of the stale final valuation.
parent
parent(index: QModelIndex = _INVALID) -> QModelIndex
Return the parent index of the given index.
remove_instrument
remove_instrument(instrument_id: str) -> bool
Remove an instrument row by its instrument_id. Returns True if found.
rowCount
rowCount(parent: QModelIndex = _INVALID) -> int
Return number of rows under parent.
update_instrument_value
update_instrument_value(
instrument_id: str, value: float
) -> bool
Update the value column for an instrument. Returns True if found.