# How to Run the Daily Stock Analysis Script: Complete Setup and Usage Guide

> Learn how to run the daily stock analysis script with our easy setup guide. Install dependencies, configure API keys, and execute python main.py for your stock analysis.

- Repository: [mumu/daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis)
- Tags: how-to-guide
- Published: 2026-04-30

---

**Execute `python main.py` from the repository root after installing dependencies with `pip install -r requirements.txt` and configuring the required API keys and stock list in a `.env` file.**

The daily stock analysis system from the ZhuLinsen/daily_stock_analysis repository provides automated equity analysis through a command-line interface centered on [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py). This Python application orchestrates data fetching, AI-powered analysis via the `StockAnalysisPipeline`, and multi-channel notifications through a flexible execution architecture. Whether you need a one-time market scan or scheduled daily reports, the script supports multiple execution modes controlled via the `parse_arguments` function.

## Prerequisites and Configuration

Before executing the script, you must install dependencies and configure environment variables that the [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) module loads at startup.

### Install Python Dependencies

The system requires **Python 3.10 or higher**. Install the required packages using the provided requirements file:

```bash
pip install -r requirements.txt

```

The [`requirements.txt`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/requirements.txt) includes core dependencies such as `pypinyin`, `openpyxl`, `imgkit`, and `litellm`. For testing environments, use [`requirements-ci.txt`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/requirements-ci.txt) which adds test-only packages.

### Configure the Environment File

Copy the example environment file and populate mandatory variables:

```bash
cp .env.example .env

```

Edit `.env` to include at minimum:
- **`STOCK_LIST`**: Comma-separated stock codes (e.g., `600519,300750,AAPL`)
- **One LLM API key**: `GEMINI_API_KEY`, `OPENAI_API_KEY`, or `AIHUBMIX_KEY`
- **One notification channel**: `WECHAT_WEBHOOK_URL`, `FEISHU_WEBHOOK_URL`, or `EMAIL_SENDER` paired with `EMAIL_PASSWORD`

The [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) module validates these variables during the bootstrap phase described in [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py) lines 13-16.

## Basic One-Shot Execution

The simplest invocation runs the full analysis pipeline immediately. According to the implementation in [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py), the `parse_arguments` function (lines 24-38) processes CLI flags before initializing the `StockAnalysisPipeline` in [`src/core/pipeline.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/pipeline.py).

### Run Full Analysis

Execute the complete workflow including per-stock analysis and market review:

```bash
python main.py

```

This loads the configuration, initializes logging via [`src/logging_config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/logging_config.py), fetches data for all stocks in `STOCK_LIST`, runs AI analysis, and sends notifications through the configured channels.

### Common Execution Flags

Tailor the execution using these parameters defined in the argument parser:

- **`--dry-run`**: Pull market data only, skipping AI analysis and notifications
- **`--stocks 600519,000001`**: Override `STOCK_LIST` to analyze only specific codes
- **`--no-notify`**: Execute analysis without sending push notifications
- **`--debug`**: Enable verbose debug logging via the logging configuration module

Example with multiple flags:

```bash
python main.py --dry-run --stocks hk00700,600519 --debug

```

## Advanced Execution Modes

The script supports specialized modes for specific workflow requirements, each handled by dedicated modules under `src/core/`.

### Market Review Only

Skip individual stock analysis and run only the market review pipeline implemented in [`src/core/market_review.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/market_review.py):

```bash
python main.py --market-review

```

This mode generates aggregated market commentary without processing individual equity positions.

### Scheduled Daily Runs

Enable the built-in scheduler to automate execution. The scheduler block in [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py) (lines 92-99) handles the timing logic:

```bash
python main.py --schedule

```

By default, this runs immediately, then schedules daily execution at 18:00. To start the scheduler without an immediate run:

```bash
python main.py --schedule --no-run-immediately

```

The scheduler re-reads `STOCK_LIST` before each execution, allowing dynamic modification of the watchlist without restarting the process. Control concurrency using the `--workers` flag (e.g., `--workers 5` for five concurrent threads).

### Web UI and API Server

Launch the FastAPI interface and optional React frontend:

```bash
python main.py --serve        # Start server and run analysis once

python main.py --serve-only   # Start server without running analysis

```

The [`src/webui_frontend.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/webui_frontend.py) module prepares static assets before the server binds to `0.0.0.0:8000`. Combine with scheduling to run the API and background analyzer simultaneously:

```bash
python main.py --serve --schedule --no-run-immediately

```

## Docker Deployment

For production environments, the repository provides containerized services defined in [`docker/docker-compose.yml`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/docker/docker-compose.yml). The configuration defines two distinct services:

- **`server`**: Runs the FastAPI web interface using `--serve-only`
- **`analyzer`**: Runs the scheduler using `--schedule`

### Quick Start with Docker Compose

```bash
docker-compose -f ./docker/docker-compose.yml up -d

```

This builds the multi-stage image defined in `docker/Dockerfile` and starts both services. Mount volumes for `.env`, `data`, `logs`, and `reports` to persist configuration and output between container restarts.

Run services individually:

```bash
docker-compose -f ./docker/docker-compose.yml up -d server    # API only

docker-compose -f ./docker/docker-compose.yml up -d analyzer  # Scheduler only

```

## Summary

- **Entry point**: All execution paths flow through [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py), which delegates to [`src/core/pipeline.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/pipeline.py) for analysis logic.
- **Configuration**: Mandatory variables reside in `.env`, loaded by [`src/config.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/config.py) at startup.
- **Execution modes**: Choose from one-shot analysis (`python main.py`), scheduled runs (`--schedule`), or API server mode (`--serve`).
- **Docker**: Use [`docker/docker-compose.yml`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/docker/docker-compose.yml) to deploy persistent `server` and `analyzer` services.
- **Customization**: Override stock lists with `--stocks`, suppress notifications with `--no-notify`, or test connectivity with `--dry-run`.

## Frequently Asked Questions

### What Python version is required to run the daily stock analysis script?

The system requires **Python 3.10 or higher**. This ensures compatibility with the type hints and async features used in [`src/core/pipeline.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/src/core/pipeline.py) and the FastAPI web interface.

### How do I run the script without sending notifications to my configured channels?

Add the **`--no-notify`** flag to any execution command. This runs the full analysis pipeline including AI generation but skips the final notification dispatch step, allowing you to review results in the logs or output files only.

### Can I analyze specific stocks instead of the entire list defined in `.env`?

Yes. Use the **`--stocks`** flag followed by comma-separated codes to override the `STOCK_LIST` environment variable for that execution. For example: `python main.py --stocks 600519,300750` analyzes only those two securities regardless of your `.env` configuration.

### How do I run the script continuously as a daily automated service?

Use the **`--schedule`** flag combined with **`--no-run-immediately`** to start the background scheduler without executing an immediate analysis. The scheduler, implemented in [`main.py`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/main.py) lines 92-99, triggers runs daily at 18:00 UTC. For containerized deployments, use the `analyzer` service in [`docker/docker-compose.yml`](https://github.com/ZhuLinsen/daily_stock_analysis/blob/main/docker/docker-compose.yml) which wraps this scheduling mode.