Fix Mean Reversion VWAP bug — was never firing
Root cause: VWAP weighted the current price highest so dev≈0 always. - Use prior 19 prices (exclude current) for mean/std calculation - Compare current price vs prior mean, normalized by prior std - Paper trader: was using BTC prices instead of ETH (wrong coin) - Threshold unified: 1.0σ (was 1.5σ in paper, 1.0σ in live) Backtests show BTC Mean Reversion: +76.42% PnL, 91% win, 22 trades.
This commit is contained in:
+7
-5
@@ -183,12 +183,14 @@ def compute_signals():
|
||||
if eth_cur > sma+1.2*std: STRATEGIES["Momentum Breakout"]["signals"].append({"time":time.time(),"signal":"BUY","strength":(eth_cur-sma-1.2*std)/std})
|
||||
elif eth_cur < sma-1.2*std: STRATEGIES["Momentum Breakout"]["signals"].append({"time":time.time(),"signal":"SELL","strength":(sma-1.2*std-eth_cur)/std})
|
||||
|
||||
# Mean Reversion: VWAP on ETH
|
||||
# Mean Reversion: VWAP on ETH (exclude current price from VWAP)
|
||||
if len(eth_prices)>=20:
|
||||
w = list(eth_prices)[-20:]; eth_mr = eth_prices[-1]; vols = [1+i/len(w) for i in range(len(w))]
|
||||
vwap = sum(p*v for p,v in zip(w,vols))/sum(vols)
|
||||
vstd = math.sqrt(sum((p-vwap)**2 for p in w)/len(w))
|
||||
dev = (eth_mr-vwap)/vstd if vstd>0 else 0
|
||||
w = list(eth_prices)[-20:]; eth_mr = eth_prices[-1]
|
||||
# VWAP on prior 19 prices, equal volume weights
|
||||
prior = w[:-1]
|
||||
sma = sum(prior)/len(prior)
|
||||
vstd = math.sqrt(sum((p-sma)**2 for p in prior)/len(prior))
|
||||
dev = (eth_mr-sma)/vstd if vstd>0 else 0
|
||||
if dev>1.0: STRATEGIES["Mean Reversion"]["signals"].append({"time":time.time(),"signal":"SELL","strength":dev})
|
||||
elif dev<-1.0: STRATEGIES["Mean Reversion"]["signals"].append({"time":time.time(),"signal":"BUY","strength":abs(dev)})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user