Skip to content
All library documents

Optimal Entry and Exit Levels for Ornstein–Uhlenbeck Mean Reversion

Code Stratmill research code

Summary

The code implements an Ornstein–Uhlenbeck model for mean-reverting portfolios and pairs of assets. It fits the model’s long-run mean, reversion speed, and noise variance to historical prices, then uses an optimal double-stopping framework to calculate entry and liquidation levels. It also supports transaction costs, discount rates, a user-defined stop-loss, and a half-life calculation for the fitted process.

For two assets, the model constructs a portfolio using a relative investment coefficient, intended to capture their co-movement. This offers a quantitative framework for deciding when to enter and exit a mean-reversion trade rather than relying on fixed thresholds alone. The excerpt gives no empirical results or trading validation, and fitted levels depend on the selected training data and model assumptions. The visible text is incomplete, so it does not permit a full review of the implementation or its numerical safeguards.

Key ideas

  • The model fits an Ornstein–Uhlenbeck process to portfolio or paired-asset price data.
  • It computes optimal entry and liquidation levels through a double-stopping formulation.
  • Transaction costs, discount rates, and an optional stop-loss are included in the setup.
  • The fitted reversion speed is used to calculate the process half-life.
  • The excerpt provides no empirical validation and is incomplete, limiting code assessment.

Tags

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