Query editor
with sfrxETH_ratio as (select date_trunc('hour', block_time) as time, avg(ratio) as avg_ratiofrom( select block_time, token_bought_amount/token_sold_amount as ratio, amount_usdfrom dex.trades where token_sold_symbol = 'sfrxETH'and block_time >= date('2023-02-09') -- pair createdand token_pair = 'sfrxETH-wstETH' and (token_sold_amount != 0 or token_bought_amount != 0)union allselect block_time, token_bought_amount/token_sold_amount as ratio, amount_usdfrom dex.trades where token_bought_symbol = 'wstETH'and block_time >= date('2023-02-09') -- pair createdand token_pair = 'sfrxETH-wstETH' and (token_sold_amount != 0 or token_bought_amount != 0) ) xwhere date_trunc('day', block_time) > now() - interval '3' monthgroup by 1order by 1 desc),get_wstETH_price as (select day as time, round(avg(price), 2) as avg_pricefrom(select date_trunc('hour', minute) as day, pricefrom prices.usd where blockchain = 'ethereum' and symbol = 'wstETH') xgroup by 1order by 1 desc),sfrxETH_price as (select time, cast((avg_ratio * avg_price)as double) as sfrxETH_pricefrom sfrxETH_ratioleft join get_wstETH_price using (time)order by 1 desc),log_data as (select time, log_returnsfrom (select time, ln(sfrxETH_price/lag(sfrxETH_price) over (order by time)) as log_returnsfrom sfrxETH_priceorder by time desc) xwhere log_returns is not null and log_returns > 0 -- ignore negative value),volatility as (select date_trunc('day', time) as time, sqrt(variance(log_returns)) as volatility_risk_sfrxETHfrom log_datagroup by 1),summary_table as (select *from volatilityleft join query_2504712 using (time))select *from summary_tableorder by time desc