Content
# AI KLine - A-share Technical Analysis and AI Prediction Tool
## Project Introduction
AI KLine is a Python-based analysis tool for A-shares that combines traditional technical analysis with artificial intelligence prediction capabilities. It conducts comprehensive analysis and forecasting of stocks using candlestick charts, technical indicators, financial data, and news data. This tool can:
1. Retrieve historical volume and price data of A-share stocks and calculate various technical indicators.
2. Generate professional candlestick charts and visualizations of technical indicators.
3. Obtain financial data and news information related to stocks.
4. Use Google's Gemini AI model to analyze integrated data and predict future stock trends.
## Features
- **Data Retrieval**: Uses AKShare to obtain historical trading data, financial data, and news information for A-share stocks.
- **Technical Analysis**: Calculates various technical indicators, including MA, MACD, KDJ, RSI, Bollinger Bands, etc.
- **Visualization**: Generates static and interactive candlestick charts and technical indicator graphs.
- **AI Analysis**: Utilizes the Gemini AI model to analyze stock data and predict future trends.
- **Web Interface**: Provides a clean and aesthetically pleasing web interface for users to input stock codes and view analysis results.
- **MCP SERVER**: Offers MCP SERVER support, enabling interaction through LLM for real-time stock analysis.
## Installation Instructions
### Environment Requirements
- Python 3.8+
- Dependencies: See `requirements.txt`
### Installation Steps
1. Clone or download this project to your local machine.
2. Install the dependencies.
```bash
pip install -r requirements.txt
```
3. Create a `.env` file and add your Gemini API key.
```
GEMINI_API_KEY=your_api_key_here
```
> Note: To obtain a Gemini API key, you need to register and create an API key at [Google AI Studio](https://ai.google.dev/).
## Usage
### Command Line Usage
```bash
python main.py --stock_code 000001 --period 1 year --save_path ./output
```
Parameter Explanation:
- `--stock_code`: Stock code, required parameter.
- `--period`: Analysis period, optional values: "1 year", "6 months", "3 months", "1 month", default is "1 year".
- `--save_path`: Result save path, default is "./output".
### Web Interface Usage
Start the web service:
```bash
python web_app.py
```
Then access the web interface in your browser at http://localhost:5000:
1. Enter the stock code in the form (e.g., 000001).
2. Select the analysis period.
3. Click the "Start Analysis" button.
4. Wait for the analysis to complete and view the results.
The web interface includes the following content:
- Basic stock information.
- Candlestick charts and technical indicator graphs.
- AI analysis result text.
Screenshot of the page:

### MCP SERVER Usage
Start the MCP:
```bash
uv run mcp_server.py
```
Then configure in the MCP client (streamable-http):
http://localhost:8000/mcp
Screenshot of the Cherry-Studio page:


### Output Results
After running the program, the following will be generated in the specified save path:
1. Candlestick charts and technical indicator graphs (static PNG images and interactive HTML charts).
2. AI analysis result text files.
## Project Structure
```
AI KLine/
├── main.py # Main program entry
├── web_app.py # Web application entry
├── requirements.txt # List of dependencies
├── .env # Environment variable configuration (to be created by user)
├── modules/ # Functional modules
│ ├── __init__.py
│ ├── data_fetcher.py # Data retrieval module
│ ├── technical_analyzer.py # Technical analysis module
│ ├── visualizer.py # Visualization module
│ └── ai_analyzer.py # AI analysis module
├── templates/ # Web template directory
│ └── index.html # Home page template
├── static/ # Static resource directory
│ ├── css/ # CSS styles
│ │ └── style.css # Custom styles
│ └── js/ # JavaScript scripts
│ └── main.js # Main script
└── output/ # Output results directory (automatically created at runtime)
├── charts/ # Charts directory
└── *_analysis_result.txt # Analysis result files
```
## Communication and Learning

## Notes
- This tool is for learning and research purposes only and does not constitute any investment advice.
- AI analysis results are based on historical data and current information and cannot guarantee the accuracy of future trends.
- Please ensure that the Gemini API key is correctly configured before use.
- Stock data retrieval relies on the AKShare library, which may be subject to network and data source limitations.
- This project is an open-source project by QuantML. Please cite the source when reproducing or using it, and contact WeChat ID QuantML for commercial use.
## Disclaimer
The analysis and predictions provided by this tool are for reference only and do not constitute any investment advice. Investing involves risks, and caution is advised when entering the market. Users are responsible for their own investment decisions.