pretrain_pooled¶
Defined in fynance.models.objective
- pretrain_pooled(model, Xs, ys, **fit_kw)[source]
Pretrain one
ObjectiveModelon a pool of aligned assets.The
(X_i, y_i)pairs are pooled into a single training run so the net learns a signal shared across assets (transfer learning across a panel). The pooling is segment-safe: each asset’s series is kept as one contiguous chunk and mini-batches are drawn within a chunk, so no mini-batch ever crosses an asset join — the turnover carry (cost) and the temporal order that the single-assetfitrelies on stay intact per asset. Concretely this extendsfit’s contiguous chunking with segment boundaries: all segments’ chunks are pooled and (whenshuffle) globally shuffled for SGD mixing, but every chunk stays inside its own segment.Typical use: pretrain a shared net here, then adapt per asset with
clone+finetune.- Parameters:
- modelObjectiveModel
The model to train in place (its hyper-parameters and seed are used).
- Xssequence of array-like
Per-asset feature matrices, each
(T_i, F)(or a(T_i, N, M)panel); all must share the feature dimension.- yssequence of array-like
Per-asset realized returns aligned with
Xs((T_i,)or(T_i, N)); must have the same length asXs.- **fit_kw
Per-run overrides of the training hyper-parameters
epochs,lr,batch_size,shuffle,costandseed(restored afterwards).
- Returns:
- ObjectiveModel
The same
model, now pretrained on the pool.
- Raises:
- ValueError
If
Xsandyshave different lengths, or the pool is empty.
Examples
>>> import numpy as np >>> from fynance.models import ObjectiveModel, pretrain_pooled >>> rng = np.random.default_rng(0) >>> Xs = [rng.standard_normal((16, 2)).astype("float32") for _ in range(3)] >>> ys = [(X[:, 0] * 0.01).astype("float32") for X in Xs] >>> m = ObjectiveModel(layers=(4,), epochs=3, seed=0) >>> _ = pretrain_pooled(m, Xs, ys) # one net trained on all three series >>> m.predict(Xs[0]).shape (16, 1)