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

# Factor

> Build, validate, and analyze factors with TQX formula or Python code.

Factors turn market or financial data into a numeric signal that you can analyze, backtest, or use in a strategy.

## Choose a factor mode

### Formula mode

Use one complete expression per line. Formula mode supports nested operators and arithmetic expressions.

```text theme={null}
RANK(close / DELAY(close, 20) - 1)
```

Use lowercase names for fields and uppercase names for operators. Do not use assignments, imports, Python attributes, or `FUTURE_RETURNS` in a factor formula.

### Python mode

Use Python when your factor needs logic that is not practical as one expression. Define one class that inherits from `Factor` and return a `Series` from `calculate(self, factors)`.

```python theme={null}
class MomentumFactor(Factor):
    def calculate(self, factors):
        close = factors["close"]
        return close.groupby(level="symbol").transform(lambda s: s / s.shift(20) - 1)
```

## Continue

* [Operator reference](/research/factor/operator-reference): Browse all supported formula operators.
* [Market compatibility](/research/factor/operator-reference#market-compatibility): Check field and market restrictions.

<Warning>
  `FUTURE_RETURNS` is listed in some legacy formula references, but TQX rejects it in factors because it uses future data.
</Warning>
