# bbfamily/abu architecture

> Architecture diagram of the GitHub repository bbfamily/abu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bbfamily/abu
- Repository: https://github.com/bbfamily/abu

## Overview

##### Main Components
- Core Trading Engine – Based on the “abupy” directory that hosts many submodules (CoreBu, MarketBu, TradeBu, etc.).
- Strategy Modules – Several modules (AlphaBu, BetaBu, FactorBuyBu, FactorSellBu, PickStockBu, etc.) that encapsulate different trading strategies, signal generation, and decision logic.
- Risk and Position Management – Modules such as TradeBu, SlippageBu, and UmpBu manage order execution, risk/commission computations, and “裁判” (ump) style decision-making.
- Data Handling and Market Data – MarketBu and RomDataBu provide data fetching, caching, and parsing capabilities.
- Machine Learning & AI Components – The MLBu module and extensions (in ExtBu) manage machine learning pipelines to optimize and validate strategies.
- Technical Indicators and Analysis – IndicatorBu, MetricsBu, and SimilarBu modules are dedicated to technical indicator calculations, performance scoring, similarity analyses, and statistical validations.
- User Interface Components – abupy_ui provides the non-programmatic front-end and even has notebooks with interactive demos.
- Learning and Documentation – abupy_lecture and ipython directories serve as educational components and example workflows (also demonstrating integration with external resources).

##### Relationships and Interactions
- The Core Trading Engine (CoreBu) is at the heart, instantiating shared utilities and environment settings.
- Pricing and market data management (MarketBu, RomDataBu) feed into the strategy modules.
- Strategy modules (AlphaBu, BetaBu, FactorBuyBu, FactorSellBu, etc.) process data and generate trading signals, often using helper modules (UtilBu) for common functionalities.
- Advanced analysis and machine learning (MLBu, ExtBu) interact with both the strategy modules and risk management modules to refine predictions and optimize parameter selection.
- Execution and risk modules (TradeBu, SlippageBu, UmpBu) interface with the trading simulation/execution system, ensuring capital management and trade orders are dispatched appropriately.
- UI modules (abupy_ui) provide front-end dashboards and visualizations that reflect outputs from the trading engine and analysis modules.
- Finally, the abupy_lecture and ipython directories illustrate sample workflows and serve as documentation/tutorials that tie everything together.

##### Architectural Patterns and Design Principles
- Modular and Layered Design: The code is broken into distinct namespaces (e.g., Core, Market, Strategy, ML, UI), promoting separation of concerns.
- Reusability and Extensibility: Common utilities and base classes (found in directories like UtilBu and ExtBu) support custom extensions.
- Parallel Processing: Modules like CoreBu (with ABuParallel) hint at parallelized computations for backtesting and parameter search.
- Data Abstraction: The strict separation between data ingestion (MarketBu, RomDataBu) and analysis enables swapping data sources.
- Integration of AI and Traditional Technical Analysis: By combining multiple models and strategies (from traditional factors to AI-driven models), the system emphasizes blending diverse quantitative techniques.

