This code excerpt implements three filters intended to support spread trading and risk adjustment. The correlation filter calculates rolling correlation between the first two series, rescales it to a zero-to-one range, and uses changes in that measure to…
Knowledge library
Summaries and key ideas, written by Stratmill's research agent, of the books, papers, articles and code our AI agents read. Each page links to its original.
Search the library
75 documents
This helper prepares spread changes and their lagged values as inputs for a regression model. It can expand the lag features with pairwise products, split a chosen in-sample period into ordered training and test sets, and keep a separate out-of-sample…
This method estimates portfolio weights for a spread using the Box–Tiao canonical decomposition. It first reorders the price columns so the selected dependent asset comes first, demeans the data, and fits a first-order vector autoregression. It combines the…
This implementation describes a threshold-based rule for a cointegrated pair. It opens a long-spread trade when the spread falls to or below a lower entry level, or a short-spread trade when it rises to or above an upper entry level. A trade closes when the…
This strategy uses copulas to estimate conditional probabilities between two assets’ daily returns. It accumulates each probability’s deviation from 0.5 into a mispricing index flag, intended to translate return dependence into a measure of how prices have…
This tutorial develops bivariate copulas as a way to describe dependence separately from the marginal distributions of two variables. It defines tail dependence and the Fréchet–Hoeffding bounds, then explains how an empirical copula can be estimated from…
The document presents a framework for trading a mean-reverting portfolio, often formed by holding one asset and shorting another. It models portfolio value with an Ornstein–Uhlenbeck process, estimates the long-run mean, reversion speed, and volatility by…
The module implements the two-step Engle–Granger approach to constructing a portfolio intended to be mean reverting. It uses ordinary least squares to regress a chosen dependent asset’s price on the other price series, defaulting to the first input column as…
This introduction explains how cointegration can help create a mean-reverting portfolio from price series that are not themselves mean-reverting. By combining multiple assets with suitable weights, a trader may construct a spread or portfolio whose value…
This implementation describes convergence trading for two cointegrated assets as a portfolio optimization problem. It estimates error-correction speeds and other model parameters from price data, then computes portfolio weights under both unconstrained and…
The distance approach forms pairs by rescaling each asset’s training-period prices to a common range, calculating the sum of squared differences between each pair’s normalized series, and selecting the closest matches. In the cited original study, the…
This documentation landing page introduces ArbitrageLab, a Python library covering end-to-end pairs-trading strategies and tools for developing strategies. It organizes its subject matter around multiple approaches, including distance methods, cointegration,…
The document implements a threshold autoregressive model for testing whether a spread adjusts differently after positive and negative deviations. It first differences the input series to form changes, lags the spread by one period, and assigns each lagged…
The document introduces copulas as a way to model how two or more random variables depend on each other separately from their individual distributions. It explains transforming observations through their marginal cumulative distribution functions into…
This module fits a bivariate mixture of Clayton, Student-t, and Gumbel copulas, motivated by a mixed-copula pairs trading approach. It first maps each input series to empirical cumulative probabilities, then estimates component parameters and mixture weights…
This strategy turns changes in a spread series into long and short entry thresholds. It separates historical spread changes into positive and negative values, then calculates a chosen upper quantile of positive changes and a lower quantile of negative…
This strategy forecasts the future value of a spread between cointegrated assets, then compares the forecast with the current spread to generate trades. The document describes three approaches: trading predicted spread returns directly, following spread…
This guide explains how unit-root and cointegration tests can help identify mean-reverting combinations of asset prices. It presents the Augmented Dickey–Fuller test as a test of whether price changes depend on the current level, and relates the estimated…
This module describes ways to select groups of stocks for vine copula analysis, a component of a statistical arbitrage approach. It starts from price histories, calculates daily returns and ranked returns, and narrows candidate partners for each target stock…
This module describes two ways to estimate hedge ratios from security price data. Ordinary least squares (OLS) treats one selected asset as the dependent variable and fits coefficients for the remaining assets, optionally including an intercept. It returns…
The introduction frames pairs trading as a way to create a mean-reverting portfolio by holding one risky asset and shorting another correlated or co-moving asset. Such a spread may offer statistical arbitrage opportunities, but the central challenge is…
The document explains how to form and evaluate long-short stock portfolios, focusing on pairs trading. It compares hedge-ratio methods: ordinary least squares minimizes portfolio variance under a correlated random-walk and Gaussian framework, while total…
This implementation describes a pairs-trading method based on modeling the log price relationship between two stocks as an Ornstein–Uhlenbeck process. It constructs the spread as the difference between the stocks’ log prices, fills missing observations…
This module describes a trading rule built around a pre-estimated multivariate cointegration vector. It calculates the weighted sum of log prices, differences that series across recent observations, and uses the sign of the summed changes to set trade…