> ## 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 https://api.reportify.cn/v1/quant/factors \
    -H "Authorization: Bearer <token>"
  ```

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

  response = requests.get(
      "https://api.reportify.cn/v1/quant/factors",
      headers={"Authorization": "Bearer <token>"}
  )
  print(response.json())
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch('https://api.reportify.cn/v1/quant/factors', {
    headers: {
      'Authorization': 'Bearer <token>'
    }
  });
  const data = await response.json();
  ```
</CodeGroup>

## 请求参数

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

## 响应参数

返回 `FactorMeta[]` 数组，因子列表按 level 分类。

<Expandable title="FactorMeta 字段">
  <ResponseField name="name" type="string">
    因子名称，用于公式中
  </ResponseField>

  <ResponseField name="type" type="string">
    类型：`variable`（变量）或 `function`（函数）
  </ResponseField>

  <ResponseField name="level" type="integer">
    级别：0, 1 或 2
  </ResponseField>

  <ResponseField name="description" type="string">
    因子描述（中文）
  </ResponseField>

  <ResponseField name="description_en" type="string">
    因子描述（英文，可选）
  </ResponseField>

  <ResponseField name="fields" type="string[]">
    返回字段列表（多字段指标，如 MACD 返回 `["dif", "dea", "macd"]`）
  </ResponseField>
</Expandable>

## 响应示例

```json theme={null}
[
  {
    "name": "CLOSE",
    "type": "variable",
    "level": 0,
    "description": "收盘价"
  },
  {
    "name": "MA",
    "type": "function",
    "level": 0,
    "description": "简单移动平均"
  },
  {
    "name": "RSI",
    "type": "function",
    "level": 2,
    "description": "相对强弱指数"
  },
  {
    "name": "PE",
    "type": "function",
    "level": 2,
    "description": "市盈率（需括号调用：PE()）"
  }
]
```

## 技术因子（Level 0-2）

### Level 0 - 变量

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

### Level 0 - 股票属性函数

| 函数                   | 描述              | 示例                        |
| -------------------- | --------------- | ------------------------- |
| `IS_ST()`            | 是否为 ST 股票       | `IS_ST() == 0` 排除 ST      |
| `IS_LIMIT_UP()`      | 是否一字涨停          | `IS_LIMIT_UP() == 0`      |
| `IS_LIMIT_DOWN()`    | 是否一字跌停          | `IS_LIMIT_DOWN() == 0`    |
| `IS_CHAIN_MAIN()`    | 是否主板（60/000 开头） | `IS_CHAIN_MAIN() == 1`    |
| `IS_CHAIN_STAR()`    | 是否科创板（68 开头）    | `IS_CHAIN_STAR() == 1`    |
| `IS_CHAIN_CHINEXT()` | 是否创业板（30 开头）    | `IS_CHAIN_CHINEXT() == 1` |

### Level 0 - 基础函数 (TongDaXin 风格: col 在前, n 在后)

| 函数             | 描述        | 示例                       |
| -------------- | --------- | ------------------------ |
| `MA(X, N)`     | N 日简单移动平均 | `MA(CLOSE, 20)`          |
| `EMA(X, N)`    | N 日指数移动平均 | `EMA(CLOSE, 12)`         |
| `SMA(X, N, M)` | 平滑移动平均    | `SMA(CLOSE, 9, 1)`       |
| `REF(X, N)`    | 引用 N 天前的值 | `REF(CLOSE, 1)`          |
| `HHV(X, N)`    | N 周期最高值   | `HHV(HIGH, 20)`          |
| `LLV(X, N)`    | N 周期最低值   | `LLV(LOW, 20)`           |
| `STD(X, N)`    | N 周期标准差   | `STD(CLOSE, 20)`         |
| `SUM(X, N)`    | N 周期求和    | `SUM(VOLUME, 5)`         |
| `ABS(X)`       | 绝对值       | `ABS(CLOSE - OPEN)`      |
| `MAX(X, Y)`    | 取最大值      | `MAX(CLOSE, OPEN)`       |
| `MIN(X, Y)`    | 取最小值      | `MIN(CLOSE, OPEN)`       |
| `IF(C, A, B)`  | 条件选择      | `IF(CLOSE > OPEN, 1, 0)` |

