Portfolio & pairs#
Rank assets against each other, turn scores into weights, backtest a book of many assets from one account, and trade pairs.
Cross-sectional#
Transforms across the assets of one time step: ranks, z-scores, demeaning, winsorizing, weight normalization, and the dispersion of a row.
Function |
Description |
|---|---|
Subtract the mean across assets at each step, removing the common component. |
|
Scale each row of scores to portfolio weights with a chosen gross exposure, and optionally a net exposure. |
|
Rank each asset against the others at the same step, scaled to [-1, 1] or [0, 1]. |
|
Standard deviation across the assets of each step: one dispersion value per row. |
|
+1 for the highest values of each row, -1 for the lowest, 0 for the rest. |
|
Clip each asset's value to the lower and upper quantiles of its row. |
|
Standardize each asset against the others at the same step: (x - mean) / std across the row. |
Portfolio backtesting#
Backtest many assets from one shared account: weights, rebalancing, exposure limits, and book statistics.
Function |
Description |
|---|---|
Backtest K assets traded toward per-asset targets from one shared capital account on OHLC bars, executed delay bars later at a chosen bar price. |
|
Backtest K assets traded toward per-asset target weights, notionals, or positions from one shared capital account, filled at each step's price. |
|
Reduce a multi-asset backtest engine output into causal portfolio-level report columns. |
Pairs & mean reversion#
Hedge ratios, spreads, stationarity tests, and entry and exit rules for a pairs trade.
Function |
Description |
|---|---|
Three-state mean-reversion position from a z-score: short above +entry, long below -entry, flat again inside the exit level, with an optional stop and lockout. |
|
Regression with a random-walk intercept and slope, estimated by a Kalman filter: the dynamic hedge ratio of a pairs trade, its spread, and the spread's predicted deviation. |
|
Rolling augmented Dickey-Fuller t-statistic: how strongly a series, such as a pairs spread, reverts to a mean over the last window. |
|
Rolling MLE fit of a mean-reverting Ornstein-Uhlenbeck process. |
|
Rolling hedge-adjusted residual x - beta * y, with beta the rolling regression slope. |
|
Rolling total least squares (orthogonal regression) slope of the first input on the second: a hedge ratio that does not depend on which leg is called dependent. |