# fabioavelino/money-printer architecture

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

- Interactive diagram: https://gitdiagram.com/fabioavelino/money-printer
- Repository: https://github.com/fabioavelino/money-printer

## Overview

##### Main Components
- Backtesting Core:
- Files: backtest.js, backtest_v1.js, and the backtest/ directory (with backtest_helper.js and market_data_configs.js) form the core of the backtesting logic.
- Data Input / Market Data Services:
- Directory: services/ – Contains subdirectories for data providers (alphavantage, binance, polygon, tiingo) with their corresponding data handlers and helper modules.
- Data flows from these modules into the backtesting engine.
- Strategy Evaluation:
- Directory: strategies/ – Contains individual trading strategies (e.g., strategies/arima, strategies/hma_kahlman_strategy.js) that implement specific buy/sell logic.
- Signal Generation:
- Directory: signals/ – Contains various signal generation modules (adaptive_zlema_signal.js, macd_signal.js, rsi_signal.js, etc.) that compute indicators and criteria used by the strategies.
- Utility and Helper Functions:
- Directory: helpers/ – Provides utility functions (data manipulation, statistical calculations, ARIMA helper, TensorFlow-related helpers, etc.) that support both strategies and signal processing.
- Portfolio Management:
- Directory: portfolio/ – Implements portfolio evaluation and performance comparison tools, vital for gauging trading strategy outcomes.
- Visualization:
- Files: index.html, htmls/visualizeCharts/ – Although not the primary focus for strategy evaluation, these present the results and analytics in a user-friendly way.

##### Component Relationships and Data Flow
- Data Collection: Market data is fetched from external providers through the services modules. Each service has data handler modules that “generate” or process the data, which is then passed to the backtesting engine.
- Backtesting Engine: The backtest.js file orchestrates the process by:
- Loading historical market data.
- Invoking the chosen strategy from the strategies/ directory.
- Using signals modules to decide on “buy” or “sell” actions.
- Employing helper utilities to process technical indicators and metrics.
- Strategy Execution: Each strategy (located in strategies/) uses algorithm logic, frequently calling on the signals and helpers to evaluate market conditions.
- Portfolio and Performance: The portfolio/ directory takes the outcomes from backtesting. It computes metrics like Sharpe Ratio and Maximum Drawdown and may work with visualization components to display the performance.
- Visualization/UI: After computation, the output data can be sent to the HTML/JS visualization modules for rendering interactive charts.

##### Architectural Patterns and Design Principles
- Modular Separation: The project follows a modular design where each component (data services, backtesting logic, strategy implementation, signal generation, etc.) is separated into its own directory.
- Loose Coupling: Strategies, signals, and helper utilities are designed to operate independently, allowing for easy extension or swapping of individual modules.
- Plug-and-Play: New strategies or data sources can be added without major changes to the core system, thanks to the standardized folder structure and conventions.
- Clear Data Flow: There is a clear flow from external market data through processing to strategy decision-making and finally portfolio evaluation.

##### Technologies, Frameworks, and Libraries
- Node.js: The project is a Node.js application that leverages JavaScript for server-side logic.
- External APIs: Utilizes APIs from providers such as Binance, Tiingo, AlphaVantage, and Polygon.
- Built-in/Custom Libraries: Uses custom helper functions and modules (possibly some TensorFlow utilities) for analysis and numerical calculations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Market Data Services
    subgraph "Market Data Services"
        DS("Data Services"):::dataservice
    end

    %% Backtesting Engine
    subgraph "Backtesting Engine"
        BT1("backtest.js"):::engine
        BT2("backtest_v1.js"):::engine
        BT_DIR("Backtest Core Directory"):::engine
    end

    %% Utility & Helpers
    subgraph "Utility & Helpers"
        HL("Helpers Directory"):::helper
    end

    %% Strategy Evaluation
    subgraph "Strategy Evaluation"
        ST("Strategies Directory"):::strategy
    end

    %% Signal Generation
    subgraph "Signal Generation"
        SG("Signals Directory"):::signal
    end

    %% Portfolio Management
    subgraph "Portfolio Management"
        PF("Portfolio Directory"):::portfolio
    end

    %% Visualization/UI
    subgraph "Visualization/UI"
        VIS1("index.html"):::visual
        VIS2("Visualization Charts Directory"):::visual
    end

    %% Data Flow Connections (vertical orientation)
    DS --> BT1
    BT1 --> ST
    BT1 --> SG
    %% Dependencies on Helpers (dashed lines)
    BT1 -.-> HL
    HL -.-> ST
    HL -.-> SG
    %% Aggregation into Portfolio Management
    ST --> PF
    SG --> PF
    %% Final visualization steps
    PF --> VIS1
    VIS1 --> VIS2

    %% Click Events
    click DS "https://github.com/fabioavelino/money-printer/tree/main/services/"
    click BT1 "https://github.com/fabioavelino/money-printer/blob/main/backtest.js"
    click BT2 "https://github.com/fabioavelino/money-printer/blob/main/backtest_v1.js"
    click BT_DIR "https://github.com/fabioavelino/money-printer/tree/main/backtest/"
    click ST "https://github.com/fabioavelino/money-printer/tree/main/strategies/"
    click SG "https://github.com/fabioavelino/money-printer/tree/main/signals/"
    click HL "https://github.com/fabioavelino/money-printer/tree/main/helpers/"
    click PF "https://github.com/fabioavelino/money-printer/tree/main/portfolio/"
    click VIS1 "https://github.com/fabioavelino/money-printer/blob/main/index.html"
    click VIS2 "https://github.com/fabioavelino/money-printer/tree/main/htmls/visualizeCharts/"

    %% Styling Classes
    classDef dataservice fill:#8EC0E4,stroke:#000,stroke-width:2px;
    classDef engine fill:#F4A261,stroke:#000,stroke-width:2px;
    classDef strategy fill:#2A9D8F,stroke:#000,stroke-width:2px,color:#fff;
    classDef signal fill:#E76F51,stroke:#000,stroke-width:2px;
    classDef helper fill:#E9C46A,stroke:#000,stroke-width:2px;
    classDef portfolio fill:#264653,stroke:#fff,stroke-width:2px,color:#fff;
    classDef visual fill:#A8DADC,stroke:#000,stroke-width:2px;
```
