# nitro56565/ai-quant-lab architecture

> Architecture diagram of the GitHub repository nitro56565/ai-quant-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nitro56565/ai-quant-lab
- Repository: https://github.com/nitro56565/ai-quant-lab

## Overview

#### Purpose and Entry Points
`ai-quant-lab` is a Python quantitative-trading/backtesting codebase. It separates market-data acquisition/preparation from strategy evaluation, indicator calculation, position sizing, and simulated execution.

Primary entry points are:
- `app.py` — top-level application orchestration.
- `market_data_pipeline/main.py` — market-data ingestion and transformation workflow.
- `simulator_dashboard.html` — browser-facing visualization artifact for simulator output.

#### Market Data Acquisition Boundary
The market-data pipeline integrates with TickVault through `market_data_pipeline/downloader/tickvault_client.py`. Download orchestration is split by year in `market_data_pipeline/downloader/download_year.py`, with download cleanup in `market_data_pipeline/downloader/cleanup.py`.

Pipeline-specific external-service settings are represented by `market_data_pipeline/config/tickvault_config.json`. TickVault is an infrastructure boundary: downstream strategy and simulation code should consume prepared local data rather than depend directly on remote retrieval.

#### Data Preparation Pipeline
`market_data_pipeline/main.py` coordinates a staged transformation flow:
1. Read source market files via `market_data_pipeline/parser/reader.py`.
2. Validate records using `market_data_pipeline/validator/validator.py`.
3. Clean normalized data in `market_data_pipeline/cleaner/cleaner.py`.
4. Resample data into target intervals through `market_data_pipeline/converters/resampler.py`.
5. Persist analytical datasets as Parquet using `market_data_pipeline/converters/parquet_writer.py`.

This establishes Parquet as the likely handoff/storage format between acquisition/preparation and quantitative consumers.

#### Data Access Layer
`data_loader/loader.py` provides the application-facing data-loading boundary, while `data_loader/request.py` represents requested data parameters and `data_loader/exceptions.py` defines loader-specific failure handling.

This package should insulate indicators, strategies, and simulation from raw files, Parquet implementation details, and pipeline-specific validation/cleanup logic.

#### Indicators and Strategy Evaluation
`indicator_engine/engine.py` calculates and attaches technical-analysis inputs using implementations in `indicator_engine/indicators.py`.

`strategy_engine/engine.py` evaluates strategies against market data and indicator-enriched inputs. The common strategy contract is centered on `strategy_engine/base.py`; concrete implementations include:
- `strategy_engine/adaptive_trend.py`
- `strategy_engine/mean_reversion.py`
- `strategy_engine/volatility_breakout.py`

Additional directional/session-style strategies reside in `strategy_engine/london_momentum.py` and `strategy_engine/pullback_continuation.py`. This is the primary signal-generation boundary: strategies should produce decisions/signals without owning execution mechanics.

#### Risk and Execution Simulation
`position_sizer/sizer.py` converts strategy opportunities into position sizes, forming the risk/allocation stage between signals and orders.

`execution_simulator/simulator.py` simulates execution of sized strategy decisions against market data. It is the boundary for fills, trading outcomes, and portfolio/execution accounting; strategy modules should not embed those concerns.

#### Primary Control Flow
The intended end-to-end flow is:

`TickVault/downloads → parse → validate → clean → resample → Parquet → data loader → indicators → strategy signals → position sizing → execution simulation → dashboard/application output`

Key separations are:
- Remote acquisition vs. local prepared datasets.
- Data access vs. analytical computation.
- Signal generation vs. risk sizing.
- Risk sizing vs. execution and outcome simulation.

