Query editor
with cpi(d, actual, cons, ver) as (values(date '2021-01-13',1.4,1.3,0),(date '2021-02-10',1.4,1.5,0),(date '2021-03-10',1.7,1.7,0),(date '2021-04-13',2.6,2.5,0),(date '2021-05-12',4.2,3.6,0),(date '2021-06-10',5.0,4.7,0),(date '2021-07-13',5.4,4.9,0),(date '2021-08-11',5.4,5.3,0),(date '2021-09-14',5.3,5.3,0),(date '2021-10-13',5.4,5.3,0),(date '2021-11-10',6.2,5.8,0),(date '2021-12-10',6.8,6.8,0),(date '2022-01-12',7.0,7.0,0),(date '2022-02-10',7.5,7.3,0),(date '2022-03-10',7.9,7.9,0),(date '2022-04-12',8.5,8.4,0),(date '2022-05-11',8.3,8.1,0),(date '2022-06-10',8.6,8.3,0),(date '2022-07-13',9.1,8.8,0),(date '2022-08-10',8.5,8.7,0),(date '2022-09-13',8.3,8.1,0),(date '2022-10-13',8.2,8.1,0),(date '2022-11-10',7.7,8.0,0),(date '2022-12-13',7.1,7.3,0),(date '2023-01-12',6.5,6.5,0),(date '2023-02-14',6.4,6.2,0),(date '2023-03-14',6.0,6.0,0),(date '2023-04-12',5.0,5.2,0),(date '2023-05-10',4.9,5.0,0),(date '2023-06-13',4.0,4.1,0),(date '2023-07-12',3.0,3.1,0),(date '2023-08-10',3.2,3.3,0),(date '2023-09-13',3.7,3.6,0),(date '2023-10-12',3.7,3.6,0),(date '2023-11-14',3.2,3.3,1),(date '2023-12-12',3.1,3.1,1),(date '2024-01-11',3.4,3.2,1),(date '2024-02-13',3.1,2.9,1),(date '2024-03-12',3.2,3.1,1),(date '2024-04-10',3.5,3.4,1),(date '2024-05-15',3.4,3.4,1),(date '2024-06-12',3.3,3.4,1),(date '2024-07-11',3.0,3.1,1),(date '2024-08-14',2.9,3.0,1),(date '2024-09-11',2.5,2.6,1),(date '2024-10-10',2.4,2.3,1),(date '2024-11-13',2.6,2.6,1),(date '2024-12-11',2.7,2.7,1),(date '2025-01-15',2.9,2.9,1),(date '2025-02-12',3.0,2.9,1),(date '2025-03-12',2.8,2.9,1),(date '2025-04-10',2.4,2.6,1),(date '2025-05-13',2.3,2.4,1),(date '2025-06-11',2.4,2.5,1),(date '2025-07-15',2.7,2.7,1),(date '2025-08-12',2.7,2.8,1),(date '2025-09-11',2.9,2.9,1),(date '2025-10-24',3.0,3.1,1),(date '2025-12-18',2.7,3.1,1),(date '2026-01-13',2.7,2.7,1),(date '2026-02-13',2.4,2.5,1),(date '2026-03-11',2.4,2.4,1),(date '2026-04-10',3.3,3.3,1),(date '2026-05-12',3.8,3.7,1),(date '2026-06-10',4.2,4.2,1),(date '2026-07-14',3.5,3.8,1),(date '2026-08-12',3.4,3.4,1),(date '2026-09-11',3.4,3.4,1),(date '2026-10-14',3.7,3.6,1)),px as (select date(timestamp) d,max(case when symbol='XRP' and hour(timestamp)=0 then price end) x0,max(case when symbol='XRP' and hour(timestamp)=12 then price end) x12,max(case when symbol='XRP' and hour(timestamp)=15 then price end) x15,max(case when symbol='WBTC' and hour(timestamp)=0 then price end) b0,max(case when symbol='WBTC' and hour(timestamp)=12 then price end) b12,max(case when symbol='WBTC' and hour(timestamp)=15 then price end) b15from prices.hourwhere ((symbol='XRP' and blockchain='bnb' and contract_address=0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe) or (symbol='WBTC' and blockchain='ethereum' and contract_address=0x2260fac5e5542a773aa44fbcfedf7c193bc2c599))and timestamp >= timestamp '2021-01-01' and hour(timestamp) in (0,12,15)group by 1),daily as (select d, x12, x15/x12-1 xw, b15/b12-1 bw, lead(x0) over (order by d)/x0-1 xd, lead(b0) over (order by d)/b0-1 bd from px),j as (select p.d, p.x12, p.xw, p.bw, p.xd, p.bd, c.actual, c.cons, c.ver, case when c.d is not null then 1 else 0 end is_cpi from daily p left join cpi c on c.d = p.d where p.xd is not null and p.xw is not null)select 'event' kind, cast(d as varchar) label, actual, cons, ver, 1 n, round(x12,4) xrp_px, round(100*xw,2) xrp_win, round(100*bw,2) btc_win, round(100*xd,2) xrp_day, round(100*bd,2) btc_day, null aw, null sw, null ad, null sd, null abw, null abd, null beta_w, null beta_dfrom j where is_cpi=1union allselect 'baseline', case when d < date '2023-11-01' then 'noncpi_weekday_2021-Oct2023' else 'noncpi_weekday_Nov2023+' end, null, null, null, count(*), null,round(100*avg(xw),3), round(100*avg(bw),3), round(100*avg(xd),3), round(100*avg(bd),3),round(100*avg(abs(xw)),3), round(100*stddev(abs(xw)),3), round(100*avg(abs(xd)),3), round(100*stddev(abs(xd)),3), round(100*avg(abs(bw)),3), round(100*avg(abs(bd)),3),round(regr_slope(xw,bw),3), round(regr_slope(xd,bd),3)from j where is_cpi=0 and day_of_week(d) between 1 and 5 group by 2order by 1 desc, 2