quantlab.factor.kunquant_ts#

Custom KunQuant time-series operators: each symbol against its own past.

KunQuant is the library this project uses to compute most factors. A factor formula is written as a graph of operators (WindowedAvg, Rank, …), and KunQuant compiles that graph to native C++ code that runs over a whole (timestamp, symbol) array at once. This module adds operators that look along time, one symbol at a time; quantlab.factor.kunquant_cs has the ones that look across symbols on one bar.

WindowedZScore is a time-series normalization: each symbol is compared with its own recent past. Its cross-sectional counterpart, kunquant_cs.CrossSectionalZScore, compares each symbol with all the other symbols on the same bar. Which one is right depends on the strategy that consumes the factor. A strategy that trades one asset over time wants the first; a strategy that ranks many assets against each other wants the second. They are not two implementations of the same thing.

The exponentially weighted window statistics (EWSum, EWMean, EWVar, EWCov, EWBeta, EWAlpha, EWResidualStd) weight the trailing window bars by 0.5 ** (age / half_life), where age is 0 for the current bar, and skip missing values. CMRA is USE4’s cumulative range of monthly returns. BarraStyle (quantlab.factor.predefined.barra) uses them; any factor can.

Classes

CMRA

USE4's cumulative range of monthly returns, from a series of daily log returns.

EWAlpha

Intercept of the exponentially weighted least-squares fit of y on x.

EWBeta

Slope of the exponentially weighted least-squares fit of y on x.

EWCov

Exponentially weighted window covariance of y and x.

EWMean

Exponentially weighted window mean, sum(w * x) / sum(w) over valid bars.

EWResidualStd

Standard deviation of the residual of EWBeta's fit of y on x.

EWSum

Exponentially weighted window sum, sum(w_age * x) over valid bars.

EWVar

Exponentially weighted window variance, sum(w * (x - m)**2) / sum(w).

WindowedZScore

Rolling z-score along time, (x - rolling_mean) / rolling_std.