Main entry points: [`app.py`](https://github.com/nitro56565/ai-quant-lab/blob/main/app.py) (Application), [`market_data_pipeline/main.py`](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/main.py) (Pipeline workflow), [`market_data_pipeline/downloader/download_year.py`](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/download_year.py) (Yearly downloads), [`data_loader/loader.py`](https://github.com/nitro56565/ai-quant-lab/blob/main/data_loader/loader.py) (Data loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_market_pipeline["Market Data Pipeline"]
  node_tickvault{{"TickVault<br/>external market data"}}
  node_download_year["Yearly downloads<br/>download orchestration<br/>[download_year.py]"]
  node_tickvault_client["TickVault client<br/>service client"]
  node_download_cleanup["Download cleanup<br/>cleanup stage<br/>[cleanup.py]"]
  node_pipeline_main["Pipeline workflow<br/>pipeline orchestrator<br/>[main.py]"]
  node_reader["Source reader<br/>parser<br/>[reader.py]"]
  node_validator["Record validation<br/>validation stage<br/>[validator.py]"]
  node_cleaner["Data cleaning<br/>cleaning stage<br/>[cleaner.py]"]
  node_resampler["Interval resampling<br/>conversion stage<br/>[resampler.py]"]
  node_parquet_writer["Parquet writer<br/>dataset persistence<br/>[parquet_writer.py]"]
end

subgraph group_quant_stack["Quantitative Stack"]
  node_data_loader["Data loader<br/>data access boundary<br/>[loader.py]"]
  node_indicator_engine["Indicator engine<br/>indicator calculation<br/>[engine.py]"]
  node_strategy_engine["Strategy engine<br/>signal evaluation<br/>[engine.py]"]
  node_strategy_contract["Strategy contract<br/>strategy interface<br/>[base.py]"]
  node_strategy_implementations["Concrete strategies<br/>strategy implementations<br/>[adaptive_trend.py]"]
  node_position_sizer["Position sizer<br/>risk allocation<br/>[sizer.py]"]
  node_execution_simulator["Execution simulator<br/>simulated execution<br/>[simulator.py]"]
end

node_app["Application<br/>orchestrator<br/>[app.py]"]
node_parquet_data[("Prepared Parquet data<br/>local dataset")]
node_dashboard["Simulator dashboard<br/>browser visualization"]

node_app -->|"runs"| node_pipeline_main
node_app -->|"loads data"| node_data_loader
node_app -->|"runs simulation"| node_execution_simulator
node_tickvault -->|"market data"| node_tickvault_client
node_download_year -->|"requests downloads"| node_tickvault_client
node_download_year -->|"cleans downloads"| node_download_cleanup
node_pipeline_main -->|"orchestrates acquisition"| node_download_year
node_pipeline_main -->|"reads source files"| node_reader
node_reader -->|"parsed records"| node_validator
node_validator -->|"validated data"| node_cleaner
node_cleaner -->|"normalized data"| node_resampler
node_resampler -->|"target intervals"| node_parquet_writer
node_parquet_writer -->|"persists"| node_parquet_data
node_parquet_data -->|"prepared datasets"| node_data_loader
node_data_loader -->|"market data"| node_indicator_engine
node_indicator_engine -->|"enriched inputs"| node_strategy_engine
node_strategy_contract -.->|"implemented by"| node_strategy_implementations
node_strategy_implementations -->|"signals"| node_strategy_engine
node_strategy_engine -->|"opportunities"| node_position_sizer
node_position_sizer -->|"sized decisions"| node_execution_simulator
node_execution_simulator -->|"simulation output"| node_dashboard

click node_app "https://github.com/nitro56565/ai-quant-lab/blob/main/app.py"
click node_download_year "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/download_year.py"
click node_tickvault_client "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/tickvault_client.py"
click node_download_cleanup "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/cleanup.py"
click node_pipeline_main "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/main.py"
click node_reader "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/parser/reader.py"
click node_validator "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/validator/validator.py"
click node_cleaner "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/cleaner/cleaner.py"
click node_resampler "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/converters/resampler.py"
click node_parquet_writer "https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/converters/parquet_writer.py"
click node_data_loader "https://github.com/nitro56565/ai-quant-lab/blob/main/data_loader/loader.py"
click node_indicator_engine "https://github.com/nitro56565/ai-quant-lab/blob/main/indicator_engine/engine.py"
click node_strategy_engine "https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/engine.py"
click node_strategy_contract "https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/base.py"
click node_strategy_implementations "https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/adaptive_trend.py"
click node_position_sizer "https://github.com/nitro56565/ai-quant-lab/blob/main/position_sizer/sizer.py"
click node_execution_simulator "https://github.com/nitro56565/ai-quant-lab/blob/main/execution_simulator/simulator.py"
click node_dashboard "https://github.com/nitro56565/ai-quant-lab/blob/main/simulator_dashboard.html"

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_tickvault,node_download_year,node_tickvault_client,node_download_cleanup,node_pipeline_main,node_reader,node_validator,node_cleaner,node_resampler,node_parquet_writer toneBlue
class node_data_loader,node_indicator_engine,node_strategy_engine,node_strategy_contract,node_strategy_implementations,node_position_sizer,node_execution_simulator toneAmber
class node_app,node_parquet_data,node_dashboard toneNeutral
```

## Components

### Market Data Pipeline

Acquires and prepares local analytical datasets.

- **TickVault**: external market data · Remote market-data provider.
- [Yearly downloads](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/download_year.py): download orchestration · `market_data_pipeline/downloader/download_year.py`
- [TickVault client](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/tickvault_client.py): service client · `market_data_pipeline/downloader/tickvault_client.py`
- [Download cleanup](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/downloader/cleanup.py): cleanup stage · `market_data_pipeline/downloader/cleanup.py`
- [Pipeline workflow](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/main.py): pipeline orchestrator · `market_data_pipeline/main.py`
- [Source reader](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/parser/reader.py): parser · `market_data_pipeline/parser/reader.py`
- [Record validation](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/validator/validator.py): validation stage · `market_data_pipeline/validator/validator.py`
- [Data cleaning](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/cleaner/cleaner.py): cleaning stage · `market_data_pipeline/cleaner/cleaner.py`
- [Interval resampling](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/converters/resampler.py): conversion stage · `market_data_pipeline/converters/resampler.py`
- [Parquet writer](https://github.com/nitro56565/ai-quant-lab/blob/main/market_data_pipeline/converters/parquet_writer.py): dataset persistence · `market_data_pipeline/converters/parquet_writer.py`

### Quantitative Stack

Consumes prepared data for signals, sizing, and simulated execution.

- [Data loader](https://github.com/nitro56565/ai-quant-lab/blob/main/data_loader/loader.py): data access boundary · `data_loader/loader.py`
- [Indicator engine](https://github.com/nitro56565/ai-quant-lab/blob/main/indicator_engine/engine.py): indicator calculation · `indicator_engine/engine.py`
- [Strategy engine](https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/engine.py): signal evaluation · `strategy_engine/engine.py`
- [Strategy contract](https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/base.py): strategy interface · Common contract for concrete signal strategies. · `strategy_engine/base.py`
- [Concrete strategies](https://github.com/nitro56565/ai-quant-lab/blob/main/strategy_engine/adaptive_trend.py): strategy implementations · Trend, mean-reversion, breakout, momentum, and pullback strategies. · `strategy_engine/adaptive_trend.py`
- [Position sizer](https://github.com/nitro56565/ai-quant-lab/blob/main/position_sizer/sizer.py): risk allocation · `position_sizer/sizer.py`
- [Execution simulator](https://github.com/nitro56565/ai-quant-lab/blob/main/execution_simulator/simulator.py): simulated execution · Models fills, outcomes, and portfolio accounting. · `execution_simulator/simulator.py`

### Other components

- [Application](https://github.com/nitro56565/ai-quant-lab/blob/main/app.py): orchestrator · `app.py`
- **Prepared Parquet data**: local dataset · Handoff between preparation and quantitative consumers.
- [Simulator dashboard](https://github.com/nitro56565/ai-quant-lab/blob/main/simulator_dashboard.html): browser visualization · `simulator_dashboard.html`

## Connections

- Application → Pipeline workflow: runs
- Application → Data loader: loads data
- Application → Execution simulator: runs simulation
- TickVault → TickVault client: market data
- Yearly downloads → TickVault client: requests downloads
- Yearly downloads → Download cleanup: cleans downloads
- Pipeline workflow → Yearly downloads: orchestrates acquisition
- Pipeline workflow → Source reader: reads source files
- Source reader → Record validation: parsed records
- Record validation → Data cleaning: validated data
- Data cleaning → Interval resampling: normalized data
- Interval resampling → Parquet writer: target intervals
- Parquet writer → Prepared Parquet data: persists
- Prepared Parquet data → Data loader: prepared datasets
- Data loader → Indicator engine: market data
- Indicator engine → Strategy engine: enriched inputs
- Strategy contract → Concrete strategies: implemented by
- Concrete strategies → Strategy engine: signals
- Strategy engine → Position sizer: opportunities
- Position sizer → Execution simulator: sized decisions
- Execution simulator → Simulator dashboard: simulation output
