Skip to content

chinesewebman/ashare_predict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A股形态预测 / A-Share Stock Pattern Predictor

基于时间序列分析的A股形态点预测系统 / Time-based sequence analysis for A-share stock landmark prediction

English | 中文


English

Overview

A-Share Stock Pattern Predictor is a web application that predicts WHEN landmark low/high points will occur using time-based sequence analysis. Unlike traditional technical analysis that focuses on price patterns, this system analyzes mathematical patterns in the timing of landmark points.

Features

  • Multi-layer Landmark Detection: 4-layer progressive filtering system

    • Layer 1: ZigZag algorithm for initial pivot detection
    • Layer 2: Statistical confirmation (frequency & deviation filters)
    • Layer 3: Trend strength filtering
    • Layer 4: Time interval validation
  • Pattern Recognition: Identifies arithmetic and geometric patterns in landmark timing

  • Bilingual Interface: Full support for English and Chinese

  • Real-time Analysis: FastAPI backend with responsive frontend

  • Interactive Charts: Chart.js visualization with landmark annotations

Tech Stack

Backend:

  • Python 3.10+
  • FastAPI
  • pandas, numpy
  • scikit-learn
  • matplotlib

Frontend:

  • HTML5, JavaScript (Vanilla)
  • Bootstrap 5
  • Chart.js 4.4.0

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ashare_predict.git
cd ashare_predict
  1. Create virtual environment:
conda create -n ashare python=3.10
conda activate ashare
  1. Install dependencies:
pip install -r requirements.txt
  1. Prepare stock database:
# 更新股票基本信息数据库
python -m scripts.update_stock_db

# 数据会自动从行情平台获取并缓存到本地SQLite数据库
# 首次运行会建立股票代码列表
  1. Run the application:
cd web
python -m uvicorn app:app --host 0.0.0.0 --port 8000 --reload
  1. Open browser:
http://localhost:8000

Usage

  1. Search Stock: Enter stock code (6 digits), pinyin, or name
  2. View Prediction: Click "分析" to see pattern prediction
  3. Detailed Analysis: Click "查看完整分析" for full chart and landmark details
  4. Adjust Parameters: Use multi-layer filter panel to fine-tune detection

Project Structure

ashare_predict/
├── core/                   # Core analysis modules
│   ├── data_loader.py      # Data loading and preprocessing
│   ├── zigzag.py           # ZigZag algorithm implementation
│   ├── pattern_detector.py # Pattern recognition engine
│   └── multi_layer_detector.py # Multi-layer filtering
├── web/                    # Web application
│   ├── app.py              # FastAPI application
│   ├── templates/          # HTML templates
│   └── static/             # CSS, JS, images
├── data/                   # Data directory
│   ├── stocks.json         # Stock info (code/name/pinyin)
│   └── stock_cache.db      # Local SQLite cache (auto-generated)
├── scripts/                # Utility scripts
│   └── update_stock_db.py  # Update stock database
├── requirements.txt        # Python dependencies
└── README.md              # This file

Data Source

The system automatically fetches stock data from:

  • Real-time API: Fetches weekly/daily OHLCV data on demand
  • Local Cache: SQLite database caches fetched data for performance
  • Stock Database: stocks.json contains basic stock information

API Endpoints

  • GET / - Homepage
  • GET /analysis/{symbol} - Stock analysis page
  • GET /api/predict?symbol={code} - Get prediction
  • GET /api/analyze?symbol={code}&threshold={val}&include_secondary={bool} - Get full analysis
  • GET /api/stocks/search?q={query} - Search stocks
  • POST /api/multi-layer-detect - Run multi-layer detection with custom parameters

Default Parameters

Optimized parameters based on testing:

  • Layer 1 Threshold: 10%
  • Layer 2 Min Frequency: 2
  • Layer 2 Min Deviation: 20%
  • Layer 3 Trend Strength: 0.50
  • Layer 4 Same Type Interval: 10 weeks
  • Layer 4 Alternating Interval: 4 weeks

Disclaimer

⚠️ This is NOT Financial Advice

This tool is for educational and research purposes only. Past patterns do not guarantee future results. Always do your own research and consult a qualified financial advisor before making investment decisions.

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


