Models API

The models module contains neural network architectures and loss functions.

GRUBetaModel

DualPathwayGRU

CAPMLoss

TFEnvironment

Architecture Overview

The GRU Dynamic Beta model uses a dual-pathway architecture:

Market Features ──→ [GRU (128)] ──→ [Dense (1)] ──→ Beta(t)
                                                     ↓
                           R_stock = α + β × R_market
                                                     ↑
Stock Features ──→ [GRU (128)] ──→ [Dense (1)] ──→ Alpha(t)

Loss Function

The composite loss combines four objectives:

\[L = L_{accuracy} + \lambda_\beta \cdot L_{\beta\_stability} + \lambda_\alpha \cdot L_{sparsity} + \lambda_{\alpha\_smooth} \cdot L_{\alpha\_stability}\]

Where:

  • \(L_{accuracy}\) = Huber loss on return predictions

  • \(L_{\beta\_stability}\) = L2 penalty on \(\beta_{t} - \beta_{t-1}\)

  • \(L_{sparsity}\) = L1 penalty on alpha values

  • \(L_{\alpha\_stability}\) = L2 penalty on \(\alpha_{t} - \alpha_{t-1}\)

Example: Custom Model

from grubeta.models import GRUBetaModel
from grubeta import DynamicBetaConfig

config = DynamicBetaConfig(
    gru_units=64,
    dropout_rate=0.3
)

model_builder = GRUBetaModel(config)
keras_model = model_builder.build(
    n_market_features=30,
    n_stock_features=20
)

keras_model.summary()