How guts-yang/stock_predictor works
Stock Predictor is an A-share forecasting product with Web and CLI entry points. The main workflow accepts a data, training, or prediction request; obtains market history; trains or loads an LSTM; and returns predictions, with separate analysis, visualization, and backtesting capabilities. The graph also preserves the documented selector and database-backed storage branches. Relationships are limited to source-index references, shown calls, or README statements; unsampled implementation details are not asserted.
Main entry points: stock_data.py Market data · train_stock_model.py Model training · predict_stock.py Prediction service · app.py Flask API
Components 30
User interfaces
- Flask API
backend/api/app.py - CLI
cli/main.py - Request schemas
backend/api/schemas.py - API responses
backend/api/_response.py - Data routes
backend/api/routes/data.py - Training routes
backend/api/routes/train.py - Prediction routes
backend/api/routes/predict.py - Backtest route
backend/api/routes/backtest.py - Chart interface
frontend/static/js/data-visualization.js - Painting interface
frontend/static/js/painting.js
Forecasting and data
- Market data
backend/core/stock_data.py - Data cache
backend/core/cache_manager.py - Model training
backend/services/train_stock_model.py - Sequence preparation
backend/core/stock_data.py - LSTM model
backend/core/stock_model.py - Prediction service
backend/services/predict_stock.py
Analysis and quant
- Financial charts
backend/services/financial_visualization.py - Stock selector
backend/services/stock_selector.py - Backtest engine
backend/quant/backtest/engine.py - Trading strategies
backend/quant/backtest/strategy.py - Factor scoring
backend/quant/factors/runner.py - Factor definitions
backend/quant/factors/base.py - Risk metrics
backend/quant/risk/metrics.py - Portfolio optimizer
backend/quant/portfolio/optimizer.py
Persistence
- Configuration
backend/core/config.py - DB connection
backend/core/database/connection.py - Data repositories
backend/core/database/repositories.py - Stored entities
backend/core/database/models.py
Other components
- User
- Tushare
Connections 41
- User → Flask API: uses web
README.md - User → CLI: uses CLI
README.md - Flask API → Data routes: registers routes
backend/api/app.py - Flask API → Training routes: registers routes
backend/api/app.py - Flask API → Prediction routes: registers routes
backend/api/app.py - Flask API → Backtest route: registers routes
- Data routes → Request schemas: validates with
backend/api/routes/data.py - Training routes → Request schemas: validates with
backend/api/routes/train.py - Prediction routes → Request schemas: validates with
backend/api/routes/predict.py - Backtest route → Request schemas: validates with
backend/api/routes/backtest.py - Data routes → Market data: fetches data
backend/api/routes/data.py - Training routes → Model training: starts training
backend/api/routes/train.py - Prediction routes → Prediction service: requests prediction
backend/api/routes/predict.py - Backtest route → Market data: fetches history
backend/api/routes/backtest.py - Backtest route → Backtest engine: runs engine
backend/api/routes/backtest.py - Backtest route → Factor scoring: computes factors
backend/api/routes/backtest.py - CLI → Model training: starts training
cli/main.py - CLI → Prediction service: requests prediction
cli/main.py - CLI → Stock selector: runs selection
cli/main.py - Model training → Market data: loads history
backend/services/train_stock_model.py - Market data → Data cache: checks cache
backend/core/stock_data.py - Market data → Tushare: fetches market data
backend/core/stock_data.py - Model training → LSTM model: trains model
backend/services/train_stock_model.py - Prediction service → Market data: loads history
backend/services/predict_stock.py - Prediction service → LSTM model: loads model
backend/services/predict_stock.py - Market data → DB connection: opens session
backend/core/stock_data.py - Market data → Data repositories: reads stored data
backend/core/stock_data.py - Model training → DB connection: opens session
backend/services/train_stock_model.py - Model training → Data repositories: stores model
backend/services/train_stock_model.py - Prediction service → DB connection: opens session
backend/services/predict_stock.py - Prediction service → Data repositories: loads model
backend/services/predict_stock.py - DB connection → Configuration: configures database
backend/core/database/connection.py - Data repositories → Stored entities: queries entities
backend/core/database/repositories.py - Backtest engine → Trading strategies: executes strategy
backend/quant/backtest/engine.py - Factor scoring → Factor definitions: uses definitions
backend/quant/factors/runner.py - Financial charts → Chart interface: provides chart capability
README.md - User → Financial charts: requests charts
README.md - User → Stock selector: requests screening
README.md - Backtest engine → Risk metrics: reports risk
- Portfolio optimizer → Risk metrics: uses risk metrics
- Painting interface → User: supports drawing