Hi everyone,
I'm excited to share a strategy that replicates and validates a Qlib-based cross-sectional stock selection model using the QuantConnect platform for independent backtesting.
Strategy Overview
This strategy originates from Microsoft’s Qlib, an open-source framework for high-frequency and daily alpha research. Qlib provides a complete data-handling and model training pipeline and is widely used for cross-sectional ranking-based prediction — commonly known as "alpha modeling".
Core Logic – Qlib Cross-Sectional Stock Ranking
The upstream model performs the following steps:
- Universe: S&P500 constituents
- Feature Engineering: Alpha158.
- Model Training: LightGBM trained to rank stocks daily by expected return
- Signal Output: Each day, the top-k stocks (e.g., 5-50) are selected
- Rebalancing Rule: Drop ndrop names (e.g., 1-5) and replace with new names based on updated rankings.
The Qlib backtest simulates trading at daily close (T), building the target portfolio from top-ranked stocks with initially equal weights. The portfolio is held until the next day’s close (T+1), when a new list is generated and a new rebalance is made.
This QuantConnect Strategy – External Signal Follower
To verify the Qlib strategy externally, I exported the daily stock lists (tickers and weights) into a simple Python dictionary file (signaltable_sp500.py).
This QuantConnect strategy:
- Reads the daily stock list
- Executes one rebalance per day, 1 minutes after market close
- Initial Build: Equal-weight buy of the 5 tickers on first valid signal day
- Daily Rebalance:
- Sell one name from yesterday’s portfolio (not in today’s list)
- Buy one new name from today’s list (not in yesterday’s portfolio)
This mimics Qlib’s close-to-close holding period and provides a second-platform verification of signal consistency.
Backtest Summary
- Backtest Period: 2024-01-01 to 2026-01-09
- Capital: $ 20,000
- Portfolio: 5 stocks each day
- Turnover: very low (only 1 in/out per day)
- Execution: End of day (delayed 1 mins after close)
- Signal Source: Qlib, imported via signaltable_sp500_symbol.py
(Backtest charts and statistics below)
Why Use QuantConnect Here?
While Qlib is great for model training, but QuantConnect offers:
- Independent execution environment
- Slippage/fee modeling
- Visual performance dashboards
- Live trading integration
By importing the signal file into QuantConnect, I was able to double-check portfolio behavior and ensure robustness across platforms — a crucial step before real deployment.
Live Trading Ready
This strategy is now also running live via Collective2. Check it out here: SP500RelativeStrength.
Let’s Collaborate
If you’re working on:
- Cross-platform signal execution (Qlib & QuantConnect)
- Alpha research using LightGBM or deep learning
- Cross-sectional models
- End-of-day or close-to-close strategies
- Deploying to Collective2, IBKR, or other live platforms
I'd love to connect, exchange ideas, or optimize together!
Neo Alice
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!