Class PointInTimeUniverse
java.lang.Object
com.quantfinlib.data.PointInTimeUniverse
Point-in-time universe membership — the engine-side half of
survivorship-bias-free backtesting.
Survivorship bias enters when a backtest's universe is built from today's constituents: every bankruptcy, acquisition and delisting has already been silently removed, so the strategy only ever "picks" from winners. Removing the bias needs two things:
- Data — historical membership including dead tickers, and delisting returns (what a holder actually received). This class cannot conjure that; it comes from CRSP-style datasets.
- Engine — screens and rebalances that only see members
as of each date, and positions that terminate correctly
when a security dies. That is what this class provides, consumed by
screener.StockScreener#membersAsOfand the universe-awarebacktest.portfolio.PortfolioBacktesteroverload.
Per symbol it records membership intervals (a symbol can leave and rejoin an index) and at most one terminal event:
PointInTimeUniverse.EventType.DELISTINGwith a delisting return — the final-day return relative to the last close (−1 = shareholders got nothing). When the true value is unknown for an involuntary delisting, the literature's convention isDEFAULT_INVOLUNTARY_DELISTING_RETURN(Shumway 1997).PointInTimeUniverse.EventType.MERGERwith per-share deal terms: cash and/or shares of the acquirer.
Timestamps use the same epoch units as the BarSeries being
backtested. Not thread-safe during construction; effectively immutable
afterwards if not mutated.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow a security's life ends.static final recordA security's terminal event. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe standard haircut for involuntary delistings with unknown proceeds: −30% on the last traded price (Shumway, Journal of Finance 1997). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddMembership(String symbol, long fromTimestamp) Membership from a date with no known end (a current constituent).addMembership(String symbol, long fromTimestamp, long toTimestampInclusive) Adds a membership interval (inclusive of both endpoints).Every symbol that ever appears in this universe (living and dead).booleanWhether the symbol is a universe member attimestamp: inside a membership interval and not past its terminal event.membersAsOf(long timestamp) All members as of a timestamp, sorted for determinism.recordDelisting(String symbol, long timestamp, double delistingReturn) Records a delisting: membership (if any) is truncated at the event and the position terminates atlastClose × (1 + delistingReturn).recordMerger(String symbol, long timestamp, double cashPerShare, double acquirerSharesPerShare, String acquirer) Records a merger/acquisition: at the event each held share converts tocashPerSharecash plusacquirerSharesPerShareshares ofacquirer.terminalEvent(String symbol) The symbol's terminal event, ornullwhile it lives.
-
Field Details
-
DEFAULT_INVOLUNTARY_DELISTING_RETURN
public static final double DEFAULT_INVOLUNTARY_DELISTING_RETURNThe standard haircut for involuntary delistings with unknown proceeds: −30% on the last traded price (Shumway, Journal of Finance 1997).- See Also:
-
-
Constructor Details
-
PointInTimeUniverse
public PointInTimeUniverse()
-
-
Method Details
-
addMembership
public PointInTimeUniverse addMembership(String symbol, long fromTimestamp, long toTimestampInclusive) Adds a membership interval (inclusive of both endpoints). A symbol may hold several disjoint intervals — index drop and later re-add. -
addMembership
Membership from a date with no known end (a current constituent). -
recordDelisting
Records a delisting: membership (if any) is truncated at the event and the position terminates atlastClose × (1 + delistingReturn). UseDEFAULT_INVOLUNTARY_DELISTING_RETURNwhen the true proceeds are unknown. -
recordMerger
public PointInTimeUniverse recordMerger(String symbol, long timestamp, double cashPerShare, double acquirerSharesPerShare, String acquirer) Records a merger/acquisition: at the event each held share converts tocashPerSharecash plusacquirerSharesPerShareshares ofacquirer. All-cash deals pass 0 shares and a null acquirer. -
isMember
Whether the symbol is a universe member attimestamp: inside a membership interval and not past its terminal event. -
membersAsOf
-
terminalEvent
The symbol's terminal event, ornullwhile it lives. -
allSymbols
-