Every operator in qex, one line each. Each family also has a page where every operator has an entry: its signature,
what it does, how it treats missing values, and examples, most with a worked example on toy data.
In the signatures:
x, y are expressions: anything that gives a value per date and stock;
period, n, window, halflife are whole numbers of days or values; q, limit are numbers;
'name' is a quoted field or group name; groups is a group's name or any expression giving labels;
Four stocks, A to D, over six trading days. C has no price on Jan 04. A and B are Tech, C and
D are Energy. surprise is an earnings surprise, reported on four days; beta is each stock's market beta (1.4, 0.7, 1.1 and 0.8);
price is the as-traded close (with no splits or dividends, the same as close()); and the data also has a market
series.
The worked examples evaluate their expressions on this data when the docs are built, so every number is what qex
computes. A dot is a missing value.
Regressions and correlations through time: one fit per stock, over its own window. For a regression across
the stocks on each day, see regression_neut under Cross-sectional.
Operation
Description
ts_corr(x, y, period[, min_periods])
Correlation of x and y over the window. Part of the window
ts_cov(x, y, period[, min_periods])
Covariance over the window. Part of the window
ts_beta(y, x, period[, min_periods])
Least-squares slope of y on x, cov(y, x) / var(x), over the window. Part of the window
ts_beta, pulled toward the day's average beta (or with groups, its group's) in proportion to its noise (Vasicek). Part of the window
ts_alpha(y, x1, ..., xk, period[, min_periods])
Intercept of y on one or more regressors over the window, from one joint least-squares fit on the days all have a value; with one, mean(y) − beta × mean(x). Part of the window
Carry each value forward over the missing days after it, at most limit days; with no limit, until the next value
latch(on, off)
1 from a day on is true until a day off is true (off wins a tie), then 0 until on again; 0 before on is first true; a day where either is missing changes nothing
ts_mean_events(x, n[, min_n])
Mean of the last n values x has had, however far back; a value every day once there are min_n (default n)
ts_std_events(x, n[, min_n])
Standard deviation of the last n values, once there are min_n
ts_sum_events(x, n[, min_n])
Sum of the last n values, once there are min_n
ts_count_events(x, period)
How many values x has in the last period days; an answer every day once period days have passed
days_since(x)
Trading days since x was last nonzero: 0 on the day, 1 the day after; missing before it first is; no window
Percentile rank among the day's stocks, from 1/n to 1, lowest first; ties share their average rank
zscore(x)
(x − mean) / standard deviation across the day's stocks; missing when they don't vary
gaussrank(x)
The day's rank mapped through the inverse normal, Φ⁻¹((r − 0.5)/n): a z-score's shape without its outliers; ties share the average score, so each day sums to zero
demean(x)
x minus the day's mean
scale(x)
Divide by the day's sum of absolute values, so they sum to 1
quantile(x, n)
Bucket 1 (lowest) to n by percentile rank
winsorize(x, limit)
Clip at the day's limit and 1 − limit quantiles: winsorize(x, 0.05) caps at the 5th and 95th percentiles
truncate(x, max)
Clip each value to [−max, max] (element by element, not across stocks)
regression_neut(y, x1, x2, ...)
One regression per day, across the stocks (not through time): y with its least-squares fit on the regressors (and an intercept) taken out
regression_alpha(y, x1, ..., xk)
The intercept of regression_neut's fit: one number per day, the same for every stock
regression_beta(y, x1, ..., xk, j)
The j-th slope of regression_neut's fit: one number per day, the same for every stock; with one regressor j may be left out
pca_factor(x, window, k[, refit])
Each stock's beta to the k-th statistical factor of x, from a principal component analysis across stocks, refit every refit days (default 21)
The value of each stock's twin: the stock whose key over the last lookback days was most alike, chosen every rebalance days from the past only; options by name
How alike each stock and its twin were when chosen: a correlation, or a distance for the distance metrics; reads the same selection as ts_match; options by name