Skip to content

StrataNetTrainer

StrataNetTrainer

Gradient descent training loop for StrataNet.

from strata import StrataNetTrainer

trainer = StrataNetTrainer(
    asset   = "AAPL",      # ticker — used for GUARD profile in label generation
    cfg     = None,        # StrataNetConfig (auto-built if None)
    model   = None,        # existing StrataNet for fine-tuning (optional)
    lr      = 1e-3,        # default learning rate
    device  = "cpu",       # "cpu" or "cuda"
    verbose = True,
)

train(dataset, cfg, epochs, batch_size, lr, weight_decay) → StrataNet

model = trainer.train(
    dataset      = dataset,   # StrataNetDataset
    cfg          = None,      # overrides trainer.cfg if provided
    epochs       = 30,
    batch_size   = 64,
    lr           = 1e-3,
    weight_decay = 1e-4,
)

Training objective:

loss = CE(action_logits, action_labels)        # primary
     + 0.3 × CE(regime_logits, regime_labels)  # auxiliary
     + 0.1 × confidence_penalty                # high conf on correct preds

Fine-tuning

# Load pretrained, fine-tune on new data
from huggingface_hub import hf_hub_download
from strata import StrataNet, StrataNetTrainer, StrataNetDataset

path    = hf_hub_download(repo_id="emylton/strata-net", filename="aapl_net.pt")
base    = StrataNet.load(path)
dataset = StrataNetDataset.from_candles(my_candles, seq_len=30, asset="AAPL")

trainer = StrataNetTrainer(model=base, lr=1e-4)   # lower LR for fine-tuning
model   = trainer.train(dataset, epochs=10)
model.save("aapl_finetuned.pt")

StrataTrainer (Classic API)

Walk-forward coordinate optimizer for StrataModel.

from strata import StrataTrainer

trainer = StrataTrainer(asset="AAPL", verbose=True)

# Prepare sliding windows
windows = StrataTrainer.prepare_windows(candles, window_size=31)

# Train — coordinate search over 17 core parameters
model = trainer.train(windows, n_trials=100)