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

# Expression reference

> Fields, operators, and functions for derived fields, filter, score, and weight expressions.

Construction rules are expressions. Tilt evaluates each expression once per security in the universe, as of the evaluation date. The syntax is Python-style arithmetic and comparison over named fields.

## Expression types

| Expression | Editor section  | Result per security | Use                                                              |
| ---------- | --------------- | ------------------- | ---------------------------------------------------------------- |
| Assignment | Derived fields  | Named values        | Defines names for later expressions.                             |
| Filter     | Selection rules | True or false       | Keeps securities where the result is true.                       |
| Score      | Selection rules | A number            | Ranks securities, highest first.                                 |
| Weight     | Position sizing | A number            | Sets relative position size. Tilt scales weights to sum to 100%. |

<Frame caption="Filter and score expressions in the Selection rules section. Tilt highlights field names.">
  <img src="https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=7f85d992265cff7aa411527f2e829f70" alt="Selection rules section with filter expression market_cap > 5000 and fcf_margin > 0.08, score expression 2 * revenue_growth_3y + roe, and maximum constituents 20" data-og-width="1006" width="1006" data-og-height="366" height="366" data-path="images/index-construction/rail-selection-rules.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=280&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=7c7d26fdbe207d9505a78fdce2435c3a 280w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=560&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=ee0e974be4cb91949eab6c9ce8937471 560w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=840&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=7834949e87d9c628747e034917b73277 840w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=1100&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=a1e150ffa7962b1ca1337950466a8995 1100w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=1650&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=1d8d4eb7b5fbcc943b67dde1ffc355cf 1650w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-selection-rules.png?w=2500&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=dfb7d4a3aaa2ed0c100ab99898544404 2500w" />
</Frame>

## Fields

A field is a named value for each security, such as `market_cap`, `pe`, or `roe`. The field catalog covers fundamentals, valuation, returns, liquidity, classification, and risk-model factor exposures. Tilt Agent can search the catalog for a field's exact name and show its distribution.

| Convention         | Detail                                                                                           | Example                                                                        |
| ------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| Units              | Each field has a unit in the catalog. `market_cap` is in millions of US dollars.                 | `market_cap > 5000` keeps companies worth more than \$5 billion.               |
| Risk-model factors | Standardized exposures with the `rm_` prefix. 0 is close to the market average.                  | `rm_momentum`, `rm_value`, `rm_quality`, `rm_volatility`, `rm_historical_beta` |
| Classification     | RBICS levels: `rbics_l1_id` for sector, `rbics_l2_id` for subsector, `rbics_l3_id` for industry. | `rbics_l3_id == 551020` selects Semiconductor Manufacturing.                   |

## Operators

| Kind       | Operators                         | Example                                   |
| ---------- | --------------------------------- | ----------------------------------------- |
| Arithmetic | `+` `-` `*` `/` `**`              | `2 * revenue_growth_3y + roe`             |
| Comparison | `>` `>=` `<` `<=` `==` `!=`       | `pe < 25`                                 |
| Logic      | `and` `or` `not`, or `&` `\|` `~` | `market_cap > 5000 and fcf_margin > 0.08` |
| Grouping   | `( )`                             | `(pe < 25) & (market_cap > 1000)`         |

Wrap each comparison in parentheses when you combine comparisons with `&` or `|`.

## Derived fields

An assignment expression names a value for reuse. Write one assignment per line:

```python theme={null}
quality = 2 * revenue_growth_3y + roe
size_basis = free_float_market_cap
```

Filter, score, and weight expressions can then use `quality` and `size_basis` like any other field. Tilt evaluates derived fields first.

<Frame>
  <img src="https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-derived-fields.png?fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=a5e784761fae1ce4e0ac022b95b55c05" alt="Derived fields section with two assignments: quality and size_basis" width="1006" height="234" data-path="images/index-construction/rail-derived-fields.png" />
</Frame>

## Functions

### Membership and exposure

These functions look up a value by name. They work in filter and score expressions only. A derived field or weight expression that calls one fails.

