# vib28/layatrainer architecture

> Architecture diagram of the GitHub repository vib28/layatrainer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vib28/layatrainer
- Repository: https://github.com/vib28/layatrainer

## Overview

Laya Trainer is a Stage A supervised stock-movement prediction system. Its main workflow loads local market bars, prepares features and forward-looking targets, builds chronological datasets, trains a multi-task model, and evaluates predictions and simulated trading performance. The README documents the pipeline; sampled source confirms key model, training, evaluation, simulator, ledger, and adapter responsibilities. Some orchestration and subsystem wiring is based on the README because main.py excerpts are incomplete.

Main entry points: [`main.py`](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/main.py) (Pipeline runner), [`evaluate.py`](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/evaluate.py) (Metrics and benchmarks), [`data_loader.py`](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/data_loader.py) (Load and align bars), [`train.py`](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/train.py) (Training loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Market data prep"]
  node_loader["Load and align bars<br/>[data_loader.py]"]
  node_features["Market features<br/>[features.py]"]
  node_labels["Forward labels<br/>[labels.py]"]
  node_normalize["Feature scaling<br/>[normalize.py]"]
  node_dataset["Chronological splits<br/>[dataset.py]"]
end

subgraph group_learning["Supervised learning"]
  node_model["Prediction network<br/>[model.py]"]
  node_trainer["Training loop<br/>[train.py]"]
end

subgraph group_assessment["Evaluation and simulation"]
  node_evaluator["Metrics and benchmarks<br/>[evaluate.py]"]
  node_simulator["Trade replay<br/>[simulator.py]"]
  node_ledger[("Portfolio accounting<br/>[ledger.py]")]
  node_results["Evaluation reports<br/>[evaluate.py]"]
end

subgraph group_extension["Model extension"]
  node_laya["Laya hybrid adapter<br/>[laya_adapter.py]"]
end

node_user(("Researcher"))
node_localdata["Local market CSVs"]
node_main["Pipeline runner<br/>[main.py]"]
node_config["Experiment configuration<br/>[config.py]"]

node_user -->|"runs pipeline"| node_main
node_localdata -->|"loads bars"| node_loader
node_main -->|"loads data"| node_loader
node_main -->|"builds features"| node_features
node_main -->|"builds targets"| node_labels
node_main -->|"scales features"| node_normalize
node_main -->|"creates splits"| node_dataset
node_loader -->|"provides bars"| node_features
node_loader -->|"provides bars"| node_labels
node_main -->|"trains model"| node_trainer
node_dataset -->|"provides batches"| node_trainer
node_trainer -->|"optimizes"| node_model
node_main -->|"evaluates model"| node_evaluator
node_dataset -->|"provides test batches"| node_evaluator
node_evaluator -->|"simulates trades"| node_simulator
node_simulator -->|"updates portfolio"| node_ledger
node_evaluator -->|"reports metrics"| node_results
node_main -->|"reads settings"| node_config
node_trainer -->|"reads settings"| node_config
node_evaluator -->|"reads settings"| node_config
node_laya -.->|"alternative architecture"| node_model

click node_main "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/main.py"
click node_loader "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/data_loader.py"
click node_features "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/features.py"
click node_labels "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/labels.py"
click node_normalize "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/normalize.py"
click node_dataset "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/dataset.py"
click node_model "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/model.py"
click node_trainer "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/train.py"
click node_evaluator "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/evaluate.py"
click node_simulator "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/simulator.py"
click node_ledger "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/ledger.py"
click node_results "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/evaluate.py"
click node_laya "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/laya_adapter.py"
click node_config "https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_features,node_labels,node_normalize,node_dataset toneBlue
class node_model,node_trainer toneAmber
class node_evaluator,node_simulator,node_ledger,node_results toneMint
class node_laya toneRose
class node_user,node_localdata toneIndigo
class node_main,node_config toneTeal
```

## Components

### Market data prep

- [Load and align bars](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/data_loader.py): `data_loader.py`
- [Market features](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/features.py): `features.py`
- [Forward labels](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/labels.py): `labels.py`
- [Feature scaling](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/normalize.py): `normalize.py`
- [Chronological splits](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/dataset.py): `dataset.py`

### Supervised learning

- [Prediction network](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/model.py): `model.py`
- [Training loop](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/train.py): `train.py`

### Evaluation and simulation

- [Metrics and benchmarks](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/evaluate.py): `evaluate.py`
- [Trade replay](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/simulator.py): `simulator.py`
- [Portfolio accounting](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/ledger.py): `ledger.py`
- [Evaluation reports](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/evaluate.py): `evaluate.py`

### Model extension

- [Laya hybrid adapter](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/laya_adapter.py): `laya_adapter.py`

### Other components

- **Researcher**
- **Local market CSVs**
- [Pipeline runner](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/main.py): `main.py`
- [Experiment configuration](https://github.com/vib28/layatrainer/blob/feature/configurable-benchmarks/config.py): `config.py`

## Connections

- Researcher → Pipeline runner: runs pipeline
- Local market CSVs → Load and align bars: loads bars
- Pipeline runner → Load and align bars: loads data
- Pipeline runner → Market features: builds features
- Pipeline runner → Forward labels: builds targets
- Pipeline runner → Feature scaling: scales features
- Pipeline runner → Chronological splits: creates splits
- Load and align bars → Market features: provides bars
- Load and align bars → Forward labels: provides bars
- Pipeline runner → Training loop: trains model
- Chronological splits → Training loop: provides batches
- Training loop → Prediction network: optimizes
- Pipeline runner → Metrics and benchmarks: evaluates model
- Chronological splits → Metrics and benchmarks: provides test batches
- Metrics and benchmarks → Trade replay: simulates trades
- Trade replay → Portfolio accounting: updates portfolio
- Metrics and benchmarks → Evaluation reports: reports metrics
- Pipeline runner → Experiment configuration: reads settings
- Training loop → Experiment configuration: reads settings
- Metrics and benchmarks → Experiment configuration: reads settings
- Laya hybrid adapter → Prediction network: alternative architecture
