Skip to content
All strategies

Strategies

Commodity-ETF 12-Month Momentum, Rank-Extreme Legs Conditioned on Own Trend Sign: Long the Strongest / Short the Weakest of the USEQ Commodity ETFs (GLD, SLV, USO, UNG), 21-Session Rebalance, Inverse-Vol Sized, Explicit Flat State (USEQ 1-DAY)

Outcome: Abandoned

CommodityEtfRankExtremeTsmomLS

Outcome Summary

CommodityEtfRankExtremeTsmomLS adapted a Quantpedia/QuantConnect commodity momentum strategy to four USEQ commodity ETFs, with each leg held only when the name's own 12-month trend sign agreed. The design asked for O(1) per-bar work because of earlier sandbox timeouts, and the code used fixed-length deques and running sums. Even so, after 3 iterations the strategy still exceeded the 300s Layer 3 sandbox limit on a 2400-day GLD window and was abandoned in the verification loop. It never reached backtesting, optimization, analyst review or risk review, so no performance metrics exist.

Hypothesis

Taken from the QuantConnect library write-up, which follows Quantpedia. The source ranks commodity futures by 12-month return, goes long the top quintile and short the bottom quintile, and rebalances monthly. We have no continuous CME/ICE futures. USEQ does carry every commodity-futures or physical ETF in our universe file: GLD (gold, from 2004), SLV (silver, from 2006), USO (front-month WTI futures, from 2006) and UNG (front-month Henry Hub futures, from 2007). UNIVERSE RULE: the universe is every……Show moreShow less

Taken from the QuantConnect library write-up, which follows Quantpedia. The source ranks commodity futures by 12-month return, goes long the top quintile and short the bottom quintile, and rebalances monthly. We have no continuous CME/ICE futures. USEQ does carry every commodity-futures or physical ETF in our universe file: GLD (gold, from 2004), SLV (silver, from 2006), USO (front-month WTI futures, from 2006) and UNG (front-month Henry Hub futures, from 2007). UNIVERSE RULE: the universe is every commodity-tracking ETF in config/us_equities_universe.txt, applied point-in-time rather than hand-picked from survivors. A name becomes eligible only once it has at least 253 daily sessions of history as of the rebalance date. With 4 names a quintile is one name, so the book has two slots: the top-ranked name (long leg) and the bottom-ranked name (short leg). Lesson 137 warns against an always-on neutral book and lesson 150 against a never-flat design, so each leg depends on its own 12-month sign. This is the Moskowitz-Ooi-Pedersen time-series momentum condition, which is part of momentum itself, not an added regime filter. The long leg is held only if the top name's 12-month return is above 0. The short leg is held only if the bottom name's 12-month return is below 0. The legs are independent, so the book can be long only, short only, both, or flat. Expected flat time: about 15-20% of months for the long slot and about 35-45% for the short slot. Economic cause: commodity momentum comes mostly from roll yield and from inventory states that persist (Erb-Harvey; Gorton-Hayashi-Rouwenhorst). Backwardated, low-inventory commodities keep rising, and contango-heavy ones (UNG, or USO in a glut) keep losing through the roll. The counterparties who pay are passive long-only roll holders and hedging producers. Per-trade arithmetic: the cross-sectional commodity momentum premium is about 0.5-1.0% per month per leg. The average hold is about 2.5-3 rebalance periods, so expected gross is about 1.5-2.5% per trade. The USEQ round trip (spread plus impact on these very liquid ETFs) is about 0.05%, so the edge is more than 30x cost. Trade count: about 228 monthly rebalances from 2007 to 2026, with a leg changing name or state in about 35-40% of them. That gives about 160-190 round trips over the history, and about 40 in the holdout. Sizing: each active leg's weight is min(0.5, 0.15 / realized_vol_63d_annualized) of equity. This is inverse-vol sizing, so UNG at 50% vol gets about 30% and GLD at 15% vol caps at 50%. Gross exposure stays at or below 100%, well inside Reg-T 2x. Performance note (from recent sandbox timeouts): per-bar work must be O(1). Keep a fixed-length deque of the last 253 closes and a running 63-day log-return sum and sum of squares for each instrument. Rank only on rebalance bars and never rescan history.

Removed the per-bar execution retry path and repeated order/position cache scans. Reconciliation now occurs only on calendar-anchored rebalance bars while retaining the fixed-size rolling state and existing signal logic.

verification_loop: sandbox_timeout: Verification failed (Layer 3 — sandbox backtest): smoke test exceeded the 300s wall-clock limit on a ~20000-bar window (2400 days of GLD.USEQ-1-DAY-LAST-EXTERNAL). This almost always means per-bar work that scales with history — e.g. rescanning the full funding/supplementary series, or rebuilding a list and calling min()/sorted() inside calculate_signal()/on_bar() on every bar. Precompute sorted timestamp arrays ONCE in __init__ and use bisect, or cache lookups keyed by timestamp, so per-bar cost is O(log n) not O(n).

Implementation

Ranks commodity ETFs by trailing 12-month return every 30 calendar days, holding the strongest only when positive and the weakest only when negative, with capped inverse-volatility sizing.

Verification Results

sandbox_timeout: Verification failed (Layer 3 — sandbox backtest): smoke test exceeded the 300s wall-clock limit on a ~20000-bar window (2400 days of GLD.USEQ-1-DAY-LAST-EXTERNAL). This almost always means per-bar work that scales with history — e.g. rescanning the full funding/supplementary series, or rebuilding a list and calling min()/sorted() inside calculate_signal()/on_bar() on every bar. Precompute sorted timestamp arrays ONCE in __init__ and use bisect, or cache lookups keyed by timestamp, so per-bar cost is O(log n) not O(n).

Outcome Summary

Multi-instrument strategies must be profiled to confirm the per-bar cost is truly O(1) in the sandbox before resubmitting. The hypothesis already required O(1) deques and running sums, but that was not enough to pass the timeout, so the remaining per-bar work (e.g. per-instrument cache/order queries and sorting on every bar instead of only on rebalance bars) should be checked.

The run was abandoned in a verification loop after 3 iterations. The Layer 3 sandbox backtest went over the 300s wall-clock limit on a ~20,000-bar window (2400 days of GLD.USEQ-1-DAY), which usually means per-bar work grows with the length of the history.

A 12-month cross-sectional commodity momentum strategy on the USEQ commodity ETFs (GLD, SLV, USO, UNG): long the strongest name only if its 12-month return was positive, short the weakest only if its 12-month return was negative, rebalanced every 21 sessions with inverse-vol sizing, on the thesis that roll yield and persistent inventory states drive commodity momentum.

No performance was measured: there is no backtest report and no optimization report, so there are no return, Sharpe or trade-count figures.

Analysis

Momentum Effect in Commodities Futures

Backtest and paper results are hypothetical. Trading involves risk of loss.