Skip to content

StrataNet

StrataNet(cfg)

PyTorch neural network for market trading action classification.

Args:

Param Type Description
cfg StrataNetConfig Hyperparameter configuration

Methods

forward(x) → StrataNetOutput

x      = torch.randn(batch, seq_len, 5)   # (B, T, 5) OHLCV
output = model(x)

output.action_logits   # (B, 3)   LONG / SHORT / HOLD
output.confidence      # (B, 1)   [0, 1]
output.hidden          # (B, 4)   [bias, momentum, trap_risk, uncertainty]
output.regime_logits   # (B, 4)   TRENDING / RANGING / TRANSITIONING / CHOPPY

predict_action(x) → dict

x      = torch.tensor(_normalise_window(candles[-30:]), dtype=torch.float32)
result = model.predict_action(x)
# {
#   "action":     "LONG",
#   "confidence": 0.71,
#   "regime":     "TRENDING",
#   "state": {"bias": 0.82, "momentum": 0.45, "trap_risk": 0.18, "uncertainty": 0.31}
# }

save(path) / StrataNet.load(path)

model.save("aapl_net.pt")
model = StrataNet.load("aapl_net.pt")

summary() → str

print(model.summary())
# StrataNet v1.0
#   asset       : AAPL
#   seq_len     : 30
#   hidden_dim  : 4  [bias, momentum, trap_risk, uncertainty]
#   parameters  : 5,020

StrataNetConfig

from strata import StrataNetConfig

cfg = StrataNetConfig(
    asset         = "AAPL",   # ticker label (metadata only)
    seq_len       = 30,       # input sequence length (bars)
    embed_dim     = 32,       # OHLCV → embedding size
    core_expand   = 16,       # recurrent cell intermediate size
    head_dim      = 16,       # head hidden size
    dropout       = 0.1,      # dropout rate
    label_smoothing = 0.05,   # training label smoothing
)

StrataNetDataset

from strata import StrataNetDataset

dataset = StrataNetDataset.from_candles(
    candles  = candles,    # list of OHLCV dicts
    seq_len  = 30,
    asset    = "AAPL",     # optional: GUARD asset profile for label gen
    verbose  = True,
)

print(dataset.action_counts())
# {"LONG": 1200, "SHORT": 380, "HOLD": 1400}

print(dataset.regime_counts())
# {"TRENDING": 1850, "RANGING": 980, "TRANSITIONING": 150, "CHOPPY": 0}

Index Maps

from strata import ACTION_IDX, IDX_ACTION, REGIME_IDX, IDX_REGIME

ACTION_IDX  # {"LONG": 0, "SHORT": 1, "HOLD": 2}
IDX_ACTION  # {0: "LONG", 1: "SHORT", 2: "HOLD"}

REGIME_IDX  # {"TRENDING": 0, "RANGING": 1, "TRANSITIONING": 2, "CHOPPY": 3}
IDX_REGIME  # {0: "TRENDING", 1: "RANGING", 2: "TRANSITIONING", 3: "CHOPPY"}