> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reportify.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 因子选股

> 基于因子公式筛选股票

基于因子公式筛选股票，返回满足条件的股票列表。支持技术因子和基本面因子组合筛选。

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.reportify.cn/v1/quant/factors/screen \
    -H "Authorization: Bearer <token>" \
    -H "Content-Type: application/json" \
    -d '{
      "market": "cn",
      "formula": "RSI(14) < 30",
      "check_date": "2026-01-08"
    }'
  ```

  ```python Python theme={null}
  import requests

  # 全市场筛选 RSI 超卖股票
  response = requests.post(
      "https://api.reportify.cn/v1/quant/factors/screen",
      headers={"Authorization": "Bearer <token>"},
      json={
          "market": "cn",
          "formula": "RSI(14) < 30",
          "check_date": "2026-01-08"
      }
  )
  print(response.json())
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch('https://api.reportify.cn/v1/quant/factors/screen', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <token>',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      market: 'cn',
      formula: 'RSI(14) < 30',
      check_date: '2026-01-08'
    })
  });
  ```
</CodeGroup>

## 请求参数

<ParamField body="market" type="string" default="cn">
  股票市场：`cn`（A股）, `hk`（港股）, `us`（美股）
</ParamField>

<ParamField body="formula" type="string" required>
  筛选公式，返回布尔值或数值
</ParamField>

<ParamField body="check_date" type="string">
  检查日期，格式：`YYYY-MM-DD`（默认：最新交易日）
</ParamField>

<ParamField body="symbols" type="string[]">
  股票代码列表（可选，不传则为全市场筛选）
</ParamField>

## 公式示例

### 技术面筛选

| 公式                                                                                            | 描述                 |
| --------------------------------------------------------------------------------------------- | ------------------ |
| `RSI(14) < 30`                                                                                | RSI 超卖             |
| `CROSS(MA(CLOSE, 5), MA(CLOSE, 10))`                                                          | 均线金叉（MA5 上穿 MA10）  |
| `CROSSDOWN(MA(CLOSE, 5), MA(CLOSE, 10))`                                                      | 均线死叉（MA5 下穿 MA10）  |
| `(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))`                                   | 多头趋势               |
| `CLOSE > BOLL(20, 2).upper`                                                                   | 突破布林带上轨            |
| `(KDJ().j < 20) & (CROSS(KDJ().k, KDJ().d))`                                                  | KDJ 低位金叉           |
| `MACD().dif > MACD().dea`                                                                     | MACD 多头            |
| `CLOSE > REF(CLOSE, 1) * 1.05`                                                                | 较昨日涨幅超 5%          |
| `CLOSE > HHV(HIGH, 20)`                                                                       | 创 20 日新高           |
| `COUNT(CLOSE > REF(CLOSE, 1), 5) >= 4`                                                        | 近 5 日至少 4 天上涨      |
| `EVERY(CLOSE > REF(CLOSE, 1), 3)`                                                             | 连续 3 天上涨           |
| `(CLOSE > MA(CLOSE, 10)) & (MA(CLOSE, 10) > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))` | 多均线多头排列            |
| `(MA(CLOSE, 10) > REF(MA(CLOSE, 10), 5)) & (MA(CLOSE, 20) > REF(MA(CLOSE, 20), 5))`           | 均线向上发散             |
| `VOLUME > MA(VOLUME, 20) * 2`                                                                 | 成交量放大（2 倍于 20 日均量） |

### 基本面筛选

| 公式                                              | 描述            |
| ----------------------------------------------- | ------------- |
| `PE() < 15`                                     | 低市盈率          |
| `PE_TTM() < 20`                                 | 市盈率（TTM）低于 20 |
| `PB() < 1`                                      | 破净股（市净率低于 1）  |
| `ROE() > 0.15`                                  | ROE 大于 15%    |
| `(PE() < 20) & (ROE() > 0.1)`                   | 价值 + 质量       |
| `(PE_TTM() < 15) & (PB() < 2) & (ROE() > 0.12)` | 多因子价值筛选       |
| `REVENUE_GROWTH_RATE() > 0.2`                   | 营收增长率大于 20%   |
| `NET_PROFIT_GROWTH_RATE() > 0.3`                | 净利润增长率大于 30%  |
| `CURRENT_RATIO() > 2`                           | 流动性充足         |
| `DEBT_TO_EQUITY_RATIO() < 0.5`                  | 低杠杆           |
| `GPM() > 0.3`                                   | 毛利率大于 30%     |

### 技术面 + 基本面组合

| 公式                                                    | 描述        |
| ----------------------------------------------------- | --------- |
| `(PE() < 20) & (RSI(14) < 40)`                        | 便宜 + 超卖   |
| `(ROE() > 0.12) & (CLOSE > MA(CLOSE, 20))`            | 质量 + 上涨趋势 |
| `(PB() < 1.5) & (CROSS(MA(CLOSE, 5), MA(CLOSE, 20)))` | 价值 + 金叉   |

### 股票属性筛选

| 公式                                                       | 描述              |
| -------------------------------------------------------- | --------------- |
| `LISTING_DATE >= '2020-01-01'`                           | 2020 年后上市的次新股   |
| `(LISTING_DATE >= '2019-01-01') & IS_CHAIN_STAR()`       | 科创板次新股          |
| `IS_CHAIN_MAIN() & (IS_ST() == 0)`                       | 主板非 ST 股票       |
| `IS_CHAIN_CHINEXT() & (LISTING_DATE >= '2023-01-01')`    | 创业板近三年上市股票      |
| `(LISTING_DATE >= '2024-01-01') & (CLOSE < ISSUE_PRICE)` | 破发的次新股（现价低于发行价） |

## 运算符

| 类型  | 运算符                              | 说明     |
| --- | -------------------------------- | ------ |
| 比较  | `>`, `<`, `>=`, `<=`, `==`, `!=` | 数值比较   |
| 逻辑与 | `&` 或 `AND`                      | 大小写不敏感 |
| 逻辑或 | `\|` 或 `OR`                      | 大小写不敏感 |
| 逻辑非 | `~` 或 `NOT`                      | 大小写不敏感 |
| 算术  | `+`, `-`, `*`, `/`               | 四则运算   |

## 支持的变量

| 变量             | 别名         | 描述                                 |
| -------------- | ---------- | ---------------------------------- |
| `CLOSE`        | `C`        | 收盘价                                |
| `OPEN`         | `O`        | 开盘价                                |
| `HIGH`         | `H`        | 最高价                                |
| `LOW`          | `L`        | 最低价                                |
| `VOLUME`       | `V`, `VOL` | 成交量                                |
| `AMOUNT`       | -          | 成交额                                |
| `LISTING_DATE` | -          | 上市日期（`YYYY-MM-DD` 字符串，可直接与日期字符串比较） |
| `ISSUE_PRICE`  | -          | IPO 发行价                            |

## 支持的函数

| 级别          | 函数                                                                                  |
| ----------- | ----------------------------------------------------------------------------------- |
| Level 0     | `MA`, `EMA`, `SMA`, `REF`, `HHV`, `LLV`, `STD`, `SUM`, `ABS`, `MAX`, `MIN`, `IF`... |
| Level 1     | `CROSS`, `CROSSDOWN`, `COUNT`, `EVERY`, `EXIST`, `BARSLAST`...                      |
| Level 2 技术  | `RSI`, `MACD`, `BOLL`, `KDJ`, `WR`, `ATR`, `CCI`, `BIAS`, `PSY`...                  |
| Level 2 基本面 | `PE()`, `PB()`, `PS()`, `ROE()`, `ROA()`, `EPS()`, `BPS()`, `CURRENT_RATIO()`...    |

## 响应参数

<ResponseField name="datas" type="ScreenedStock[]">
  通过筛选的股票列表

  <Expandable title="ScreenedStock 字段">
    <ResponseField name="symbol" type="string">
      股票代码
    </ResponseField>

    <ResponseField name="close" type="number">
      检查日收盘价
    </ResponseField>

    <ResponseField name="factor_value" type="number | boolean">
      因子值（如适用）
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="metadata" type="object">
  筛选元数据
</ResponseField>

## 响应示例

### 全市场筛选

```json theme={null}
{
  "datas": [
    {
      "symbol": "000001",
      "close": 12.35,
      "factor_value": 28.5
    },
    {
      "symbol": "002142",
      "close": 8.92,
      "factor_value": 25.3
    },
    {
      "symbol": "600036",
      "close": 35.68,
      "factor_value": 29.8
    }
  ],
  "metadata": {
    "formula": "RSI(14) < 30",
    "market": "cn",
    "check_date": "2026-01-08",
    "total_screened": 3,
    "total_universe": 5000
  }
}
```

### 指定股票池筛选

请求：

```python theme={null}
response = requests.post(
    "https://api.reportify.cn/v1/quant/factors/screen",
    headers={"Authorization": "Bearer <token>"},
    json={
        "market": "cn",
        "formula": "(RSI(14) < 30) & (CLOSE > MA(CLOSE, 20))",
        "symbols": ["000001", "000002", "000003", "600519"]
    }
)
```

响应：

```json theme={null}
{
  "datas": [
    {
      "symbol": "000001",
      "close": 12.35,
      "factor_value": true
    }
  ],
  "metadata": {
    "formula": "(RSI(14) < 30) & (CLOSE > MA(CLOSE, 20))",
    "market": "cn",
    "check_date": "2026-01-10",
    "total_screened": 1,
    "total_universe": 4
  }
}
```


## OpenAPI

````yaml POST /v1/quant/factors/screen
openapi: 3.1.0
info:
  title: Reportify API
  version: 1.0.0
  description: API documentation for Reportify's document management and search services.
servers:
  - url: https://api.reportify.cn
    description: Production server
security:
  - BearerAuth: []
paths:
  /v1/quant/factors/screen:
    post:
      tags:
        - openapi-quant
      summary: Screen stocks by factor
      description: >
        Screen stocks based on factor formula.


        Returns stocks where the formula evaluates to True (for boolean
        formulas)

        or non-null (for numeric formulas).


        **Variables vs Functions:**

        - Variables (no parentheses): `CLOSE`, `OPEN`, `HIGH`, `LOW`, `VOLUME`,
        `AMOUNT` (aliases: `C`, `O`, `H`, `L`, `V`, `VOL`)

        - Functions (with parentheses): `MA(CLOSE, 20)`, `RSI(14)`, `PE()`,
        `ROE()`, etc.

        - Rule: Technical indicators and fundamental factors are functions, need
        `()`


        **Technical Screening Examples:**

        - `RSI(14) < 30` - RSI oversold

        - `CROSS(MA(CLOSE, 5), MA(CLOSE, 10))` - Golden cross (MA5 crosses above
        MA10)

        - `CROSSDOWN(MA(CLOSE, 5), MA(CLOSE, 10))` - Death cross (MA5 crosses
        below MA10)

        - `(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))` - Uptrend
        with MA alignment

        - `CLOSE > BOLL(20, 2).upper` - Above upper Bollinger Band

        - `(KDJ().j < 20) & (CROSS(KDJ().k, KDJ().d))` - KDJ low golden cross

        - `MACD().dif > MACD().dea` - MACD bullish

        - `CLOSE > REF(CLOSE, 1) * 1.05` - Up more than 5% from yesterday

        - `CLOSE > HHV(HIGH, 20)` - New 20-day high

        - `COUNT(CLOSE > REF(CLOSE, 1), 5) >= 4` - Up at least 4 of last 5 days

        - `EVERY(CLOSE > REF(CLOSE, 1), 3)` - Up 3 consecutive days

        - `(CLOSE > MA(CLOSE, 10)) & (MA(CLOSE, 10) > MA(CLOSE, 20)) &
        (MA(CLOSE, 20) > MA(CLOSE, 60))` - Multi-MA bullish

        - `(MA(CLOSE, 10) > REF(MA(CLOSE, 10), 5)) & (MA(CLOSE, 20) >
        REF(MA(CLOSE, 20), 5))` - MA trending up

        - `VOLUME > MA(VOLUME, 20) * 2` - Volume spike (2x 20-day average)


        **Fundamental Screening Examples (all need parentheses):**

        - `PE() < 15` - Low P/E stocks

        - `PE_TTM() < 20` - P/E TTM under 20

        - `PB() < 1` - Price below book value

        - `ROE() > 0.15` - ROE greater than 15%

        - `(PE() < 20) & (ROE() > 0.1)` - Value + quality

        - `(PE_TTM() < 15) & (PB() < 2) & (ROE() > 0.12)` - Multi-factor value
        screening

        - `REVENUE_GROWTH_RATE() > 0.2` - Revenue growth > 20%

        - `NET_PROFIT_GROWTH_RATE() > 0.3` - Net profit growth > 30%

        - `CURRENT_RATIO() > 2` - Strong liquidity

        - `DEBT_TO_EQUITY_RATIO() < 0.5` - Low leverage

        - `GPM() > 0.3` - Gross profit margin > 30%


        **Combined Technical + Fundamental:**

        - `(PE() < 20) & (RSI(14) < 40)` - Cheap + oversold

        - `(ROE() > 0.12) & (CLOSE > MA(CLOSE, 20))` - Quality + uptrend

        - `(PB() < 1.5) & (CROSS(MA(CLOSE, 5), MA(CLOSE, 20)))` - Value + golden
        cross


        **Supported Operators:**

        - Comparison: `>`, `<`, `>=`, `<=`, `==`, `!=`

        - Logical: `&` or `AND`, `|` or `OR`, `~` or `NOT` (case-insensitive)

        - Arithmetic: `+`, `-`, `*`, `/`

        - **Important: expressions on both sides of logical operators
        (`&`/`|`/`AND`/`OR`) must be wrapped in parentheses `()`**


        **Supported Variables (no parentheses):**

        - `CLOSE`, `C` - Close price

        - `OPEN`, `O` - Open price

        - `HIGH`, `H` - High price

        - `LOW`, `L` - Low price

        - `VOLUME`, `V`, `VOL` - Volume

        - `AMOUNT` - Amount


        **Supported Functions (TongDaXin style: col first, n second):**

        - Level 0: MA(col, n), EMA(col, n), SMA(col, n, m), REF(col, n),
        HHV(col, n), LLV(col, n), STD(col, n), SUM(col, n), ABS(), MAX(), MIN(),
        IF()...

        - Level 1: CROSS(), CROSSDOWN(), COUNT(), EVERY(), EXIST(),
        BARSLAST()...

        - Level 2 Technical: RSI(), MACD(), BOLL(), KDJ(), WR(), ATR(), CCI(),
        BIAS(), PSY()...

        - Level 2 Fundamental: PE(), PB(), PS(), ROE(), ROA(), EPS(), BPS(),
        CURRENT_RATIO()...
      operationId: factors_screen
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FactorScreenInput'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FactorScreenOutput'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    FactorScreenInput:
      type: object
      required:
        - formula
      properties:
        market:
          $ref: '#/components/schemas/StockMarket'
          description: Stock market
          default: cn
        formula:
          type: string
          title: Formula
          description: Screening formula (required)
        check_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Check Date
          description: 'Check date (optional, default: latest trading day)'
        symbols:
          anyOf:
            - type: array
              items:
                type: string
            - type: 'null'
          title: Symbols
          description: >-
            Stock code list, e.g., ["600519", "000001"] (optional, None = full
            market)
      title: FactorScreenInput
      description: Input for factor-based stock screening.
    FactorScreenOutput:
      type: object
      required:
        - datas
        - metadata
      properties:
        datas:
          type: array
          title: Datas
          description: List of stocks that passed the filter
          items:
            $ref: '#/components/schemas/ScreenedStock'
        metadata:
          type: object
          title: Metadata
          description: Screening metadata
          additionalProperties: true
      title: FactorScreenOutput
      description: Output for factor-based stock screening.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    StockMarket:
      type: string
      enum:
        - cn
        - hk
        - us
        - global
      title: StockMarket
      description: Stock market identifier
    ScreenedStock:
      type: object
      required:
        - symbol
        - close
      properties:
        symbol:
          type: string
          title: Symbol
          description: Stock code
        close:
          type: number
          title: Close
          description: Close price on check date
        factor_value:
          anyOf:
            - type: number
            - type: boolean
            - type: 'null'
          title: Factor Value
          description: Factor value (if applicable)
        indicators:
          anyOf:
            - type: object
              additionalProperties: true
            - type: 'null'
          title: Indicators
          description: Intermediate indicator values from formula
      title: ScreenedStock
      description: A stock that passed the screening filter.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your Bearer token

````