Repository Public
1"""Mean reversion: buy an asset in proportion to how far it trades below its recent average (z-score)."""23import numpy as np45META = {6 "name": "mean_reversion",7 "version": "1",8 "universe": ["ETH", "BTC", "LINK", "SOL"],9 "interval": "1h",10 "lookback": 200,11 "params": {"window": 48, "z_full": 2.0},12}131415def target_weights(data, params):16 window, z_full = int(params["window"]), float(params["z_full"])17 n = len(data)18 weights = {}19 for symbol, df in data.items():20 close = df["close"].to_numpy()21 if len(close) < window or window < 2 or z_full <= 0:22 weights[symbol] = 0.023 continue24 recent = close[-window:]25 std = recent.std(ddof=1)26 if not std > 0:27 weights[symbol] = 0.028 continue29 z = (close[-1] - recent.mean()) / std30 weights[symbol] = float(np.clip(-z / z_full, 0.0, 1.0)) / n31 return weights32