Pairs trading: worth a try?


I evaluate a popular stock market strategy known as pairs trading. Pairs trading is a market-neutral approach to investing, meaning it is designed to generate profits regardless of whether the overall market is moving up or down (Palomar, 2025). The strategy begins by finding two financial instruments (e.g., stocks) whose prices have historically moved in tandem. When the two stocks temporarily drift apart—with one becoming overvalued relative to the other—the strategy bets on their eventual return to their normal relationship.

To execute this, an investor uses two basic market actions:

  1. Going Long: Buying a stock with the expectation that its price will increase.
  2. Selling Short: Borrowing a stock and immediately selling it, with the plan to buy it back later at a lower price to return to the lender. The profit is the difference between the initial sale price and the later purchase price.

When one stock in the pair is identified as “too high” and the other “too low,” an investor will simultaneously sell short the overpriced stock and go long on the underpriced one. The profit is realized when their prices converge back to their historical relationship. This analysis applies the pairs trading methodology to the stocks of four major Indonesian banks: Bank Central Asia (BBCA), Bank Rakyat Indonesia (BBRI), Bank Negara Indonesia (BBNI), and Bank Mandiri (BMRI). The goal is to identify a cointegrated pair, trade on their price deviations, and assess the strategy’s performance.

Data Preparation and Preprocessing

I utilized daily closing stock prices for the four banks from September 29, 2005, to June 10, 2025. The data is collected from Google Sheets using the GOOGLEFINANCE function and saved locally as an Excel file. Missing dates were handled by forward-filling, carrying forward the last observed price.

Indonesian banks’ daily stock prices (Rupiah)
Indonesian banks’ daily stock prices (Rupiah)

A visual inspection of the stock prices is presented in Figure 1. BMRI, BBNI, and BBRI follow broadly similar long-term trends. BBCA’s price, however, shows a distinct pattern, suggesting a weaker relationship with the other three. Thus, BBCA was excluded from further analysis. The prices of the remaining three stocks (BMRI, BBNI, and BBRI) were transformed into their natural logarithms. This helps stabilize the variance and linearize the underlying relationship, making it suitable for further analysis.

Cointegration Analysis

Cointegration is the critical statistical property that underpins pairs trading. It means that even though two stock prices may be non-stationary (i.e., have time-varying mean or variance which makes them unpredictable), a specific linear combination of them is stationary. A stationary series always converges to its long-run average, a statistical property one can exploit for profit.

The Engle & Granger (1987) two-step test was used to identify a cointegrated pair. The null hypothesis of this test is that no cointegration exists between a pair of stocks, while the alternative hypothesis is that they are cointegrated. The results, which test for the stationarity of the regression residuals, are summarized in Table 2.

Table 2. Engle-Granger cointegration test results.

Pair Test Statistic 1% Critical Value
BBNI-BMRI 4.021-4.021 3.898-3.898
BMRI-BBRI 2.459-2.459 3.898-3.898
BBNI-BBRI 3.313-3.313 3.898-3.898

The test results clearly indicate that the BBNI-BMRI pair is strongly cointegrated. Its test statistic of 4.021-4.021 is more negative than the 1% critical value, allowing us to reject the null hypothesis of no cointegration. The other pairs did not show a statistically significant relationship. Therefore, the BBNI-BMRI pair was selected for developing the trading strategy.

Rolling Regressions

The long-run relationship between the prices of BBNI and BMRI is likely not constant over two decades. To account for this, a rolling OLS regression with a 365-day window was used to estimate a time-varying hedge ratio (βt\beta_t) and intercept (αt\alpha_t). The model is defined as:

ln(BBNIt)=αt+βt×ln(BMRIt)+ϵt ln(BBNI_t) = \alpha_t + \beta_t \times ln(BMRI_t) + \epsilon_t