| Function             | Returns                                                        | Example                               |
| -------------------- | -------------------------------------------------------------- | ------------------------------------- |
| `index("<name>")`    | The security's point-in-time weight in a named index, or 0     | `index("S&P 500") > 0`                |
| `etf("<ticker>")`    | The security's point-in-time weight in an ETF's holdings, or 0 | `etf("QQQ") > 0`                      |
| `theme("<label>")`   | The company's exposure to a theme, or 0 with no evidence       | `theme("Nuclear Energy") >= 0.55`     |
| `feature("<id>")`    | A custom numeric feature shared with your organization         | `feature("momentum_composite") > 0.5` |
| `enrichment("<id>")` | A custom AI-scored column you created                          | `enrichment("moat_score") > 7`        |

`index()` accepts published Tilt index names and third-party index names. A third-party name resolves to the holdings of the largest ETF that tracks the index. Universe presets are a separate setting, in the Universe section.

`theme()` takes a theme in plain language, such as `"Nuclear Energy"` or `"Grid Modernization"`:

| Use                       | Expression                                                        |
| ------------------------- | ----------------------------------------------------------------- |
| Include exposed companies | `theme("Nuclear Energy") >= 0.55` in the filter                   |
| Exclude exposed companies | `theme("Fossil Fuels") < 0.55` in the filter                      |
| Rank and size by exposure | `theme("Nuclear Energy")` as the score, with no weight expression |

The score starts at 0 and has no fixed maximum. Companies with heavy exposure often score several points. Tilt's default cutoff is 0.55, and Tilt Agent uses it unless you name another threshold. Every share class of a company gets the same score. [Build a thematic Tilt](/index-construction/example-nuclear-energy) walks through a Tilt built with `theme()`.

### How theme() scores companies

Tilt matches the theme against several kinds of evidence for each company, including its SEC filings, financial news coverage, earnings calls, and analyst research. Tilt weights each source by how well it predicted relevance in testing, then combines them into one score. Every piece of evidence has a date, so a backtest sees only the evidence available on each historical date.

The [thematic scoring white paper](https://tilt.io/research/tilt-research-engine-whitepaper.pdf) documents the method, its sources, and its validation. Across 81 themes, companies it selected on held-out data averaged 8.36 out of 10 for relevance, as judged by a relevance grader that a blinded panel of portfolio managers and analysts validated.

Coverage is strongest for US-listed companies, since much of the evidence comes from SEC filings and English-language financial news. A company that has changed its business keeps its old filing description until its next annual report.

### Trailing-window statistics

These functions summarize a field over a window that ends on the evaluation date. They work in all four expression types.

| Function                  | Returns                          | Example                              |
| ------------------------- | -------------------------------- | ------------------------------------ |
| `avg(field, "window")`    | Mean                             | `avg(pe, "3m") > 20`                 |
| `median(field, "window")` | Median                           | `median(quick_ratio, "1y") > 1.5`    |
| `min(field, "window")`    | Lowest value                     | `min(operating_income, "3y") > 0`    |
| `max(field, "window")`    | Highest value                    | `market_cap / max(market_cap, "1y")` |
| `std(field, "window")`    | Standard deviation               | `std(gross_margin, "1y") < 0.05`     |
| `first(field, "window")`  | Value at the start of the window | `revenue > first(revenue, "1y")`     |

Write the field as a bare name and the window as a quoted string, such as `"3m"`, `"1y"`, or `"5y"`. Daily fields such as `market_cap` and `pe` support short windows. Quarterly fundamentals such as `revenue` update four times a year, so use windows of one year or more. `first()` accepts quarterly fundamentals only. The catalog lists the windows each field accepts.

## Validation

Tilt checks expressions as you type. An unknown field name disables **Apply changes** until you fix it.

<Frame>
  <img src="https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=d338efac04de21d5261cd394b25e7a30" alt="Filter expression market_cap > unknown_metric with the error: Unknown field 'unknown_metric'" data-og-width="1006" width="1006" data-og-height="422" height="422" data-path="images/index-construction/rail-validation-error.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=280&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=656d811a60bc35034010a7eb926e2bd3 280w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=560&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=1246983b99d0b85ce484d53b92cccb59 560w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=840&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=422a73b5bf23336023449e3fe70cd613 840w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=1100&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=205c8808c8ff796cfc4e619500dbd860 1100w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=1650&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=d09a6a6a260930d41cd959d30098d3ad 1650w, https://mintcdn.com/tilt/CizYNoSLp0Sv3sdD/images/index-construction/rail-validation-error.png?w=2500&fit=max&auto=format&n=CizYNoSLp0Sv3sdD&q=85&s=b4a922f04d3169092a1fc0eaba7f0135 2500w" />
</Frame>
