How nitro56565/ai-quant-lab works
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 Application · main.py Pipeline workflow · download_year.py Yearly downloads · loader.py Data loader
Components 20
Market Data Pipeline
Acquires and prepares local analytical datasets.
- TickVault · Remote market-data provider.
- Yearly downloads
market_data_pipeline/downloader/download_year.py - TickVault client
market_data_pipeline/downloader/tickvault_client.py - Download cleanup
market_data_pipeline/downloader/cleanup.py - Pipeline workflow
market_data_pipeline/main.py - Source reader
market_data_pipeline/parser/reader.py - Record validation
market_data_pipeline/validator/validator.py - Data cleaning
market_data_pipeline/cleaner/cleaner.py - Interval resampling
market_data_pipeline/converters/resampler.py - Parquet writer
market_data_pipeline/converters/parquet_writer.py
Quantitative Stack
Consumes prepared data for signals, sizing, and simulated execution.
- Data loader
data_loader/loader.py - Indicator engine
indicator_engine/engine.py - Strategy engine
strategy_engine/engine.py - Strategy contract · Common contract for concrete signal strategies.
strategy_engine/base.py - Concrete strategies · Trend, mean-reversion, breakout, momentum, and pullback strategies.
strategy_engine/adaptive_trend.py - Position sizer
position_sizer/sizer.py - Execution simulator · Models fills, outcomes, and portfolio accounting.
execution_simulator/simulator.py
Other components
- Application
app.py - Prepared Parquet data · Handoff between preparation and quantitative consumers.
- Simulator dashboard
simulator_dashboard.html
Connections 21
- 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