quantlab.core.component.config_to_dict#
- quantlab.core.component.config_to_dict(config)[source]#
Return a config dataclass as a plain dict, components as their own configs.
Every declared component field (see
component) is written as theget_config()of the component it holds: one dict, a list of them, or a dict of them keyed as the field is. Every other field is deep-copied, a nested dataclass written asdataclasses.asdict; a free-form dict is copied as data whatever keys it holds.A component held at several places under
configis written at each of them with a"shared_as"key, its first path aswalk_componentsspells it, andrebuildturns those configs back into one object. The places are found once, by the outermost call; theget_config()calls nested in it use the same marks.- Parameters:
- configdataclass instance
The config to write.
- Returns:
- dict
One entry per field, in field order.
Examples
With
factora factor over aStockDataset:>>> saved = config_to_dict(factor.config) >>> saved["dataset"]["name"] 'quantlab.dataset.stock.StockDataset'
With
backtesterwhose price dataset is also its model’s first factor’s dataset:>>> saved = config_to_dict(backtester.config) >>> saved["price_dataset"]["shared_as"] 'price_dataset' >>> saved["model"]["factors"][0]["dataset"]["shared_as"] 'price_dataset'