I find a more appropriate way to write rolling volatility, mainly utilizing the sliding window mstd function to achieve it.
select ts_code,trade_date,mstd(pct_change/100,21) as mvol from t context by ts_code