Compound Filters

Compound filters combine other filter conditions into one. Use them when a screen needs more than one condition, or when the logic is more than a simple match.

Compound Operators

OperatorMeaning
andAll conditions must match.
orAt least one condition must match.
notNone of the conditions can match.

Each operator takes an array of conditions.

{
  "<operator>": [
    { "<dataPointA>": "<value>" },
    { "<dataPointB>": { "gt": "<value>" } }
  ]
}

Every element of the array is itself a filter condition. It can be an equality, text or comparison filter, or another compound filter.

Write the operators in lowercase.

Require All Conditions with And

The following query returns investments that have a 12-month yield in a range and a base currency of US dollars. Every condition must match.

"query": {
  "and": [
    {
      "yieldsHistorical.12MoYield": { "gt": 1.5, "lt": 10.55 }
    },
    {
      "basicReference.baseCurrency": "USD"
    }
  ]
}

Require Any Condition with Or

The following query returns investments that match the yield range, or have a base currency of US dollars, or both.

"query": {
  "or": [
    {
      "yieldsHistorical.12MoYield": { "gt": 1.5, "lt": 10.55 }
    },
    {
      "basicReference.baseCurrency": "USD"
    }
  ]
}

Exclude Conditions with Not

The not operator excludes investments that match its conditions. The following query returns investments whose 12-month yield isn't in the range and whose base currency isn't US dollars.

"query": {
  "not": [
    {
      "yieldsHistorical.12MoYield": { "gt": 1.5, "lt": 10.55 }
    },
    {
      "basicReference.baseCurrency": "USD"
    }
  ]
}

Nest Compound Filters

Compound filters can be nested to any level you need, so you can build complex logic. The following query returns investments that have either a recent portfolio date and a low risk score, or a high Morningstar Rating.

"query": {
  "or": [
    {
      "and": [
        {
          "basicReference.portfolioDate": { "gt": "2010-01-01", "lt": "2024-03-31" }
        },
        {
          "morningstarPortfolioRiskScore.portfolioRiskScore": { "lte": 25.555 }
        }
      ]
    },
    {
      "morningstarRatingHistorical.morningstarRatingOverall": { "gte": 4 }
    }
  ]
}

To read a nested filter, start at the outermost operator and work inward. Here, an investment is returned if it satisfies the inner and group, which needs both conditions, or if it satisfies the rating condition.

The following query combines and and or the other way round. It returns investments in one of two base currencies that also have a high rating and an inception date after a given day.

"query": {
  "and": [
    {
      "or": [
        { "basicReference.baseCurrency": "USD" },
        { "basicReference.baseCurrency": "CAD" }
      ]
    },
    {
      "morningstarRatingHistorical.morningstarRatingOverall": { "gte": 4 }
    },
    {
      "basicReference.inceptionDate": { "gt": "2010-01-01" }
    }
  ]
}

Use Compound Filters in the Scope

The scope uses the same syntax as the query, so it can also be a compound filter. When it is, each branch must contain the scoping data point, which for managed investments is basicReference.countryAvailableForSale.

The following scope covers two countries, with a different condition on each.

"scope": {
  "or": [
    {
      "and": [
        { "basicReference.countryAvailableForSale": "USA" },
        { "basicReference.baseCurrency": "USD" }
      ]
    },
    {
      "and": [
        { "basicReference.countryAvailableForSale": "GBR" },
        { "basicReference.baseCurrency": "GBP" }
      ]
    }
  ]
}

A branch without the scoping data point isn't a valid scope.

Tips

  • Use a compound filter whenever you combine conditions, even if only two. It makes the logic explicit.
  • Keep each element of the array to one condition. Group related conditions in a nested filter.
  • Check each data point's metadata to be sure it supports the operator in the condition. See Explore Data Points.