Class BacktestAttribution
For step s (bar b → b+1) with book h held over
the bar, cross-sectional factor returns f and specific returns
u from a FactorRiskModel regression of that bar
(exposures X at close(b)):
factor_k = (Σ_i h_i X_ik) f_k specific = Σ_i h_i u_i trading = Σ_i pnl_i − factor − specific net = factor + specific + trading + cost + financing (exact)
This is the holdings-based decomposition with a trading residual (Menchero and Hu 2006, "Portfolio Risk Attribution", J. Performance Measurement 10(3), for the factor/specific split; the trading term is the transaction-based correction of Brinson-style attribution). The trading term holds intrabar fills (a next-open fill earns a different bar return than the book held at the close), terminal events of names outside the regression and compounding across the open. With close fills it is zero to rounding for names inside the regression.
Legs and sectors split Σ_i pnl_i: a name is long or short by
the sign of its weight over the bar, or after the fill when it was not
held. Components are fractions of equity at the start of each bar;
totals are arithmetic sums over bars.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BacktestAttributionattribute(AlphaContext ctx, AlphaBacktester.Traced traced, String[] sectors, AlphaRiskModels.Spec spec) Attributes a traced run.doublecost(int s) doubledoublecumulativeFactor(int k) Sum over steps of factork's P&L.doubledoubledoubledoublecumulativeSector(int j) doubledoubledoubledoublefactor(int s, int k) P&L from factorkin steps.doublefactorTotal(int s) P&L from all factors in steps.doublefinancing(int s) format()A plain-text table of the cumulative components.doublelongLeg(int s) doublenet(int s) Net return of steps.doublesector(int s, int j) doubleshortLeg(int s) doublespecific(int s) intsteps()doubletrading(int s)
-
Method Details
-
attribute
public static BacktestAttribution attribute(AlphaContext ctx, AlphaBacktester.Traced traced, String[] sectors, AlphaRiskModels.Spec spec) Attributes a traced run. The factor model is a single ex-post estimate over the traced bars, so each bar's factor returns come from that bar's own cross-section. The bars before the trace must cover the style lookbacks ofspec.- Parameters:
sectors- sector label per symbol in context order (null = one sector)spec- style lookbacks and model settings (its window is replaced by the trace length)
-
factorNames
-
sectorNames
-
steps
public int steps() -
factor
public double factor(int s, int k) P&L from factorkin steps. -
factorTotal
public double factorTotal(int s) P&L from all factors in steps. -
specific
public double specific(int s) -
trading
public double trading(int s) -
cost
public double cost(int s) -
financing
public double financing(int s) -
longLeg
public double longLeg(int s) -
shortLeg
public double shortLeg(int s) -
sector
public double sector(int s, int j) -
net
public double net(int s) Net return of steps. -
cumulativeFactor
public double cumulativeFactor(int k) Sum over steps of factork's P&L. -
cumulativeSpecific
public double cumulativeSpecific() -
cumulativeTrading
public double cumulativeTrading() -
cumulativeCost
public double cumulativeCost() -
cumulativeFinancing
public double cumulativeFinancing() -
cumulativeLong
public double cumulativeLong() -
cumulativeShort
public double cumulativeShort() -
cumulativeSector
public double cumulativeSector(int j) -
cumulativeNet
public double cumulativeNet() -
format
A plain-text table of the cumulative components.
-