中文

概述

A股形态预测系统是一个基于时间序列分析的Web应用,用于预测关键低点/高点出现的时间。与关注价格形态的传统技术分析不同,本系统分析形态点时机的数学规律。

功能特点

  • 多层地标点检测:4层渐进式过滤系统

    • 第1层:ZigZag算法初步检测转折点
    • 第2层:统计确认(频率和偏离度过滤)
    • 第3层:趋势强度过滤
    • 第4层:时间间隔验证
  • 模式识别:识别地标点时机中的算术和几何规律

  • 双语界面:完整支持中英文

  • 实时分析:FastAPI后端,响应式前端

  • 交互式图表:Chart.js可视化,带地标点标注

技术栈

后端:

  • Python 3.10+
  • FastAPI
  • pandas, numpy
  • scikit-learn
  • matplotlib

前端:

  • HTML5, JavaScript (原生)
  • Bootstrap 5
  • Chart.js 4.4.0

安装步骤

  1. 克隆仓库:
git clone https://github.com/yourusername/ashare_predict.git
cd ashare_predict
  1. 创建虚拟环境:
conda create -n ashare python=3.10
conda activate ashare
  1. 安装依赖:
pip install -r requirements.txt
  1. 准备股票数据库:
# 更新股票基本信息数据库
python -m scripts.update_stock_db

# 数据会自动从行情平台获取并缓存到本地SQLite数据库
# 首次运行会建立股票代码列表
  1. 运行应用:
cd web
python -m uvicorn app:app --host 0.0.0.0 --port 8000 --reload
  1. 打开浏览器:
http://localhost:8000

数据源

系统自动从以下来源获取股票数据:

  • 实时API: 按需获取周线/日线OHLCV数据
  • 本地缓存: SQLite数据库缓存已获取数据,提高性能
  • 股票数据库: stocks.json 包含股票基本信息

使用方法

  1. 搜索股票:输入股票代码(6位数字)、拼音或名称
  2. 查看预测:点击"分析"按钮查看形态预测
  3. 详细分析:点击"查看完整分析"查看完整图表和地标点详情
  4. 调整参数:使用多层过滤控制面板微调检测参数

项目结构

ashare_predict/
├── core/                   # 核心分析模块
│   ├── data_loader.py      # 数据加载和预处理
│   ├── zigzag.py           # ZigZag算法实现
│   ├── pattern_detector.py # 模式识别引擎
│   └── multi_layer_detector.py # 多层过滤系统
├── web/                    # Web应用
│   ├── app.py              # FastAPI应用
│   ├── templates/          # HTML模板
│   └── static/             # CSS、JS、图片
├── data/                   # 数据目录
│   ├── stocks.json         # 股票基本信息 (代码/名称/拼音)
│   └── stock_cache.db      # 本地SQLite缓存 (自动生成)
├── scripts/                # 辅助脚本
│   └── update_stock_db.py  # 更新股票数据库
├── requirements.txt        # Python依赖
└── README.md              # 本文件

API接口

  • GET / - 首页
  • GET /analysis/{symbol} - 股票分析页面
  • GET /api/predict?symbol={code} - 获取预测
  • GET /api/analyze?symbol={code}&threshold={val}&include_secondary={bool} - 获取完整分析
  • GET /api/stocks/search?q={query} - 搜索股票
  • POST /api/multi-layer-detect - 使用自定义参数运行多层检测

默认参数

基于测试优化的默认参数:

  • 第1层阈值:10%
  • 第2层最小频率:2
  • 第2层最小偏离:20%
  • 第3层趋势强度:0.50
  • 第4层同类型间隔:10周
  • 第4层交替间隔:4周

免责声明

⚠️ 这不是投资建议

本工具仅供教育和研究目的。过去的规律不能保证未来的结果。在做出投资决策前,务必自行研究并咨询合格的专业理财顾问。

许可证

MIT License

贡献

欢迎贡献!请随时提交 Pull Request。


Developed with ❤️ for A-share market analysis

About

基于时间序列分析的A股形态点预测系统 / Time-based sequence analysis for A-share stock landmark prediction

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors