Skip to content

AdvancedStrategiesPython

Run this module

cd "Strategies - Statistical Arbitrage"
python "stat_arb.py"

View source on GitHub


Strategies - Statistical Arbitrage

This module demonstrates a basic Statistical Arbitrage strategy, specifically pairs trading.

Concepts

  • Cointegration: A statistical property of a collection of time series variables. If two or more series are themselves non-stationary, but a linear combination of them is stationary, then the series are said to be cointegrated.
  • Pairs Trading: Identifying two cointegrated assets and trading the spread between them. When the spread widens beyond a historical norm (measured by z-score), you short the outperforming asset and long the underperforming one, betting the spread will revert to the mean.

Example

Run python stat_arb.py to see a demonstration of testing cointegration and generating entry/exit signals based on the z-score of the spread.


Continue in Strategies

  • Order Execution Simulator

    This utility does NOT use any external APIs. All trades and portfolio data are managed locally for learning and experimentation.

  • Strategies - Backtesting Engine

    A backtest answers one question: *if I had traded this rule, what would have

  • Strategies - Market Making

    Implementation of the Avellaneda-Stoikov (2008) continuous-time market making model. A dealer posts bid/ask quotes to maximize expected PnL while penalizing inventory accumulation.

  • Strategies - Mean Reversion

    Mean reversion is the statistical tendency for an asset's price to return to its historical average after deviating from it. While Momentum strategies bet on continuation, Mean Reversion strategies bet on reversal — buying when something is "too cheap" and selling when it is "too expensive" relative to recent history.

  • Strategies - Momentum Trading

    Momentum trading is a strategy that capitalizes on the continuance of existing trends in the market. The core philosophy is "buy high, sell higher." If an asset's price is rising strongly, momentum traders assume it will continue to rise.

  • Strategies - Pairs Trading

    This module demonstrates a statistical arbitrage strategy known as Pairs Trading. It identifies two assets that move together and trades the convergence of their spread. When the correlation weakens temporarily, executing trades on both assets allows for capturing profits as they revert to their historical relationship. This quantitative technique relies strictly on mathematical relationships rather than fundamental valuation.

Browse all modules Learning paths