Here, βt\beta_t is the time-varying hedge ratio, representing the number of units of BMRI to hold for every unit of BBNI to maintain a market-neutral position (see Section 6). The coefficients (αt\alpha_t and βt\beta_t) are re-estimated every week. Figure 2 and 3, shows the evolution of the hedge ratio (βt\beta_t) and intercept (αt\alpha_t), respectively, over time.

Evolution of the hedge ratio (βt\beta_t) over time.
Evolution of the hedge ratio (\(\beta_t\)) over time.

Evolution of the intercept (αt\alpha_t) over time.
Evolution of the intercept (\(\alpha_t\)) over time.

Trading Signals

The trading strategy does not forecast the direction of the individual stocks themselves, but rather the behavior of the regression residual (ϵt\epsilon_t) which is referred to as the spread:

Spreadt=ϵt=ln(BBNIt)αtβt×ln(BMRIt) Spread_t = \epsilon_t = ln(BBNI_t) - \alpha_t - \beta_t \times ln(BMRI_t)

The assumption of cointegration ensures that the spread is mean-reverting—any deviation from zero is temporary. A positive spread suggests BBNI is temporarily overvalued relative to BMRI, while a negative spread suggests it is undervalued. The strategy bets on this spread reverting to its mean of zero.

The Stata code implementation provided in Appendix A requires at least two parameters:

  1. Threshold multiplier (kk): defines how far the spread must deviate from its mean (zero) to trigger a trade signal. I set k=1k = 1, meaning that a trade is initiated only when the spread moves beyond ±1 standard error (σt\sigma_t) from its zero mean. A smaller kk (e.g., 0.5) would lead to more frequent but potentially less profitable trades, while a larger kk (e.g., 2) would lead to fewer but potentially more significant deviations to exploit. The practical application of this threshold is visualized in Figure 4. The navy blue line represents the spread over time, while the dashed red lines form the trading bands calculated as ±kσt\pm k \sigma_t​. The shaded area between them is the region where no action is taken. A trade is triggered only when the spread moves out of this band.

Historical spread and trading thresholds
Historical spread and trading thresholds

  1. Maximum holding period: defines the maximum duration you are willing to keep a trade open, regardless of whether the spread has reverted to its mean. Even for cointegrated pairs, there’s no guarantee that the spread will revert within a short timeframe. This parameter acts as a time-based stop-loss. If the spread diverges persistently or the cointegration relationship breaks down, this parameter limits potential losses by forcing an exit. I set this parameter to 54 weeks (approximately one year) to match the rolling window size for the hedge ratio (βt\beta_t) estimation.

A trade is only considered if there is no existing open position. For simulation purposes, weekly OLS estimates are iterated through, and the spread is compared against the trading bands to check for an entry signal.

  • Signal 1: short the spread. When the spread is positive and exceeds the upper threshold (ϵt>kσt\epsilon_t > k \sigma_t), it implies that BBNI’s price is significantly higher than what the model predicts based on BMRI’s price. The strategy interprets this as BBNI being temporarily overvalued relative to BMRI. To profit from the expected reversion, the strategy bets on the spread falling. This is executed by short selling the relatively overvalued BBNI and simultaneously buying (going long) the relatively undervalued BMRI. The trade is exited at the first occurrence of one of two conditions: (1) the spread drops below zero, or (2) the maximum holding period is reached.

  • Signal 2: long the spread. When spread is negative and breaches the lower threshold (ϵt<kσt\epsilon_t < - k \sigma_t), it suggests that BBNI’s price is temporarily well below its predicted value, indicating it is undervalued relative to BMRI. The strategy bets on the spread rising back toward zero. This is done by buying (going long) the undervalued BBNI and short selling the overvalued BMRI. Similarly, the trade is exited at the first occurrence of one of two conditions: (1) the spread rises above zero, or (2) the maximum holding period is reached.

The outcome of these entry and exit rules over the entire sample period is shown in Figure 5.

Trading positions over time
Trading positions over time

Position Sizing