### Level 1 - 应用函数

| 函数                | 描述                                                | 示例                                                                         |
| ----------------- | ------------------------------------------------- | -------------------------------------------------------------------------- |
| `CROSS(A, B)`     | A 上穿 B                                            | `CROSS(MA(CLOSE, 5), MA(CLOSE, 10))`                                       |
| `CROSSDOWN(A, B)` | A 下穿 B                                            | `CROSSDOWN(MA(CLOSE, 5), MA(CLOSE, 10))`                                   |
| `COUNT(X, N)`     | N 周期内满足条件的天数                                      | `COUNT(CLOSE > OPEN, 10)`                                                  |
| `EVERY(X, N)`     | N 周期内全部满足条件                                       | `EVERY(CLOSE > MA(CLOSE, 20), 5)`                                          |
| `EXIST(X, N)`     | N 周期内存在满足条件                                       | `EXIST(CLOSE > HHV(HIGH, 60), 5)`                                          |
| `BARSLAST(X)`     | 上次满足条件到现在的周期数                                     | `BARSLAST(CROSS(MA(CLOSE, 5), MA(CLOSE, 10)))`                             |
| `FIN_REF(expr)`   | 财务历史数据链式引用，支持 `.where(cond).shift(n).alias(name)` | `FIN_REF(INCOME.net_profit).where(INCOME.fiscal_quarter == "FY").shift(1)` |

### Level 2 - 技术指标

| 函数               | 描述       | 返回字段                    |
| ---------------- | -------- | ----------------------- |
| `RSI(N)`         | 相对强弱指数   | `rsi`                   |
| `MACD(S, L, M)`  | MACD 指标  | `dif`, `dea`, `macd`    |
| `KDJ(N, M1, M2)` | KDJ 随机指标 | `k`, `d`, `j`           |
| `BOLL(N, P)`     | 布林带      | `upper`, `mid`, `lower` |
| `WR(N)`          | 威廉指标     | `wr`                    |
| `ATR(N)`         | 平均真实波幅   | `atr`                   |
| `CCI(N)`         | 商品通道指数   | `cci`                   |
| `BIAS(N)`        | 乖离率      | `bias`                  |
| `PSY(N)`         | 心理线      | `psy`                   |

***

## 基本面因子（Level 2）

### 财务报表

通过 `.` 访问报表字段：

| 报表             | 描述    | 示例                            |
| -------------- | ----- | ----------------------------- |
| `INCOME`       | 利润表   | `INCOME.net_profit`           |
| `BALANCESHEET` | 资产负债表 | `BALANCESHEET.total_assets`   |
| `CASHFLOW`     | 现金流量表 | `CASHFLOW.operating_cashflow` |
| `EQUITY`       | 股东权益表 | `EQUITY.total_equity`         |

### 盈利能力

| 因子       | 描述      |
| -------- | ------- |
| `ROE()`  | 净资产收益率  |
| `ROA()`  | 总资产收益率  |
| `GPM()`  | 毛利率     |
| `NPM()`  | 净利率     |
| `ROIC()` | 投入资本回报率 |

### 估值因子

| 因子         | 描述       |
| ---------- | -------- |
| `PE()`     | 市盈率      |
| `PE_TTM()` | 市盈率（TTM） |
| `PB()`     | 市净率      |
| `PS()`     | 市销率      |
| `PCF()`    | 市现率      |
| `EV()`     | 企业价值     |
| `PEG()`    | PEG 比率   |

### 偿债能力

| 因子                | 描述    |
| ----------------- | ----- |
| `CURRENT_RATIO()` | 流动比率  |
| `QUICK_RATIO()`   | 速动比率  |
| `DEBT_RATIO()`    | 资产负债率 |

### 成长能力

| 因子                         | 描述      |
| -------------------------- | ------- |
| `REVENUE_GROWTH_RATE()`    | 营收增长率   |
| `NET_PROFIT_GROWTH_RATE()` | 净利润增长率  |
| `EPS_GROWTH_RATE()`        | EPS 增长率 |

### 运营能力

