Neural network extension for signalflow (torch/lightning).
Project description
Part of the SignalFlow ecosystem.
PyTorch/Lightning library for financial time series classification. Provides modular encoders, classification heads, and loss functions designed for trading signal validation and prediction.
Installation
pip install signalflow-nn
Requires: Python ≥ 3.12, signalflow-trading ≥ 0.5.0, PyTorch ≥ 2.2, Lightning ≥ 2.5
Quick Start
from signalflow.nn.encoder import TransformerEncoder
from signalflow.nn.head import MLPClassifierHead
from signalflow.nn.model import TemporalClassificator
from signalflow.nn.data import SignalDataModule
import lightning as pl
# Create model
model = TemporalClassificator(
encoder_type="encoder/transformer",
encoder_params={"d_model": 64, "nhead": 4, "num_layers": 2},
head_type="head/cls/mlp",
head_params={"hidden_sizes": [32]},
num_classes=3, # fall, neutral, rise
)
# Create data module
dm = SignalDataModule(
data=df,
window_size=60,
batch_size=32,
split_strategy="temporal",
)
# Train
trainer = pl.Trainer(max_epochs=50, accelerator="auto")
trainer.fit(model, dm)
Encoders (14)
| Encoder | Architecture | Best For |
|---|---|---|
LSTMEncoder |
Bidirectional LSTM | Sequential patterns |
GRUEncoder |
Gated Recurrent Unit | Faster training |
TCNEncoder |
Temporal Convolutional Network | Long-range dependencies |
TransformerEncoder |
Self-attention + positional encoding | Complex relationships |
PatchTSTEncoder |
Patch-based Transformer | Multivariate time series |
TSMixerEncoder |
All-MLP (Google 2023) | Efficient mixing |
InceptionTimeEncoder |
Multi-scale convolutions | Multi-resolution features |
ResNet1dEncoder |
1D ResNet | Deep representations |
XceptionTimeEncoder |
Depthwise separable conv | Efficient computation |
Conv1dEncoder |
1D CNN | Local patterns |
XCMEncoder |
Cross-Channel Mixing | Channel interactions |
gMLPEncoder |
Gating MLP | Spatial/channel gating |
OmniScaleCNNEncoder |
Multi-scale CNN | Scale-invariant features |
ConvTranEncoder |
Conv + Transformer hybrid | Combined strengths |
Classification Heads (7)
| Head | Use Case |
|---|---|
LinearClassifierHead |
Simple baseline |
MLPClassifierHead |
Non-linear classification |
ResidualClassifierHead |
Deep with skip connections |
AttentionClassifierHead |
Attention-weighted pooling |
OrdinalRegressionHead |
Ordered classes (fall < neutral < rise) |
DistributionHead |
Probability distributions |
ClassificationWithConfidenceHead |
Class + confidence score |
Loss Functions (4)
| Loss | Purpose |
|---|---|
FocalLoss |
Class imbalance — down-weights easy examples |
DiceLoss |
Imbalanced multi-class |
LDAMLoss |
Large margin for rare classes |
SymmetricCrossEntropyLoss |
Noisy labels |
SignalFlow Integration
Use as a validator in the SignalFlow pipeline:
import signalflow as sf
result = (
sf.Backtest("nn_validated")
.data(raw=raw)
.detector("sma_cross", fast_period=20, slow_period=50)
.validator("nn/transformer", d_model=64, nhead=4)
.entry(size_pct=0.1)
.exit(tp=0.03, sl=0.015)
.run()
)
Package Structure
| Module | Description |
|---|---|
signalflow.nn.data |
Data loading, windowing, temporal splitting |
signalflow.nn.encoder |
14 feature encoding architectures |
signalflow.nn.head |
7 output head architectures |
signalflow.nn.layer |
Custom neural network layers |
signalflow.nn.loss |
4 specialized loss functions |
signalflow.nn.model |
TemporalClassificator — complete model |
signalflow.nn.validator |
SignalFlow validator integration |
License: MIT · Part of SignalFlow
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file signalflow_nn-0.6.0.tar.gz.
File metadata
- Download URL: signalflow_nn-0.6.0.tar.gz
- Upload date:
- Size: 53.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
045624d3f22334c8430a6a0bfe9fc15a67202007673e06cc68867af5e63a50e8
|
|
| MD5 |
fb5339e17bdb4ef7508b676894bf7e25
|
|
| BLAKE2b-256 |
66e4aeee16f936a14f6878e2139147d5d8da5b63629f48976ac91fbc09b64d9e
|
File details
Details for the file signalflow_nn-0.6.0-py3-none-any.whl.
File metadata
- Download URL: signalflow_nn-0.6.0-py3-none-any.whl
- Upload date:
- Size: 71.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e4ec21795f6d61e27eb5de954cc76c42431ff75d05c89a882ed4e7c239c0243
|
|
| MD5 |
1c2cc25052e83696acfc828f0aa7adf0
|
|
| BLAKE2b-256 |
4e0b8ff3632cc9f6b393717495179512cdb4e1a207a05788f2f7956a8d564c65
|