To maintain a market-neutral stance, the value of the long and short positions must be carefully balanced. The hedge ratio (βt\beta_t) reflects how much one stock moves relative to the other. For example, if βt=2\beta_t = 2, BBNI moves, on average, 2% when BMRI moves 1%, based on historical data. When we short BBNI and go long on BMRI, we need to balance the positions so that if both stocks move together in the same direction due to market factors, the gains and losses offset each other. Multiplying the long position’s value by βt\beta_t adjusts for this relative movement, ensuring the portfolio’s exposure to market shifts cancels each other.

Let’s define a base investment value, VV, set at IDR 1,000 for this analysis. For a short spread trade initiated at time t:

  1. Short Leg (BBNI): The value of the BBNI position to be shorted is equal to the base investment, VV. The number of shares to short is therefore:

    NBBNI,t=VBBNIt N_{BBNI,t} = \frac{V}{BBNI_t}
  2. Long Leg (BMRI): The value of the BMRI position must be weighted by the hedge ratio to neutralize exposure to common market factors. The total value of the long position in BMRI is set to V×βt V \times \beta_t . The number of BMRI shares to buy is:

    NBMRI,t=V×βtBMRIt N_{BMRI,t} = \frac{V \times \beta_t}{BMRI_t}

Without this adjustment, the portfolio would be vulnerable to directional risk. By setting the long position’s value to V×βt V \times \beta_t (where VV is the short position’s value), we align the positions to cancel out market-driven changes, leaving us to profit solely from the spread’s convergence. A numeric example is provided in the Appendix B for clarity.

Profit calculations

A position is held until the primary exit condition is met: the spread (ϵt \epsilon_t ), reverts and crosses its long-term mean of zero. If this does not occur, the 54-week holding period forces a closure.

Upon exiting a trade that was entered at time ENTRYENTRY and closed at time EXITEXIT, the profit (π \pi ) for each leg is calculated, and then summed for the total trade profit. For our short spread example:

πBBNI=NBBNI×(BBNIENTRYBBNIEXIT)πBMRI=NBMRI×(BMRIEXITBMRIENTRY)πTOTAL=πBBNI+πBMRI \pi_{BBNI} = N_{BBNI} × (BBNI_{ENTRY} - BBNI_{EXIT}) \\ \pi_{BMRI} = N_{BMRI} × (BMRI_{EXIT} - BMRI_{ENTRY}) \\ \pi_{TOTAL} = \pi_{BBNI} + \pi_{BMRI}

The logic for a long spread trade is identical, but the long/short actions are reversed.

Performance and Results

I simulated this strategy using Stata over the period of 2006 to 2025. A summary of the strategy’s performance metrics is presented in Table 3.

Table 3. Pairs trading performance summary

Metric Value
Trading Period 2006w39 to 2025w23
Total Number of Trades 62
Win Rate 87.10%
Average Profit per Trade IDR 82.49
Final Cumulative Profit IDR 5,114.23

The strategy was highly effective, executing 62 trades with a remarkable win rate of 87.10%. The cumulative profit from an initial IDR 1,000 investment per trade grew to IDR 5,114.23 by the end of the period.

Figure 6 shows the cumulative profit of the pairs trading strategy versus simple buy-and-hold strategies for both BBNI and BMRI. While the buy-and-hold strategy for BMRI yielded the highest final return (IDR 7,826.09), the pairs trading strategy (IDR 5,114.23) significantly outperformed a buy-and-hold investment in BBNI (IDR 2,985.72). The strategy generated much smoother returns, avoiding the large drawdowns experienced by the buy-and-hold strategies, which are fully exposed to market risk.

Cumulative profit comparison (Rupiah)
Cumulative profit comparison (Rupiah)

However, the strong performance reported in this simulation must be interpreted with some important caveats.

First, the simulation does not account for transaction costs. A pairs trading strategy is, by nature, transaction-intensive. This backtest executed 62 distinct trades, each involving both a long and a short position at entry and exit. In contrast, a buy-and-hold strategy involves only one initial purchase and one final sale. The inclusion of costs such as brokerage commissions, bid-ask spreads, and potential short-term capital gains taxes would reduce the profitability of the pairs trading strategy. Given the high frequency of trades, these costs would have a far more significant impact on its net returns than on those of the buy-and-hold benchmarks.

