FILTER function spotlight

This document explains the syntax and various usage patterns of Vektor's powerful FILTER function. For a shorter summary with examples you could read our launch announcement here.

[insert video]

🧠
If you haven’t used VXL before, try our Quick Start Guide! You may also find it useful to first learn about VXL basics and Common Syntax Patterns, or book a call using the CALL function in the app to learn more.

Summary

Vektor's FILTER allows you to filter any list using an expression. It's a powerful way to process lists into highly curated selections. Use FILTER for a variety of use cases like a) discovering the best market opportunities, b) identifing wasted opportunities, c) preventing high-risk situations, and d) analyzing underperformances of your positions.

Vektor's FILTER function works with any List type in Vektor (e.g. PRICES, LP.POSITIONS, BALANCES, ASSETS, BORROW.MARKETS). You can filter on any conditional expression, giving ultimate control to find specific data using multiple parameters and combining different lists.

Function Specification

You can use FILTER  (without subfunctions) to filter any list.

Function Description
FILTER(...) Filter a list using an expression

FILTER(...) Syntax and Examples

Use FILTER() to set up a list and a conditional expression for the filter. The required parameters are a list to filter, and a conditional expression.

⚠️
Note: The Function Helper box pictured above should be useful in helping guide you through the syntax of Vektor functions. It appears automatically when you open the parentheses of a function.

Description of data points:

  • LIST : The list that you want to filter.
  • EXPRESSION : The filter condition, to test on every row of the list.

FILTER(...) Examples

Similar to Formulaic Alerts, the FILTER function makes use of arbitrary complex conditional expressions for the qualifying expression, unlocking infinite filtering possibilities. We have grouped a few examples below under common use cases such as

  1. Discovering the best market opportunities,
  2. Identifying wasted opportunities,
  3. Preventing high-risk situations, and
  4. Analyzing underperformance of your positions

but there are many more!

🔧 Use Case: Discovering the best market opportunities

Show me all lend markets with APY higher than 10%

FILTER(LEND.MARKETS, VAL.SUPPLY_APY > 10%)  

⚠️
The syntax to build a conditional expression is to self-reference the list rows using the Lambda Syntax VAL on the right-hand side. VAL then lets you use the standard Vektor Data Model to access data points and perform operations on them. Vektor uses this VAL syntax to be consistent with many other languages, and to avoid problems with disambiguation.
⚠️
You can also use logical functions like AND(...) & OR(...) to make more complicated conditions.
Let's look for a Arbitrum borrow market with a borrow APY lower than 3% and a total debt value higher than 50K

FILTER(BORROW.MARKETS(INCLUDE_BLOCKCHAINS=[ARBITRUM]),  (VAL.BORROW_APY < 3%) AND (VAL.TOTAL_DEBT > 50000))  

Show me liquidity pools from Curve with more than 100k of liquidity and a APY higher 5%

FILTER(LP.POOLS(INCLUDE_VENUES=[CURVE]), (VAL.LIQUIDITY > 1000000) AND (VAL.APYS.TOTAL > 5%))  

Show me the pools from Curve that give token rewards

FILTER(LP.POOLS(INCLUDE_VENUES=[CURVE]), (VAL.APYS.REWARD > 0%))  

🔧 Use Case: Identifying wasted opportunities

Show me Arbitrum Lend Markets that I can already lend into with existing spot assets in my portfolio, sorted by APY

SORT(FILTER(LEND.MARKETS(INCLUDE_BLOCKCHAINS=[ARBITRUM]), VAL.ASSET IN COLUMN(BALANCES, "ASSET")), "SUPPLY_APY", ASC=FALSE)  

Show me borrow markets where I already have accounts with more than $1k of borrowing power available

FILTER(BORROW.MARKETS, VAL.VENUE.SYMBOL IN COLUMN(FILTER(BORROW.ACCOUNTS, VAL.AVAILABLE_BORROW > 1000), "VENUE.SYMBOL"))  

Show me borrow markets where I already have accounts with more than $1k of borrowing power available, AND the borrow APY is less than 3%

FILTER(BORROW.MARKETS, (VAL.VENUE.SYMBOL IN COLUMN(FILTER(BORROW.ACCOUNTS, VAL.AVAILABLE_BORROW > 1000), "VENUE.SYMBOL")) AND (VAL.BORROW_APY < 3%))

Show me liquidity pools that I can already deposit into with existing spot assets in my portfolio

FILTER(LP.POOLS, LIST.INTERSECTS(VAL.ASSETS, BALANCES.ASSET))  

Show me pools that I can already deposit into with existing assets in my portfolio with liquidity > 1M

FILTER(LP.POOLS, (LIST.INTERSECTS(VAL.ASSETS,  BALANCES.ASSET)) AND (VAL.LIQUIDITY > 1000000))  

⚠️
NB because each LP.POOL has multiple different assets, we cannot use the IN operator as with previous examples because we are testing if "any" balance asset is in "any" pool asset for this filter. So we use LIST.INTERSECT which returns TRUE if two lists have any elements in common.

🔧 Use Case: Preventing High Risk Situations

Get my borrow accounts with health factor lower than 170%

FILTER(BORROW.ACCOUNTS, VAL.HEALTH_FACTOR < 170%)

Get my borrow positions where the price of the borrowed assets is down more than 10% in one month

FILTER(BORROW.POSITIONS, VAL.MARKET.ASSET.SYMBOL IN COLUMN(FILTER(PRICES, VAL.CHANGE_30D < -10%), "ASSET"))

Get my liquidity pool positions with Liquidity lower than 2M.

FILTER(LP.POSITIONS , VAL.POOL.LIQUIDITY < 2000000)

Show me my liquidity pool positions where my ownership is higher than 50%.

FILTER(LP.POSITIONS , VAL.OWNERSHIP > 50%)

Show me my borrow positions where my debt amount represents more than a 5% of the total market debt

FILTER(BORROW.POSITIONS,((VAL.DEBT_AMOUNT / VAL.MARKET.TOTAL_DEBT)) > 0.05)

(intentionally no screenshot)

🔧 Use Case: Analyzing Underperformance of your positions

Get my liquidity pool positions with pool APY<5%

FILTER(LP.POSITIONS, VAL.POOL.APYS.TOTAL < 5%)

Show me all the USDC lending markets that beat my current lend positions best APYs

FILTER(LEND.MARKETS(INCLUDE_ASSETS=[USDC]), VAL.SUPPLY_APY > MAX(LEND.POSITIONS(INCLUDE_ASSETS=[USDC]).MARKET.SUPPLY_APY))

Show me all the lending markets that beat my current lend positions APYs (without having to bridge to another chain)

FILTER(LEND.MARKETS, VAL.SUPPLY_APY > LIST.FIRST(LEND.POSITIONS(INCLUDE_ASSETS=[VAL.ASSET], INCLUDE_BLOCKCHAINS=[VAL.BLOCKCHAIN])).MARKET.SUPPLY_APY)

(intentionally no screenshot)


Questions?

Email: [email protected]
Zoom: Use CALL function in Vektor