| 因子                           | 描述       |
| ---------------------------- | -------- |
| `INVENTORY_TURNOVER()`       | 存货周转率    |
| `ACCOUNTS_RECEIVABLE_DAYS()` | 应收账款周转天数 |
| `TOTAL_ASSET_TURNOVER()`     | 总资产周转率   |

### 每股指标

| 因子                    | 描述      |
| --------------------- | ------- |
| `EPS()`               | 每股收益    |
| `BPS()`               | 每股净资产   |
| `OCFPS()`             | 每股经营现金流 |
| `REVENUE_PER_SHARE()` | 每股营收    |


## OpenAPI

````yaml GET /v1/quant/factors
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:
    get:
      tags:
        - openapi-quant
      summary: List available factors
      description: >
        List all available factors (variables and functions) for formula
        computation.


        **How to Use:**

        - `type="variable"`: Use directly without parentheses, e.g. `CLOSE`,
        `VOLUME`

        - `type="function"`: Call with parentheses, e.g. `MA(CLOSE, 20)`,
        `PE()`, `ROE()`


        **Technical Factors (Level 0-2):**

        - **Level 0 Variables** (no parentheses): `CLOSE`, `OPEN`, `HIGH`,
        `LOW`, `VOLUME`, `AMOUNT` and aliases

        - **Level 0 Functions** (TongDaXin style: col first, n second): `MA(col,
        n)`, `EMA(col, n)`, `REF(col, n)`, `HHV(col, n)`, `LLV(col, n)`,
        `STD(col, n)`, etc.

        - **Level 1 Functions** (need parentheses): `CROSS()`, `COUNT()`,
        `EVERY()`, etc.

        - **Level 2 Functions** (need parentheses): `MACD()`, `KDJ()`, `RSI()`,
        `BOLL()`, etc.


        **Fundamental Factors (Level 2, all need parentheses):**

        - **Data Accessors**: `INCOME.field`, `BALANCESHEET.field`,
        `CASHFLOW.field`, `EQUITY.field`

        - **Profitability**: `ROE()`, `ROA()`, `GPM()`, `NPM()`, `ROIC()`, etc.

        - **Valuation**: `PE()`, `PE_TTM()`, `PB()`, `PS()`, `PCF()`, `EV()`,
        `PEG()`, etc.

        - **Solvency**: `CURRENT_RATIO()`, `QUICK_RATIO()`, `DEBT_RATIO()`, etc.

        - **Growth**: `REVENUE_GROWTH_RATE()`, `NET_PROFIT_GROWTH_RATE()`,
        `EPS_GROWTH_RATE()`, etc.

        - **Operating**: `INVENTORY_TURNOVER()`, `ACCOUNTS_RECEIVABLE_DAYS()`,
        `TOTAL_ASSET_TURNOVER()`, etc.

        - **Per Share**: `EPS()`, `BPS()`, `OCFPS()`, `REVENUE_PER_SHARE()`,
        etc.


        Each factor includes:

        - `name`: Factor name for use in formulas

        - `type`: "variable" (no parentheses) or "function" (need parentheses)

        - `level`: 0, 1, or 2

        - `description`: Brief description (Chinese)

        - `description_en`: English description (optional)
      operationId: factors
      parameters:
        - name: market
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/StockMarket'
            default: cn
          description: Stock market (cn, hk, us), default cn
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: array
                title: Response List Factors
                items:
                  $ref: '#/components/schemas/FactorMeta'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    StockMarket:
      type: string
      enum:
        - cn
        - hk
        - us
        - global
      title: StockMarket
      description: Stock market identifier
    FactorMeta:
      type: object
      required:
        - name
        - type
        - level
        - description
      properties:
        name:
          type: string
          title: Name
          description: Factor name for use in formulas
        type:
          type: string
          title: Type
          description: '"variable" or "function"'
        level:
          type: integer
          title: Level
          description: 'Level: 0 (variable/core), 1 (application functions), 2 (indicators)'
        description:
          type: string
          title: Description
          description: Brief description in Chinese
        description_en:
          anyOf:
            - type: string
            - type: 'null'
          title: Description En
          description: Brief description in English (optional)
      title: FactorMeta
      description: Metadata for a factor (variable or function).
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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

````