# algotrade-research/searchingta architecture

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

- Interactive diagram: https://gitdiagram.com/algotrade-research/searchingta
- Repository: https://github.com/algotrade-research/searchingta

## Overview

##### Project’s Main Components
- Data Collection & Ingestion: Represented by the Downloader class in the “utils” folder, which fetches tick and bid/ask data from an external algotrade database. This component is responsible for ingesting large amounts of tick data and preparing it for analysis.
- Data Processing & Resampling: Also in “utils” (processor.py) along with visualization utilities, this part converts raw tick data into resampled OHLC and technical indicator enriched data.
- Signal Generation / Trading Strategy: Located in the “strategy” folder, these components include functions (e.g., the RSI strategy) which generate trading signals (buy/sell/hold) based on technical indicators.
- Backtesting Engine: Found under the “backtest/backtesting” module along with configuration and portfolio management (“backtest/portfolio”), this engine applies the generated signals to historical data, simulating trade execution. It implements risk and position management rules.
- Optimization Engine: In the “optimize” folder, this component leverages Optuna to fine-tune indicator parameters (including TP, SL, interval, etc.) to optimize performance metrics such as winrate, Sharpe ratio, and maximum drawdown.
- Configuration & Deployment: Files such as “long.py” and “short.py” serve as entry points for running long/short strategy simulations. The project also contains devcontainer configurations and CSV data used to support initial testing.

##### Relationships and Interactions
- Data flows from external sources into the Downloader, then passes through the data processing component.
- The processed data is fed into the Backtesting Engine where strategies (from the Strategy module) are applied.
- Results of the backtests—including performance metrics like winrate and PnL distribution—are stored or visualized.
- The Optimization Engine (using Optuna) interacts with the backtesting module by repeatedly calling it with different hyperparameters based on trial results.
- Finally, a Testing module leverages the best parameters to perform out-of-sample validation, with results visualized and compared via reporting tools.

##### Architectural Patterns and Design Principles
- Model–View Separation: Backtesting and optimization logic are separated from the data ingestion and visualization components, allowing independent updates and testing.
- Modularity: Each module (backtest, optimize, strategy, utils) is encapsulated so that each process (data download, signal generation, simulation, optimization) can be developed and maintained independently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    DB["Algotrade Database"]:::external

    subgraph "Data Ingestion and Processing"
        A1["Data Downloader"]:::data
        A2["Data Processor & Resampler"]:::data
        A3["Visualization Utility"]:::data
        A1 -->|"tickData"| A2
        A2 -->|"processedData"| A3
    end
    DB --> A1

    subgraph "Trading Strategy Generation"
        B1["Trading Signal Generator"]:::strategy
        B1a["Strategy: strategy_name.py"]:::strategy
        B1b["Indicator: technical_indicator.py"]:::strategy
        B1 -->|"applyLogic"| B1a
        B1 -->|"useIndicators"| B1b
    end
    A3 -->|"dataForSignals"| B1
    B1 -->|"generatedSignals"| C1

    subgraph "Simulation and Backtesting"
        C1["Backtesting Engine"]:::simulation
        C2["Portfolio Management"]:::simulation
        C1 -->|"simulateTrades"| C2
    end

    subgraph "Optimization"
        D1["Hyperparameter Optimizer"]:::optimizer
        D2["Parameter Searcher"]:::optimizer
        D1 -->|"searchParams"| D2
        D1 ---|"optimizes"| C1
        D2 ---|"feedsParams"| C1
    end
    C2 -->|"backtestResults"| E1

    subgraph "Testing & Reporting"
        E1["Out-of-Sample Tester"]:::testing
        E2["Jupyter Notebook Visualizer"]:::testing
        E3["Reporting Module"]:::reporting
        E4["Candlestick Chart"]:::reporting
        E1 -->|"visualizeResults"| E2
        E2 -->|"reportData"| E3
        E3 -->|"displayChart"| E4
    end

    subgraph "Configuration & Deployment"
        F1["Backtest Config"]:::config
        F2["Long Simulation"]:::config
        F3["Short Simulation"]:::config
        F1 --> F2
        F1 --> F3
        F2 ---|"triggerBacktest"| C1
        F3 ---|"triggerBacktest"| C1
    end

    %% Click Events
    click A1 "https://github.com/algotrade-research/searchingta/blob/main/utils/downloader.py"
    click A2 "https://github.com/algotrade-research/searchingta/blob/main/utils/processor.py"
    click A3 "https://github.com/algotrade-research/searchingta/blob/main/utils/visualize.py"
    click B1a "https://github.com/algotrade-research/searchingta/blob/main/strategy/strategy_name.py"
    click B1b "https://github.com/algotrade-research/searchingta/blob/main/strategy/technical_indicator.py"
    click C1 "https://github.com/algotrade-research/searchingta/blob/main/backtest/backtesting/Backtesting.py"
    click C2 "https://github.com/algotrade-research/searchingta/blob/main/backtest/portfolio/Portfolio.py"
    click D1 "https://github.com/algotrade-research/searchingta/blob/main/optimize/Optimizer.py"
    click D2 "https://github.com/algotrade-research/searchingta/blob/main/optimize/Searcher.py"
    click E1 "https://github.com/algotrade-research/searchingta/blob/main/papertrade/Papertrade.py"
    click E2 "https://github.com/algotrade-research/searchingta/blob/main/visualize.ipynb"
    click E3 "https://github.com/algotrade-research/searchingta/blob/main/report/Report.py"
    click E4 "https://github.com/algotrade-research/searchingta/blob/main/candlestick_chart.html"
    click F1 "https://github.com/algotrade-research/searchingta/blob/main/backtest/backtest_config/BacktestConfig.py"
    click F2 "https://github.com/algotrade-research/searchingta/blob/main/long.py"
    click F3 "https://github.com/algotrade-research/searchingta/blob/main/short.py"

    %% Styles
    classDef data fill:#C6E2FF,stroke:#000,stroke-width:1px;
    classDef strategy fill:#FFCCCC,stroke:#000,stroke-width:1px;
    classDef simulation fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef optimizer fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef testing fill:#EE82EE,stroke:#000,stroke-width:1px;
    classDef reporting fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef external fill:#ADD8E6,stroke:#000,stroke-width:1px;
```
