Backtest to Insight: Building an Index Futures Strategy from Stock-Level Signals

yiweileng1 pts0 comments

Backtest to Insight: Building an Index Futures Strategy from Stock-Level Signals | by DolphinDB | MediumSitemapOpen in appSign up<br>Sign in

Medium Logo

Get app<br>Write

Search

Sign up<br>Sign in

Backtest to Insight: Building an Index Futures Strategy from Stock-Level Signals

DolphinDB

5 min read·<br>Nov 5, 2025

Listen

Share

Press enter or click to view image in full size

The stock index futures trading strategy based on constituent stock signals is a strategy that predicts index trends by analyzing signals from index constituent stocks and trades stock index futures accordingly. Its core idea is to use microscopic signals from constituent stocks to capture macroscopic index trends, thereby generating profits in the stock index futures market. Its core logic involves several main steps: individual stock signal generation, constituent stock signal synthesis, index signal decision-making, and risk management.<br>Individual stock signal generation:<br>Conduct technical and fundamental analysis on index constituent stocks to generate individual stock signals.<br>Each constituent stock’s signal can be buy, sell, or hold.<br>2. Index signal synthesis:<br>At each minute-level snapshot, synthesize signals from all constituent stocks through equal weighting, market cap weighting, liquidity weighting, and other methods to generate the synthesized index signal.<br>3. Index signal decision-making: Based on the synthesized index signal, decide whether to buy or sell stock index futures. Common decision rules include:<br>· Long signal: Buy stock index futures when the index signal reaches a certain buy threshold.<br>· Short signal: Sell stock index futures when the index signal reaches a certain sell threshold.<br>· Hold signal: Maintain current positions when the index signal is between buy and sell thresholds.<br>We will introduce how to use DolphinDB’s built-in scripting to write time-driven functions to implement stock index futures trading strategies. Content includes the implementation process of strategy logic, initialization parameter configuration, how to generate individual stock signals and index signals in strategy logic context, etc.<br>1. Strategy Logic Introduction<br>Below is a simple stock index futures strategy based on moving average crossovers and RSI, mainly used to generate buy/sell signals for individual stocks, and decide whether to open or close positions in stock index futures by synthesizing these signals. The core logic of this strategy includes individual stock signal generation and index signal synthesis, ultimately simulating trading through the backtesting engine.

Figure 1.1 Stock Index Futures Trading Strategy Flowchart Stock signal generation: First generate individual stock opening signals (long signal marked as 1, short signal marked as -1) and closing signals (marked as 0) based on indicators such as dual moving averages, RSI, volatility, etc.<br>Index signal synthesis: Based on individual stock signals, obtain index signals through equal weighting, and get corresponding index target opening signals (marked as 1) and closing signals (marked as 0)<br>In this case, we take CSI 300 stock index futures as an example, passing stock index futures and constituent stocks as minute-level futures market data into the backtesting engine. The strategy’s orders are executed at the order prices. Additionally, the backtest process of this case is similar to the previously introduced portfolio backtest case, and repeated steps will not be explained in detail.<br>2. Strategy Implementation Process<br>2.1 Individual Stock Signal Generation<br>Initialization Function<br>First, strategy parameters can be set through the parameter context in the initialization function initialize. initialize is only triggered once after creating the engine. In this case, dual moving averages, RSI, volatility and other indicators must be subscribed to via subscribeIndicator in the initialization function, and global parameters such as buy/sellSignal, stockSignal, indexSignal, shortLongMA, etc. must be defined in the initialization function.<br>def initialize(mutable contextDict){<br>d = dict(STRING, ANY)<br>d["shortMA"] =<br>d["longMA"] =<br>d["RSI"] =<br>d["volatility"] =<br>Backtest::subscribeIndicator(contextDict["engine"], "kline", d)

// Buy signal threshold<br>contextDict["buySignal"] = 0.995<br>// Sell signal threshold<br>contextDict["sellSignal"] = 0.995<br>// Signal dictionary<br>contextDict["stockSignal"] = dict(STRING, ANY)<br>contextDict["indexSignal"] = dict(STRING, ANY)

// Signal dictionary for ShortMA and LongMA<br>// set to -1 when the ShortMA is greater than the LongMA,<br>// set to 1 when the LongMA is greater than the ShortMA,<br>// and set to 0 otherwise<br>contextDict["shortLongMA"] = dict(STRING, ANY)<br>}2. Open Signal Detection<br>After subscribing to the above indicators, the strategy logic function onBar generates opening signals based on indicators such as shortMA, longMA, RSI, and volatility, and the global dictionary shortLongMA:<br>At market open, when the short MA crosses above the long MA, RSI is less...

index stock signal signals futures strategy

Related Articles