Skip to content
All library documents

Using Cointegration Vectors to Build Mean-Reverting Portfolios

Article MQL5 code base

Summary

This code excerpt describes two operations used in a cointegration-based statistical arbitrage workflow. The first multiplies each asset’s price series by the corresponding coefficient in a cointegration vector and sums across assets, producing a portfolio value series that can be examined for mean-reverting trading signals. If no vector is supplied, it uses the first stored vector, described as the one associated with the largest eigenvalue.

The second operation rescales a cointegration vector so its first coefficient equals one. The resulting weights express the other assets’ quantities relative to one unit of the first asset. These routines provide portfolio construction mechanics, but do not show how to estimate or validate cointegration, generate entry and exit signals, size positions, or account for transaction costs. The code assumes compatible asset columns and vector entries, and its output alone does not establish that a portfolio will remain mean reverting.

Key ideas

  • A cointegration vector weights asset prices to form a portfolio value series.\nThe resulting series can be analyzed for mean-reverting trade signals.\nWhen no vector is provided, the implementation selects the first stored vector.\nScaling by the inverse of the first coefficient expresses weights relative to one unit of the first asset.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.