TQTradingQuery

Session behavior · MYM

How often does MYM revert to VWAP after moving 1 standard deviation away from it

529

reversion count

n=6272026-03-05 to 2026-09-07

reversion count

529

reversion rate

82.6%

num trading days

130

Methodology

Analysis code was generated by an AI model up to 25 times, run in a sandbox against real MYM 1-minute bars from 2026-03-05 to 2026-09-07, and reviewed automatically. Attempts that computed the same set of measures were grouped, and the figures shown are the median of the largest group. Agreement between attempts lowers the chance of a one-off coding slip; it does not prove the code matches the question, so the exact code is shown below.

Show the code

bars_et = to_et(bars)
rth = rth_session(bars_et)
rth = rth.copy()
rth['date'] = trading_date(rth)

events = 0
reverts = 0

for date, day in rth.groupby('date'):
    if len(day) < 10:
        continue
    typical = (day['high'] + day['low'] + day['close']) / 3
    vol = day['volume'].values
    cum_vol = vol.cumsum()
    if cum_vol[-1] == 0:
        continue
    cum_pv = (typical.values * vol).cumsum()
    vwap = cum_pv / np.where(cum_vol == 0, np.nan, cum_vol)
    diff = day['close'].values - vwap
    # rolling std of diff up to that point, use expanding std as "sigma" of deviation
    diff_series = pd.Series(diff)
    exp_std = diff_series.expanding(min_periods=10).std().values

    in_event = False
    direction = 0
    for i in range(len(day)):
        if np.isnan(vwap[i]) or np.isnan(exp_std[i]) or exp_std[i] == 0:
            continue
        dev = diff[i]
        sigma = exp_std[i]
        if not in_event:
            if abs(dev) >= sigma:
                in_event = True
                direction = np.sign(dev)
                events += 1
        else:
            # check for reversion: price crosses back to vwap (diff changes sign or hits zero)
            if np.sign(dev) != direction or dev == 0:
                reverts += 1
                in_event = False
            elif abs(dev) < sigma * 0.1:
                reverts += 1
                in_event = False

revert_rate = reverts / events if events > 0 else None

result = {
    "sample_size": int(events),
    "reversion_count": int(reverts),
    "reversion_rate": float(revert_rate) if revert_rate is not None else None,
    "num_trading_days": int(rth['date'].nunique())
}
  • Generated by an AI model up to 25 times, run in a sandbox, and reviewed automatically; the figures above are the median of the largest group of attempts that computed the same measures. Agreement between attempts lowers the chance of a one-off coding slip -- it does not prove the code matches the question, so check the definition and code. A one-off calculation, not a permanent fixture.

This is historical statistical information only. It is not investment advice, and past performance does not indicate future results. Trading involves risk of loss.