Class Factors
AlphaFactor producing raw cross-sectional scores where
higher = more attractive long (see the interface contract).
Sign conventions are chosen so every factor is usable long/short as-is:
- Trend (MA crossover, MACD, momentum) score positively when the trend is up;
- Mean reversion (RSI, Bollinger, mean reversion) score positively when the price is depressed — the contrarian orientation, since these signals bet on the snap-back;
- Defensive/fundamental (value, quality, low volatility) score positively for cheap, profitable, calm names — the Fama-French/AQR orientation of each anomaly.
All computations read only bars <= index (the no-look-ahead
contract) and cost O(window) per symbol per call — stateless by design so
factors are trivially safe to evaluate at arbitrary dates, at the price
of recomputing windows the streaming indicators would carry. EMAs are
truncated at 4× their period, where the dropped tail weight is
(1−2/(p+1))^{4p} < 0.04% — far below signal noise.
-
Method Summary
Modifier and TypeMethodDescriptionstatic AlphaFactorbollinger(int period, double stdDevs) Bollinger mean reversion:−(close − SMA) / (k·σ)— the negative band position, +1 at the lower band, −1 at the upper.static AlphaFactorlowVolatility(int lookback) Low-volatility anomaly:−σ(returns)over the lookback — calm names score high.static AlphaFactormacd(int fast, int slow, int signal) MACD histogram normalized by price:(macdLine − signalLine) / close.static AlphaFactormeanReversion(int lookback) Plain mean reversion:−(close / SMA − 1)— how far the price sits below its own average, as a fraction.static AlphaFactormomentum(int lookback, int skip) Cross-sectional momentum:close[i−skip] / close[i−lookback] − 1.static AlphaFactormovingAverageCrossover(int fast, int slow) Moving-average crossover:(SMA_fast − SMA_slow) / SMA_slow.static AlphaFactorquality()Quality composite: profitability minus leverage —ROE − 0.1 × debt/equity.static AlphaFactorrsi(int period) Contrarian RSI:(50 − RSI) / 50, in [−1, +1].static AlphaFactorvalue()Value composite: the average of earnings yield (1/PE) and book yield (1/PB) — yields, not ratios, so "cheap" is high and negative-earnings names contribute a negative yield rather than a meaningless negative PE rank.
-
Method Details
-
movingAverageCrossover
Moving-average crossover:(SMA_fast − SMA_slow) / SMA_slow. Positive when the fast average rides above the slow — the % spread makes scores comparable across price levels. -
macd
MACD histogram normalized by price:(macdLine − signalLine) / close. Positive while bullish momentum is accelerating; the price normalization keeps a $10 and a $1000 stock on one scale. -
momentum
Cross-sectional momentum:close[i−skip] / close[i−lookback] − 1. The academic 12-1 form when called asmomentum(252, 21)— skipping the last month sidesteps short-term reversal (Jegadeesh-Titman 1993). -
rsi
Contrarian RSI:(50 − RSI) / 50, in [−1, +1]. Oversold names (RSI 30 → +0.4) score positively.Definition note: this is Cutler's RSI (arithmetic average of gains/losses over the window), chosen because it is stateless and exactly recomputable at any bar. It is NOT the same number as
indicators.Indicators#rsi, which uses Wilder smoothing — after a trend the two can disagree near the 30/70 thresholds. The factor name says so to keep reports unambiguous. -
bollinger
Bollinger mean reversion:−(close − SMA) / (k·σ)— the negative band position, +1 at the lower band, −1 at the upper. -
meanReversion
Plain mean reversion:−(close / SMA − 1)— how far the price sits below its own average, as a fraction. -
value
Value composite: the average of earnings yield (1/PE) and book yield (1/PB) — yields, not ratios, so "cheap" is high and negative-earnings names contribute a negative yield rather than a meaningless negative PE rank. NaN without fundamentals. -
quality
Quality composite: profitability minus leverage —ROE − 0.1 × debt/equity. The 0.1 haircut puts one turn of leverage on the same scale as 10 points of ROE, the usual quality-minus-junk shape (profitable AND conservatively financed). -
lowVolatility
Low-volatility anomaly:−σ(returns)over the lookback — calm names score high. Ranking only needs the negative sign, not annualization.
-