quantlab.core.component.walk_components#

quantlab.core.component.walk_components(root, path='')[source]#

Yield every component under root with its path, depth first, root excluded.

The tree follows the declared component fields (see component) of each component’s config. A path joins the field names with ., and an item of a many-field adds its index or key, so the price dataset of a backtester is "price_dataset" and the dataset of its model’s first factor "model.factors.0.dataset". A component held in several places is yielded at each of them.

Parameters:
rootComponent

The component to walk.

pathstr, optional

The path of root itself, prefixed to every path yielded.

Yields:
tuple[str, Component]

A path and the component found there.

Examples

With label a Forward label over a factor over a dataset:

>>> [path for path, _ in walk_components(label)]
['factor', 'factor.dataset']