Meme-Coin Momentum Rotation v4.0
Meme-Coin Momentum Rotation v4.0
1. Core Idea: The Strong Stay Strong
High-volatility meme coins are momentum assets, not mean-reverting ones. Their prices are driven by capital flow and narrative, and once a direction reaches consensus it tends to persist over the short term rather than snap back to a mean. That makes them suited to buying strength and selling weakness — not to buying dips and selling rips.
But this raises the real question: how do you measure "strong"?
Return is the obvious answer, but return is only a result — it tells you the asset has already gone up, not whether capital is still backing that move. The funding rate supplies evidence from a different angle: a positive funding rate means longs are continuously paying shorts, and the higher it goes, the more the market is willing to pay to hold that long exposure. That is behavioral evidence, not a price outcome.
So this strategy combines the two into a single composite momentum score:
score = w₁ · z(price momentum) + w₂ · z(funding rate)
Price momentum tells you "it went up"; the funding rate tells you "someone is willing to keep paying to stay long." The two factors describe the same thing — the strength and persistence of market consensus — from different directions. After cross-sectional z-scoring and weighting, the strategy goes long the highest-scoring names and short the lowest-scoring ones, forming a market-neutral two-leg portfolio.
2. Three Engineering Details That Matter
1) Funding-Interval Correction: Normalize Everything to an 8h Basis
Binance contracts do not share a common funding interval — market-wide there are roughly 440 contracts on 4h, 324 on 8h, and 4 on 1h. This means an identical nominal 5bp rate settles six times a day on a 4h contract versus three times on an 8h one: the real cost differs by a factor of two.
Ranking raw nominal rates across the cross-section therefore compares incommensurable numbers and produces a meaningless ordering. At startup the strategy pulls fundingInfo to obtain each contract's settlement interval, then normalizes every rate to an 8-hour basis:
fund8 = premium index × 10000 × (8 / funding interval hours)
Both live scoring and historical regression fitting use the premium index (mark/index − 1) rather than the last settled funding rate — the former is continuous and real-time, the latter a discrete historical snapshot. Because both paths share one definition, the fitted β can be applied directly to live trading.
2) Risk Parity: Two Layers of Volatility Control
Within a leg: volatility varies enormously across these names, and equal weighting would let the wildest coin dominate the entire leg's P&L. The strategy weights inversely to volatility (w ∝ 1/σ) so each name contributes the same risk budget.
At the portfolio level: it estimates residual volatility after long/short hedging, compares it to a target, and scales gross exposure proportionally:
estimated portfolio vol ≈ weighted average leg σ / 2 × 0.6
exposure scale = min(1, target vol / estimated portfolio vol)
Exposure shrinks automatically when market-wide volatility expands and recovers when it contracts, making the return distribution more predictable rather than passively absorbing volatility regime shifts.
3) Cross-Margin: Unrealized P&L Offsets Across Legs
Under Binance's unified account / cross-margin mode, unrealized losses on the long leg are offset by unrealized gains on the short leg and vice versa. At the same notional exposure, the maintenance-margin ratio is substantially higher than under isolated margin, sharply reducing the chance of a single leg being liquidated by an extreme move.
This matters especially for meme coins, where the short leg carries theoretically unbounded loss. Under isolated margin, one short squeeze can liquidate that leg alone — instantly converting a neutral portfolio into an unhedged long.
3. Dynamic Weights: Rolling Cross-Sectional Regression
What should w₁ and w₂ be? Fixed priors are one option, but factor efficacy drifts with market regime. The strategy offers Fama-MacBeth rolling cross-sectional regression to fit them dynamically:
- Pull the last
REG_PERIODS4h panel observations (price + premium index); - Run a period-by-period cross-sectional OLS:
forward return = a + b₁·z(momentum) + b₂·z(funding); - Take the time-series mean and t-statistic of
b₁andb₂; - Shrink by |t|: full weight when
|t| ≥ T_SHRINK, proportionally decayed otherwise — statistically insignificant factors are automatically downweighted; - Apply a weight floor
W_FLOOR, then renormalize so that|w₁| + |w₂| = 1.
Because the panel is z-scored as well, the fitted βs are directly comparable in magnitude between the two factors.
4. Execution: Strict Two-Leg Management
The real danger in a market-neutral strategy is not getting the direction wrong — it is the two legs failing to align. If the long leg fills and the short leg does not, a neutral portfolio silently becomes an unhedged long. The strategy carries forward the strict state machine from v3:
cancel-and-confirm → forced reconciliation → delta orders → loop until exact match
- Cancel-and-confirm: issuing a cancel is not enough; it polls until the open-order list is genuinely empty;
- Forced reconciliation: local records are never trusted — every round calls
GetPositionsfor the true state. If any position cannot be resolved back to a trading pair, order submission is refused outright (better to do nothing than to do the wrong thing); - Delta orders: compare target to actual and submit only the difference; the first two rounds use limit orders (capturing maker rebates), then switch to market orders to guarantee completion;
- Net-exposure check: after entry, compute
|long notional − short notional| / average notional, and flatten everything if it exceeds the threshold.
While holding, positions are reconciled every 30 seconds and any deviation returns the system to the repair flow. On restart, recovery is driven by the execState field: OPENING resumes entry, HOLDING verifies positions, and any other state flattens first before starting fresh.
5. Universe Screening
Not every coin qualifies. From the full USDT-perp universe the strategy filters on:
| Condition | Rationale |
|---|---|
VOL_MIN_M ~ VOL_MAX_M | 24h turnover band — too small cannot absorb the exposure, too large (BTC/ETH) is not a meme coin |
σ ≥ SIGMA_MIN | Hourly volatility floor — low volatility means it is not a momentum asset, so it is excluded |
spread ≤ SPREAD_MAX | Bid-ask spread cap — a wide spread means execution cost consumes the entire alpha |
bars ≥ MIN_HISTORY | Minimum candle history — newly listed contracts lack the basis for momentum and volatility estimates |
6. Parameters and Dashboard
Key parameters: TOP_K (legs per side), REBAL_H (rotation period), MOM_LOOKBACK_H (momentum lookback), TARGET_VOL_PCT (target volatility), GROSS_MAX_USDT (per-side exposure cap), LEVERAGE, and STOP_PCT (portfolio stop-loss).
Setting LIVE_MODE=false enables a simulated matching engine with modeled slippage, limit-fill probability, and partial fills, so the logic can be observed without connecting live funds. The dashboard displays account equity, composite factor weights with their t-statistics, per-leg positions and reconciliation status, net-exposure deviation, cumulative performance, and per-symbol attribution, with the built-in equity curve plotted via LogProfit.
/*
* ============================================================================
* 妖币动量轮转 v4.4 —— 资金费率作为动量特征 · 风险均衡 · 统一账户
* 发明者量化 FMZ / JavaScript / 币安 USDT 本位合约
*
* 核心思想: 强者恒强
* 高波动的 meme / 妖币是动量型资产, 不是均值回归型资产。
* 衡量"强"不能只看涨幅——涨幅是结果, 资金费率是资金在为这个方向付钱的证据。
* 价格动量告诉你"它涨了", 资金费率告诉你"有人愿意持续付成本做多它"。
* 两者合成一个复合动量分, 做多最强的一批、做空最弱的一批。
*
* 三个工程要点:- 1