quantlab.model.config.ModelConfig#
- class quantlab.model.config.ModelConfig(factors, labels, model_save_dir, factor_data_strategy, label_data_strategy, start_date=None, end_date=None, hyperparameters=<factory>, val_size=0.2, metric_splits=('train', 'val', 'test'), random_seed=42, train_start=None, train_end=None, test_start=None, test_end=None, tracker=<factory>, name=None)[source]#
Bases:
FrozenConfigConfig of every model head, torch or library.
It holds only what both variants read. Everything a variant or a head reads for training goes in
hyperparameters, one flat dict. The base classes and the shipped heads read these reserved keys from it:epochsEpoch cap of a
TorchModel; default 100, a positive integer.lrLearning rate of the default
TorchModel._init_optim; default1e-3.early_stopping,early_stopping_patienceThe library’s native early stopping in the shipped library heads; default off and 5 rounds (or the library’s own unit).
training_targetA
LibraryModel’s training target:"cs_rank"or"cs_zscore", applied per bar; unset trains on the raw label. Set,label_scalesis"standardized"; metrics still read the raw label.
batch_size,num_workers,pin_memory,prefetch,panel_device,panel_dtypeReserved for the torch data loader and training panel.
A
LibraryModel’s_init_modelreceives the dict without the library keys above. ATorchModel’s receives the whole dict, reserved keys included, so a torch head never splats it into a network; it reads its own keys by name, or drops the reserved ones withBaseModel.head_hyperparameters.train_start,train_end,test_startandtest_endbound the training and test windows; rolling cross-validation overwrites them fold by fold.start_dateandend_datebound all the data the model collects; they are passed to every factor and label per request.Examples
With
factorsandlabelslists of factor objects built earlier:>>> cfg = ModelConfig( ... factors=factors, ... labels=labels, ... model_save_dir="/data/models/xgb", ... factor_data_strategy="read", ... label_data_strategy="read", ... train_start="2018-01-01", ... train_end="2022-12-31", ... test_start="2023-01-01", ... test_end="2023-12-31", ... hyperparameters={"max_depth": 6, "early_stopping": True}, ... ) >>> cfg.val_size, cfg.hyperparameters["early_stopping"] (0.2, True)
- end_date = None#
Last date of data to collect, inclusive.
Nonemeans no upper bound.
- factor_data_strategy#
"read"loads factor values from their stores;"cal"computes them first.
- factors#
The factors whose values form the model’s input features.
- hyperparameters#
Training and architecture settings, one flat dict; see the reserved keys above.
- label_data_strategy#
"read"loads label values from their stores;"cal"computes them first.
- labels#
The factors (labels) whose values form the prediction targets.
- metric_splits = ('train', 'val', 'test')#
The segments a trained unit is scored on, any of
"train","val"and"test", in that order: their metrics and losses, and the bars its evaluation predicts.("test",)scores only the test segment and predicts only its bars, which a walk-forward training repeats per fold.
- model_save_dir#
Root directory checkpoints and their
config.jsonare written under.
- name = None#
Dotted import path of the model class; filled by the config setter.
- random_seed = 42#
Seed applied to Python, numpy and, for torch heads, torch before training.
- start_date = None#
First date of data to collect, inclusive.
Nonemeans no lower bound.
- test_end = None#
Last date of the test window, inclusive.
- test_start = None#
First date of the test window, inclusive.
- tracker#
Where training runs are tracked (ADR 0015); the default
NullTrackersends nothing anywhere.
- train_end = None#
Last date of the training window, inclusive.
- train_start = None#
First date of the training window, inclusive.
- val_size = 0.2#
Fraction of the training window held out, at its end, for validation.