# erfaniaa/crypto-portfolio-optimizer architecture

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

- Interactive diagram: https://gitdiagram.com/erfaniaa/crypto-portfolio-optimizer
- Repository: https://github.com/erfaniaa/crypto-portfolio-optimizer

## Overview

##### Project’s Main Components
- Entry Point: main.py, which coordinates and initiates the portfolio simulation process.
- Configuration Module: config.py, holding simulation and optimization parameters (e.g., candidate coins, date interval, wallet size, weights precision).
- Optimization Engine: crypto_portfolio_optimizer.py, which likely contains the brute-force (backtracking) algorithm to explore different allocations.
- Simulation Component: wallet_simulator.py, which is in charge of simulating the portfolio performance over the backtested period.
- Metrics Analysis: metrics.py, responsible for computing and evaluating key performance measures like drawdowns.
- External Dependencies: requirements.txt outlines the Python libraries, and the project may rely on external data sources not explicitly shown here (but implied in the simulation of historical coin data).

##### Relationships and Interactions
- main.py serves as the application’s entry point. It reads configuration values from config.py and initiates the simulation.
- From main.py, the optimization engine (in crypto_portfolio_optimizer.py) is called to generate a range of potential portfolio allocations.
- The wallet_simulator.py then uses these allocation strategies to simulate the investment portfolio’s performance over a given historical period.
- After simulation, metrics.py is called to analyze the performance (especially focusing on drawdown calculations).

##### Architectural Patterns and Design Principles
- Modular Design: Each file represents a distinct module with clearly separated responsibilities (configuration, optimization, simulation, and metrics).
- Single Entry Point: The “main.py” centralizes execution, which simplifies the integration of various modules.
- Data Flow Driven by Configuration: The config.py file abstracts key simulation parameters, ensuring that the system can be easily tuned without modifying business logic.
- Emphasis on Simulation and Backtesting: The design reflects a focus on processing historical data to simulate and optimize portfolio performance.

##### Relevant Technologies and Frameworks
- Python (as the primary programming language)
- Standard libraries and potential dependencies (as indicated by requirements.txt) for numerical analysis, data handling, or even plotting (if used for visualization in the simulation results).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependency
    EXT["External Dependencies (requirements.txt)"]:::ext

    %% Core Modules Subgraph
    subgraph "Core Modules"
        CONFIG["Configuration (config.py)"]:::core
        MAIN["Application Entry (main.py)"]:::core
    end

    %% Simulation Modules Subgraph
    subgraph "Simulation Modules"
        OPT["Portfolio Optimizer (crypto_portfolio_optimizer.py)"]:::sim
        SIM["Wallet Simulator (wallet_simulator.py)"]:::sim
        MET["Metrics Analyzer (metrics.py)"]:::sim
    end

    %% Data Flow
    CONFIG -->|"reads_parameters"| MAIN
    MAIN -->|"calls_optimizer"| OPT
    MAIN -->|"calls_simulation"| SIM
    SIM -->|"outputs_metrics"| MET

    %% External Dependencies Feeding Components
    EXT -.->|"provides_packages"| CONFIG
    EXT -.->|"provides_packages"| MAIN
    EXT -.->|"provides_packages"| OPT
    EXT -.->|"provides_packages"| SIM
    EXT -.->|"provides_packages"| MET

    %% Click Events
    click CONFIG "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/config.py"
    click MAIN "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/main.py"
    click OPT "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/crypto_portfolio_optimizer.py"
    click SIM "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/wallet_simulator.py"
    click MET "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/metrics.py"
    click EXT "https://github.com/erfaniaa/crypto-portfolio-optimizer/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#ffdddd,stroke:#b30000,stroke-width:2px,color:#000000;
    classDef sim fill:#ddffdd,stroke:#008000,stroke-width:2px,color:#000000;
    classDef ext fill:#ddeeff,stroke:#003399,stroke-width:2px,color:#000000;
```
