# wonglaitung/fortune architecture

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

- Interactive diagram: https://gitdiagram.com/wonglaitung/fortune
- Repository: https://github.com/wonglaitung/fortune

## Overview

This repository is a dual-market financial analysis and trading assistant for Hong Kong and A-share equities. Its principal workflow collects market and company data, derives technical and market features, produces multi-horizon model predictions and complementary analysis, combines signals into trading recommendations, then delivers reports and alerts. Separate branches cover anomaly detection, Hang Seng Index forecasts, A-share analysis, and strategy validation/performance monitoring. The README documents these capabilities; several implementation files were not sampled, so links for those branches are limited to documented workflow relationships.

Main entry points: [`ml_services/ml_trading_model.py`](https://github.com/wonglaitung/fortune/blob/main/ml_services/ml_trading_model.py) (HK stock model), [`message_services/notifier.py`](https://github.com/wonglaitung/fortune/blob/main/message_services/notifier.py) (Notification service), [`data_services/tencent_finance.py`](https://github.com/wonglaitung/fortune/blob/main/data_services/tencent_finance.py) (HK market data), [`comprehensive_analysis.py`](https://github.com/wonglaitung/fortune/blob/main/comprehensive_analysis.py) (HK recommendations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Market data"]
  node_hk_data["HK market data<br/>[tencent_finance.py]"]
  node_a_data["A-share data<br/>[a_stock_data.py]"]
  node_fundamentals["Fundamentals"]
end

subgraph group_analysis["Analysis and signals"]
  node_technical["Technical indicators"]
  node_calendar["Calendar features"]
  node_sectors["Sector analysis"]
  node_regimes["Market regimes<br/>[regime_detector.py]"]
  node_network["Stock networks"]
  node_anomalies["Anomaly detection"]
  node_llm["Qwen analysis<br/>[qwen_engine.py]"]
  node_hk_report["HK recommendations"]
  node_a_report["A-share recommendations"]
  node_hsi_report["HSI / HK alerts<br/>[hsi_email.py]"]
  node_anomaly_job["Anomaly workflow"]
end

subgraph group_models["Prediction and validation"]
  node_hk_model["HK stock model"]
  node_a_model["A-share model"]
  node_hsi_model["HSI forecasts<br/>[hsi_ml_model.py]"]
  node_validation["Walk-forward validation"]
  node_monitoring["Performance monitoring"]
end

subgraph group_delivery["Reports and alerts"]
  node_messaging["Notification service<br/>[notifier.py]"]
  node_email["Email delivery<br/>[email_sender.py]"]
  node_wechat["WeChat delivery<br/>[wechat_work_bot.py]"]
  node_wxpush["WxPusher delivery<br/>[wxpusher_bot.py]"]
end

node_operator(("Investor / schedule"))
node_qwen_service["Qwen API"]
node_smtp["SMTP server"]
node_notification_users(("Report recipients"))

node_operator -.->|"requests report"| node_hk_report
node_operator -.->|"requests report"| node_a_report
node_hk_data -.->|"provides prices"| node_technical
node_hk_data -.->|"provides market context"| node_fundamentals
node_hk_data -->|"provides prices"| node_sectors
node_hk_data -->|"provides market data"| node_calendar
node_a_data -->|"provides prices"| node_a_model
node_technical -->|"supplies features"| node_hk_model
node_fundamentals -->|"supplies features"| node_hk_model
node_calendar -->|"supplies features"| node_hk_model
node_regimes -->|"supplies features"| node_hk_model
node_sectors -->|"supplies features"| node_hk_model
node_network -->|"supplies features"| node_hk_model
node_hk_data -->|"provides prices"| node_hsi_model
node_anomalies -->|"detects outliers"| node_hsi_model
node_hk_model -->|"provides predictions"| node_hk_report
node_llm -.->|"provides analysis"| node_hk_report
node_qwen_service -->|"answers requests"| node_llm
node_a_model -.->|"provides predictions"| node_a_report
node_hsi_model -.->|"provides forecasts"| node_hsi_report
node_anomaly_job -.->|"runs detection"| node_anomalies
node_hk_report -.->|"sends report"| node_messaging
node_a_report -.->|"sends report"| node_messaging
node_hsi_report -.->|"sends alerts"| node_messaging
node_messaging -->|"dispatches email"| node_email
node_messaging -->|"dispatches WeChat"| node_wechat
node_messaging -.->|"dispatches push"| node_wxpush
node_email -->|"sends mail"| node_smtp
node_email -.->|"delivers report"| node_notification_users
node_hk_model -->|"evaluates model"| node_validation
node_validation -.->|"tracks performance"| node_monitoring
node_monitoring -->|"reports metrics"| node_messaging

click node_hk_data "https://github.com/wonglaitung/fortune/blob/main/data_services/tencent_finance.py"
click node_a_data "https://github.com/wonglaitung/fortune/blob/main/data_services/a_stock_data.py"
click node_fundamentals "https://github.com/wonglaitung/fortune/blob/main/data_services/fundamental_data.py"
click node_technical "https://github.com/wonglaitung/fortune/blob/main/data_services/technical_analysis.py"
click node_calendar "https://github.com/wonglaitung/fortune/blob/main/data_services/calendar_features.py"
click node_sectors "https://github.com/wonglaitung/fortune/blob/main/data_services/hk_sector_analysis.py"
click node_regimes "https://github.com/wonglaitung/fortune/blob/main/data_services/regime_detector.py"
click node_network "https://github.com/wonglaitung/fortune/blob/main/ml_services/stock_network_analysis.py"
click node_hk_model "https://github.com/wonglaitung/fortune/blob/main/ml_services/ml_trading_model.py"
click node_a_model "https://github.com/wonglaitung/fortune/blob/main/a_stock_ml_model.py"
click node_hsi_model "https://github.com/wonglaitung/fortune/blob/main/ml_services/hsi_ml_model.py"
click node_anomalies "https://github.com/wonglaitung/fortune/blob/main/anomaly_detector/isolation_forest_detector.py"
click node_llm "https://github.com/wonglaitung/fortune/blob/main/llm_services/qwen_engine.py"
click node_hk_report "https://github.com/wonglaitung/fortune/blob/main/comprehensive_analysis.py"
click node_a_report "https://github.com/wonglaitung/fortune/blob/main/a_stock_comprehensive_analysis.py"
click node_hsi_report "https://github.com/wonglaitung/fortune/blob/main/hsi_email.py"
click node_anomaly_job "https://github.com/wonglaitung/fortune/blob/main/detect_stock_anomalies.py"
click node_validation "https://github.com/wonglaitung/fortune/blob/main/ml_services/walk_forward_validation.py"
click node_monitoring "https://github.com/wonglaitung/fortune/blob/main/ml_services/performance_monitor.py"
click node_messaging "https://github.com/wonglaitung/fortune/blob/main/message_services/notifier.py"
click node_email "https://github.com/wonglaitung/fortune/blob/main/message_services/email_sender.py"
click node_wechat "https://github.com/wonglaitung/fortune/blob/main/message_services/wechat_work_bot.py"
click node_wxpush "https://github.com/wonglaitung/fortune/blob/main/message_services/wxpusher_bot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_hk_data,node_a_data,node_fundamentals toneBlue
class node_technical,node_calendar,node_sectors,node_regimes,node_network,node_anomalies,node_llm,node_hk_report,node_a_report,node_hsi_report,node_anomaly_job toneAmber
class node_hk_model,node_a_model,node_hsi_model,node_validation,node_monitoring,node_qwen_service,node_smtp toneMint
class node_messaging,node_email,node_wechat,node_wxpush toneRose
class node_operator,node_notification_users toneIndigo
```

## Components

### Market data

- [HK market data](https://github.com/wonglaitung/fortune/blob/main/data_services/tencent_finance.py): `data_services/tencent_finance.py`
- [A-share data](https://github.com/wonglaitung/fortune/blob/main/data_services/a_stock_data.py): `data_services/a_stock_data.py`
- [Fundamentals](https://github.com/wonglaitung/fortune/blob/main/data_services/fundamental_data.py): `data_services/fundamental_data.py`

### Analysis and signals

- [Technical indicators](https://github.com/wonglaitung/fortune/blob/main/data_services/technical_analysis.py): `data_services/technical_analysis.py`
- [Calendar features](https://github.com/wonglaitung/fortune/blob/main/data_services/calendar_features.py): `data_services/calendar_features.py`
- [Sector analysis](https://github.com/wonglaitung/fortune/blob/main/data_services/hk_sector_analysis.py): `data_services/hk_sector_analysis.py`
- [Market regimes](https://github.com/wonglaitung/fortune/blob/main/data_services/regime_detector.py): `data_services/regime_detector.py`
- [Stock networks](https://github.com/wonglaitung/fortune/blob/main/ml_services/stock_network_analysis.py): `ml_services/stock_network_analysis.py`
- [Anomaly detection](https://github.com/wonglaitung/fortune/blob/main/anomaly_detector/isolation_forest_detector.py): `anomaly_detector/isolation_forest_detector.py`
- [Qwen analysis](https://github.com/wonglaitung/fortune/blob/main/llm_services/qwen_engine.py): `llm_services/qwen_engine.py`
- [HK recommendations](https://github.com/wonglaitung/fortune/blob/main/comprehensive_analysis.py): `comprehensive_analysis.py`
- [A-share recommendations](https://github.com/wonglaitung/fortune/blob/main/a_stock_comprehensive_analysis.py): `a_stock_comprehensive_analysis.py`
- [HSI / HK alerts](https://github.com/wonglaitung/fortune/blob/main/hsi_email.py): `hsi_email.py`
- [Anomaly workflow](https://github.com/wonglaitung/fortune/blob/main/detect_stock_anomalies.py): `detect_stock_anomalies.py`

### Prediction and validation

- [HK stock model](https://github.com/wonglaitung/fortune/blob/main/ml_services/ml_trading_model.py): `ml_services/ml_trading_model.py`
- [A-share model](https://github.com/wonglaitung/fortune/blob/main/a_stock_ml_model.py): `a_stock_ml_model.py`
- [HSI forecasts](https://github.com/wonglaitung/fortune/blob/main/ml_services/hsi_ml_model.py): `ml_services/hsi_ml_model.py`
- [Walk-forward validation](https://github.com/wonglaitung/fortune/blob/main/ml_services/walk_forward_validation.py): `ml_services/walk_forward_validation.py`
- [Performance monitoring](https://github.com/wonglaitung/fortune/blob/main/ml_services/performance_monitor.py): `ml_services/performance_monitor.py`

### Reports and alerts

- [Notification service](https://github.com/wonglaitung/fortune/blob/main/message_services/notifier.py): `message_services/notifier.py`
- [Email delivery](https://github.com/wonglaitung/fortune/blob/main/message_services/email_sender.py): `message_services/email_sender.py`
- [WeChat delivery](https://github.com/wonglaitung/fortune/blob/main/message_services/wechat_work_bot.py): `message_services/wechat_work_bot.py`
- [WxPusher delivery](https://github.com/wonglaitung/fortune/blob/main/message_services/wxpusher_bot.py): `message_services/wxpusher_bot.py`

### Other components

- **Investor / schedule**
- **Qwen API**
- **SMTP server**
- **Report recipients**

## Connections

- Investor / schedule → HK recommendations: requests report
- Investor / schedule → A-share recommendations: requests report
- HK market data → Technical indicators: provides prices
- HK market data → Fundamentals: provides market context
- HK market data → Sector analysis: provides prices (evidence: `data_services/hk_sector_analysis.py`)
- HK market data → Calendar features: provides market data (evidence: `data_services/calendar_features.py`)
- A-share data → A-share model: provides prices (evidence: `data_services/a_stock_data.py`)
- Technical indicators → HK stock model: supplies features (evidence: `ml_services/ml_trading_model.py`)
- Fundamentals → HK stock model: supplies features (evidence: `ml_services/ml_trading_model.py`)
- Calendar features → HK stock model: supplies features (evidence: `ml_services/ml_trading_model.py`)
- Market regimes → HK stock model: supplies features (evidence: `ml_services/ml_trading_model.py`)
- Sector analysis → HK stock model: supplies features (evidence: `ml_services/ml_trading_model.py`)
- Stock networks → HK stock model: supplies features
- HK market data → HSI forecasts: provides prices
- Anomaly detection → HSI forecasts: detects outliers
- HK stock model → HK recommendations: provides predictions (evidence: `comprehensive_analysis.py`)
- Qwen analysis → HK recommendations: provides analysis (evidence: `comprehensive_analysis.py`)
- Qwen API → Qwen analysis: answers requests (evidence: `llm_services/qwen_engine.py`)
- A-share model → A-share recommendations: provides predictions
- HSI forecasts → HSI / HK alerts: provides forecasts
- Anomaly workflow → Anomaly detection: runs detection
- HK recommendations → Notification service: sends report
- A-share recommendations → Notification service: sends report
- HSI / HK alerts → Notification service: sends alerts
- Notification service → Email delivery: dispatches email (evidence: `message_services/__init__.py`)
- Notification service → WeChat delivery: dispatches WeChat (evidence: `message_services/__init__.py`)
- Notification service → WxPusher delivery: dispatches push (evidence: `message_services/__init__.py`)
- Email delivery → SMTP server: sends mail (evidence: `message_services/email_sender.py`)
- Email delivery → Report recipients: delivers report
- HK stock model → Walk-forward validation: evaluates model (evidence: `ml_services/walk_forward_validation.py`)
- Walk-forward validation → Performance monitoring: tracks performance
- Performance monitoring → Notification service: reports metrics (evidence: `ml_services/performance_monitor.py`)