Second, this simulation considers only the change in prices and does not incorporate dividend payments. This omission likely overstates the relative performance of the pairs trading strategy. A buy-and-hold investor would capture the entire stream of dividends paid by the stock over the nearly two-decade horizon. The pairs trading strategy, however, involves intermittent ownership and would thus miss dividend payments on its long positions when not in a trade. More critically, when holding a short position in a stock over its ex-dividend date, the strategy would be liable for paying the dividend to the lender of the stock, representing a direct cost. A definitive assessment would require a more complex total-return analysis, but it is reasonable to conclude that accounting for dividends would favor the buy-and-hold strategies.

Despite these limitations, the analysis provides strong evidence that the BBNI-BMRI pair has exhibited a durable, mean-reverting relationship that a systematic trading strategy can exploit. Future research should focus on incorporating these real-world frictions to determine the strategy’s net profitability after all costs.

References

Daniel P. Palomar (2025). Portfolio Optimization: Theory and Application. Cambridge University Press.

Engle, R. F., & Granger, C. W. J. (1987). Co-Integration and Error Correction: Representation, Estimation, and Testing. Econometrica, 55(2), 251–276. https://doi.org/10.2307/1913236

Appendix

Appendix A: data and code

  1. Dataset: https://docs.google.com/spreadsheets/d/1omPsIDrCSE16yb5KFZYj1NhHklbb6CQ9bV8PlasThk4/edit?usp=sharing
  2. Stata Code (tested on Stata/MP 19.5): https://github.com/rahmanfadhil/pairs_trading

Appendix B: why multiply with βt\beta_t?

Suppose at time tt, we initiate a short spread trade (short BBNI, long BMRI) with the following parameters:

  • Base investment: V = IDR 1,000,000
  • BBNI price: BBNIt = IDR 5,000
  • BMRI price: BMRIt = IDR 4,000
  • Hedge ratio: βt = 1.25

Scenario 1: with βt\beta_t adjustment

Short BBNI:

  • NBBNI,t=V×BBNIt=1,000,000×5,000=200 sharesN_{BBNI,t} = V \times BBNI_t = 1,000,000 \times 5,000 = \text{200 shares}
  • Value of short position=200×5,000=IDR 1,000,000\text{Value of short position} = 200 × 5,000 = \text{IDR 1,000,000}

Long BMRI:

  • NBMRI,t=(V×βt)/BMRIt=(1,000,000×1.25)/4,000=312.5 sharesN_{BMRI,t} = (V \times \beta_t) / BMRI_t = (1,000,000 \times 1.25) / 4,000 = \text{312.5 shares} For simplicity, round to 312 shares.
  • Value of long position=312×4,000=IDR 1,248,000\text{Value of long position} = 312 \times 4,000 = \text{IDR 1,248,000}.

Assume a market-wide event causes both stocks to rise by 5% the next day:

  • New BBNI price = 5,000 × 1.05 = IDR 5,250
  • New BMRI price = 4,000 × 1.05 = IDR 4,200

Table B1. Impact of a 5% Market-Wide Price Increase

Position Shares Initial Price New Price Profit
Short BBNI 200 5,000 5,250 –50,000
Long BMRI 312 4,000 4,200 +62,400
Net Profit +12,400

Scenario 2: without βt\beta_t adjustment

If we didn’t multiply by βₜ and instead used equal values (e.g., IDR 1,000,000 for both legs):

  • Long BMRI shares = 1,000,000 / 4,000 = 250 shares.
  • Value = 250 × 4,000 = IDR 1,000,000.

Table B2. Impact of a 5% Market-Wide Price Increase

Position Shares Initial Price New Price Profit
Short BBNI 200 5,000 5,250 –50,000
Long BMRI 250 4,000 4,200 +50,000
Net Profit 0

Tags: Finance