quantlab.core.component.rebuild#

quantlab.core.component.rebuild(config, run_dir=None, expected=None)[source]#

Rebuild the component a saved config names, and everything nested in it.

The class named by config["name"] is imported, checked to declare a config class, and asked to rebuild itself with from_config. config is not modified. Within one call, every config carrying the same "shared_as" mark (written by config_to_dict for a component held at several places) is built once and returned as that one object wherever it appears.

Parameters:
configMapping

A dict get_config() returned, for example read back from JSON.

run_dirstr or os.PathLike, optional

The run directory the config was read from; a dataset recorded relative to it (FrameDataset) is resolved against it at any depth.

expectedtype, optional

The class the rebuilt component must be an instance of, such as BaseBacktester. Checked on the named class before anything is rebuilt.

Returns:
object

The rebuilt component.

Raises:
TypeError

If the named class declares no config class, or is not a subclass of expected.

ValueError

If the config, or a config nested in it, holds a key its config class does not have, or a dataset relative to a run directory is found without run_dir.

Examples

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

>>> rebuild(label.get_config()) == label
True
>>> rebuild(label.get_config(), expected=Forward) == label
True