Neural network models¶
BaseNeuralNet is the root of all PyTorch models in
this package. It wraps torch.nn.Module with higher-level training, prediction
and serialization helpers — set_optimizer,
train_on,
predict,
set_data,
save_model /
load_model — so that subclasses only
need to implement forward.
MultiLayerPerceptron is the feed-forward specialization:
a configurable stack of Linear → Dropout → Activation blocks, best suited for
tabular or sliding-window features (technical indicators, volatility signals). For
time-ordered sequences, prefer the recurrent architectures described in
Recurrent neural networks.
Objective-aligned training
ObjectiveModel trains a network directly on a
differentiable financial objective — e.g. SharpeLoss
— rather than MSE against a target. The net outputs positions and the loss is
computed on positions * returns: fit(X, y) reads y as the realized
returns, and predict(X) returns positions in [-1, 1]. It is a
SignalModel, so it drops straight into a Strategy
with an identity signal:
from fynance.models import ObjectiveModel, SharpeLoss
from fynance.strategy import Strategy
model = ObjectiveModel(layers=(16, 8), loss=SharpeLoss(), epochs=60, seed=0)
strat = Strategy(model=model, signal=lambda positions: positions)
Feed it through the research harness via the X path with y = returns; see
Research workflow.
Inheritance
BaseNeuralNet → MultiLayerPerceptron
BaseNeuralNet → _RecurrentBase → RecurrentNeuralNetwork / GRUCell
/ LSTMCell (see Recurrent neural networks)
Classes
|
Base object for neural network model with PyTorch. |
|
Neural network with MultiLayer Perceptron architecture. |
|
Train a net to maximize a differentiable financial objective. |