Class AlphaContext
Everything in com.quantfinlib.alpha works cross-sectionally:
at a bar index, a factor scores every symbol, and downstream steps
(evaluation, construction, backtest) consume those scores as arrays
aligned with symbols(). Freezing the symbol order once here is
what makes plain double[] the interchange type for the whole
pipeline — no per-step map lookups, no ordering ambiguity.
Series must be index-aligned (same length, same bar times — see
data.SeriesAligner); the constructor enforces equal length, the
timestamp discipline is the caller's (documented) responsibility.
Fundamentals are an optional static snapshot: factors that need them
(Factors.value(), Factors.quality()) return NaN for
symbols without entries. A point-in-time fundamentals history is data
this library cannot invent — the snapshot is honest about that.
Survivorship: alpha research is the stage survivorship bias
flatters most — the delisted losers a short book would have held are the
exact names a today's-constituents panel lacks. Attach a
PointInTimeUniverse via withUniverse(com.quantfinlib.data.PointInTimeUniverse) and every built-in
factor scores non-members/dead names as NaN at each bar
(isActive(int, int)), so ICs, validation and constructed weights only ever
see the point-in-time cross-section. Without a universe the panel is
survivorship-blind — fine for methodology work, dishonest for
performance claims. Custom AlphaFactors should honor
isActive the same way. Note the weight-based
AlphaBacktester still earns ghost returns on a name that dies
mid-hold (weights only change at rebalances); for
lifecycle-exact accounting feed the weights into
backtest.portfolio.PortfolioBacktester's survivorship-aware
overload.
-
Method Summary
Modifier and TypeMethodDescriptionintbars()Panel length in bars (every series has exactly this many).fundamentals(int i) Fundamentals for symbol indexi, ornullwhen unknown.booleanisActive(int i, int barIndex) Whether symboliis in the tradeable cross-section atbarIndex: always true without a universe, otherwise point-in-time membership (dead and dropped names excluded).static AlphaContextPanel without fundamentals (technical factors only).static AlphaContextPanel with a fundamentals snapshot for value/quality factors.doublereturnOver(int i, int fromIndex, int toIndex) Simple return of symboliover(fromIndex, toIndex]— the forward-return building block evaluation and backtesting share.series(int i) Price series for symbol indexi(the panel axis, not the bar).intsymbols()The frozen symbol order every score/weight array aligns with.longtimestamp(int index) Bar timestamp atindex(taken from the first series).withUniverse(PointInTimeUniverse universe) The same panel with a point-in-time universe attached: built-in factors then score non-members as NaN per bar (see the class doc).
-
Method Details
-
of
Panel without fundamentals (technical factors only). -
of
Panel with a fundamentals snapshot for value/quality factors. -
withUniverse
The same panel with a point-in-time universe attached: built-in factors then score non-members as NaN per bar (see the class doc). Universe timestamps must be in the same units as the bar timestamps. -
isActive
public boolean isActive(int i, int barIndex) Whether symboliis in the tradeable cross-section atbarIndex: always true without a universe, otherwise point-in-time membership (dead and dropped names excluded). -
symbols
-
symbolCount
public int symbolCount() -
bars
public int bars()Panel length in bars (every series has exactly this many). -
series
Price series for symbol indexi(the panel axis, not the bar). -
fundamentals
Fundamentals for symbol indexi, ornullwhen unknown. -
timestamp
public long timestamp(int index) Bar timestamp atindex(taken from the first series). -
returnOver
public double returnOver(int i, int fromIndex, int toIndex) Simple return of symboliover(fromIndex, toIndex]— the forward-return building block evaluation and backtesting share.
-