Query editor
/*-- @title: ALM - By Day-- @author: Steakhouse Financial-- @description: Returns one line per day for each asset of Sky at the ilk level.-- @version:- 2024-04-02 : Fix coinbase custody- 2024-07-05 : added rates for Spark DAI Vault- 2024-08-15 : using accounting v2- 2024-08-31 : excluding idle DAI from LITE-PSM-USDC-A- 2024-09-03 : adjusted rate for LITE-PSM-USDC-A depending on balance ranges- 2024-10-30 : remove the idle amount reference to the query- 2024-11-26 : rate for LITE-PSM-USDC-A based on period and balance- 2025-04-13 : Point to Morpho V2 Vault- 2025-10-20 : Add Grove and Spark split APY*/with ilks_params as (-- v1 : https://docs.google.com/spreadsheets/d/1giHwSFYSlZJQGhhejiYWJwXhscQKTKCXdtsp6ZX7yHs/edit?gid=0-- select * from query_3273458 -- ALM params v1-- v2 : https://docs.google.com/spreadsheets/d/1giHwSFYSlZJQGhhejiYWJwXhscQKTKCXdtsp6ZX7yHs/edit?gid=1434793311select * from query_3685400 -- ALM params v2 including LITE-PSM-USDC-A),assets as (select date_trunc('day', ts) as period, ilk, sum(dai_value) as amountfrom dune.steakhouse.result_sky_accountingwhere ilk is not nulland cast(code as varchar) like '1%'group by 1, 2),start_date_assets as (select ilk, min(period) as start_datefrom assetsgroup by 1),filler as (select *from assetsunion allselect period, ilk, null as amountfrom start_date_assetscross join unnest(sequence(date'2019-01-01', current_date, interval '1' day)) as t(period)where start_date < period),grp_by as (select period, ilk, sum(amount) as amountfrom fillergroup by 1, 2),balances as (selectb.period,b.ilk,greatest(sum(b.amount) over (partition by b.ilk order by b.period asc),0) as balancefrom grp_by b),ilks_rates_set as (select