##### Relevant Technologies/Frameworks
- Python fundamentals with extensive use of structured modules and package initialization.
- Machine learning pipelines (via ABuML and associated grid search/parameter tuning).
- Notebook interfaces for interactive demonstration (Jupyter/IPython notebooks in abupy_lecture, ipython).
- Deployment and environment configuration – typical deployment with Anaconda as recommended in the README.
- Support for different data sources (stock, futures, digital currencies).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Data Handling & Market Data
    subgraph "Data Handling & Market Data"
        M["MarketBu"]
        R["RomDataBu"]
    end

    %% Core Trading Engine
    subgraph "Core Trading Engine"
        C["CoreBu"]
    end

    %% Strategy Modules
    subgraph "Strategy Modules"
        A["AlphaBu"]
        B["BetaBu"]
        FBuy["FactorBuyBu"]
        FSell["FactorSellBu"]
        P["PickStockBu"]
    end

    %% Technical Indicators and Analysis
    subgraph "Technical Indicators and Analysis"
        I["IndicatorBu"]
        Mtr["MetricsBu"]
        S["SimilarBu"]
    end

    %% Risk & Position Management
    subgraph "Risk & Position Management"
        T["TradeBu"]
        Sl["SlippageBu"]
        U["UmpBu"]
    end

    %% Machine Learning & AI Components
    subgraph "Machine Learning & AI Components"
        ML["MLBu"]
        E["ExtBu"]
    end

    %% User Interface Components
    subgraph "User Interface Components"
        UI["abupy_ui"]
    end

    %% Learning and Documentation
    subgraph "Learning and Documentation"
        L["abupy_lecture"]
        IP["ipython"]
    end

    %% Connections
    %% Data to Strategy Modules
    M -->|"feeds"| A
    R -->|"feeds"| A

    %% Core Trading Engine influences Strategy Modules
    C -->|"instantiates"| A

    %% Technical Indicators feed into Strategy Modules
    I -->|"provides"| A

    %% Strategy Modules interact among themselves (other strategy nodes)
    A -->|"supports"| B
    A -->|"supports"| FBuy
    A -->|"supports"| FSell
    A -->|"supports"| P

    %% Strategy Modules drive Risk & Position Management
    A -->|"signals"| T
    B -->|"signals"| T
    FBuy -->|"signals"| T
    FSell -->|"signals"| T
    P -->|"signals"| T

    %% Machine Learning interacts with Strategy Modules and Risk Management
    ML -- "optimizes" --> A
    A -- "feedback" --> ML
    ML -- "adjusts" --> T
    T -- "triggers" --> ML

    %% Core influences ML components
    C -->|"supports"| ML

    %% Risk & Position Management impact User Interface
    T -->|"outputs"| UI
    Sl -->|"adjusts"| UI
    U -->|"monitors"| UI

    %% Strategy Modules also influence User Interface
    A -->|"reports"| UI

    %% Documentation provides learning content via UI
    L -->|"tutorials"| UI
    IP -->|"notebooks"| UI

    %% Styles
    class C core;
    class A,B,FBuy,FSell,P strategy;
    class T,Sl,U risk;
    class M,R data;
    class ML,E ml;
    class I,Mtr,S tech;
    class UI ui;
    class L,IP doc;

    classDef core fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef strategy fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef risk fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef data fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef ml fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef tech fill:#D8BFD8,stroke:#333,stroke-width:2px;
    classDef ui fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef doc fill:#E6E6FA,stroke:#333,stroke-width:2px;

    %% Click Events
    click C "https://github.com/bbfamily/abu/tree/master/abupy/CoreBu"
    click A "https://github.com/bbfamily/abu/tree/master/abupy/AlphaBu"
    click B "https://github.com/bbfamily/abu/tree/master/abupy/BetaBu"
    click FBuy "https://github.com/bbfamily/abu/tree/master/abupy/FactorBuyBu"
    click FSell "https://github.com/bbfamily/abu/tree/master/abupy/FactorSellBu"
    click P "https://github.com/bbfamily/abu/tree/master/abupy/PickStockBu"
    click T "https://github.com/bbfamily/abu/tree/master/abupy/TradeBu"
    click Sl "https://github.com/bbfamily/abu/tree/master/abupy/SlippageBu"
    click U "https://github.com/bbfamily/abu/tree/master/abupy/UmpBu"
    click M "https://github.com/bbfamily/abu/tree/master/abupy/MarketBu"
    click R "https://github.com/bbfamily/abu/tree/master/abupy/RomDataBu"
    click ML "https://github.com/bbfamily/abu/tree/master/abupy/MLBu"
    click E "https://github.com/bbfamily/abu/tree/master/abupy/ExtBu"
    click I "https://github.com/bbfamily/abu/tree/master/abupy/IndicatorBu"
    click Mtr "https://github.com/bbfamily/abu/tree/master/abupy/MetricsBu"
    click S "https://github.com/bbfamily/abu/tree/master/abupy/SimilarBu"
    click UI "https://github.com/bbfamily/abu/tree/master/abupy_ui"
    click L "https://github.com/bbfamily/abu/tree/master/abupy_lecture"
    click IP "https://github.com/bbfamily/abu/tree/master/ipython"
```
