Factor Model#

Decomposes portfolio return into per-factor contributions plus an idiosyncratic residual, using user-supplied factor return series (style factors such as size, momentum, beta, residual volatility and value, plus industry factors).

Formulas#

For each date:

\[\begin{split}\text{factor\_contribution}_f &= \sum_{\text{assets}} \text{weight}_{\text{asset}} \cdot x_{f,\text{asset}} \\ \text{portfolio\_return} &= \sum_{\text{assets}} \text{weight}_{\text{asset}} \cdot \text{asset\_return}_{\text{asset}}\end{split}\]

where \(x_{f,\text{asset}}\) is the cell of factor file \(f\): the asset’s contribution from that factor on that date, i.e. its exposure to the factor times the factor’s return. It is not the factor return itself; supply exposure x return.

Contributions are accumulated over time with multi-period linking (see below). The percentage decomposition divides each factor’s contribution by the total return and captures the unexplained part as an idiosyncratic residual: column f_idio_returns in the daily shares, key idio_returns in the cumulative shares and column idiosyncratic_returns in the cumulative totals (Conventions and limitations lists every name).

The idiosyncratic residual is the portfolio’s own return minus the sum of factor contributions, daily and cumulatively. Files named f_total_factor_returns, f_total_excess_returns and f_idyo_returns hold vendor totals: they are not loaded (an INFO line names them), so they never count as factors and never change the date window. f_market is an ordinary factor. The cumulative shares divide by the portfolio’s own total return (compounded when linking) over the dates that have both factor data and a portfolio return (a warning counts the excluded dates). A date on which no held asset has a return, such as the first price date, has no portfolio return (null, not 0), so it is excluded from the shares and from the dashboard’s summary statistics. If the factor files hold excess-of-cash returns, the cash return lands in the residual.

A date that has a portfolio return but no factor attribution (no factor file has a row for it, or nothing has a non-zero weight on it) is left out of the cumulative contributions, shares and totals, so their cumulative portfolio return omits that date’s return and differs from the portfolio’s own, which the summary statistics still include. One warning per model gives the number of such dates and the first one; a date whose return is 0 (for example a day held entirely in cash) is not counted, since leaving it out changes no total. Nothing is filled in: give the factor files every date of the weights to attribute the whole period.

The dates are attributed in ascending order whatever the row order of the weights: the model sorts the weights by date first, so every daily and cumulative table runs from the first date to the last and linking compounds in date order. The sort is stable (the rows of a repeated date keep their order), and string dates sort as text, so give them as ISO-8601 (YYYY-MM-DD). A weights row without a date is dropped, with a warning. The factor files, the asset returns and a pre-computed portfolio_returns are matched to the weights by date, so their row order does not matter.

Set factor_return_type = log when the factor files hold log returns. Each stock-day’s factor total \(TF = \sum_k a_k\) is restated as \(e^{TF} - 1\) and shared out in proportion to the original contributions, \(a_k (e^{TF} - 1)/TF\), so the factors are in the same units as the simple asset returns they are compared with. Without this the log/simple gap lands in the residual. In log mode, infinite values, duplicate dates within a factor file, or date types that differ between factor files raise an error.

Multi-period linking#

Each date’s factor contributions plus the residual add up to that date’s portfolio return, but their plain sum over time does not add up to the compounded return \(R_T = \prod_{t \le T}(1 + r_t) - 1\). With linking_method = carino (the default) the cumulative contributions are linked as in Multi-period linking with a zero benchmark (\(b = 0\)): each date’s contribution \(e_t\) is scaled by \(k(r_t, 0) / k(R_T, 0)\), where \(k(x, 0) = \ln(1 + x) / x\). At every date the cumulative factor contributions plus the residual then add up to the compounded portfolio return, and the cumulative shares divide by that compounded total. grap is the alternative. none keeps plain running sums and a share total equal to the sum of the daily portfolio returns (no linking, the behaviour of 0.3.x and earlier).

When linking, the cumulative factor table (simulated_rets) covers only the dates that have a portfolio return, so the first price date is excluded; a warning, logged once per model, counts the dropped dates. The run raises PerformanceAttributionError, naming the date, for a portfolio return of -100% or below or a non-finite one (for example from a zero price), or a non-finite factor contribution. The dashboard’s daily decomposition view still covers every attribution date; only the cumulative views skip dates without a portfolio return.

Return components: carry and dividends#

Two file names in the factor folder are reserved for return components that are not factors: f_carry.csv and f_dividends.csv (matched whatever the case of the file name, as the vendor totals above are). They use the factor-file format (date x ticker), and each cell is the asset’s simple carry or dividend return that day. They are computed like a factor (\(\sum w \cdot x\)) but reported as their own components:

\[\text{idiosyncratic}_t = r_{p,t} - \sum_f \text{factor\_contribution}_{f,t} - \text{carry}_t - \text{dividends}_t\]
  • They are never restated from log to simple returns, even with factor_return_type = log, and they are not part of the per-asset factor total \(TF\) that the restatement shares out. In log mode they are still checked like the factor files (no duplicate dates, no infinite values, the same date type).

  • They have their own columns in contributions, cumulative_contributions and daily_shares, and their own keys in cumulative_shares. In cumulative_totals they have their own columns (carry_returns, dividends_returns) only when the file is present; an absent file adds no column, rather than a column of zeros that would claim a measured zero. factor_returns excludes them.

  • They are linked like the factors (\(b = 0\)), so factors, components and the residual still add up to the compounded portfolio return.

  • When the files are loaded they are ordinary factor files: a component file that covers fewer dates than the other inputs narrows the common date window like any factor file. The factor-coverage INFO line ignores them (a carry file alone would otherwise report full coverage).

  • The charts draw them with the totals (“Carry”, “Dividends”), never among the style or industry factors, and the decomposition charts label them “Carry” and “Dividends”.

A component must already be inside the asset returns, which are computed from the price files. With f_dividends, the price files must be total-return (dividend-adjusted) prices. Otherwise the component is subtracted from a return that never contained it, and the residual is understated by the same amount.

Active factor attribution#

With active_factor_model on (set from Python, see Options set from Python), the active return \(r_{p,t} - r_{b,t}\) is decomposed as well. The same model runs on the benchmark’s constituent weights (holdings basis) with the same factor files, already restated when they are log returns:

\[\begin{split}a_{f,t} &= \sum_i w^P_{i,t}\, x_{f,i,t} - \sum_i w^B_{i,t}\, x_{f,i,t} \\ \text{active\_idiosyncratic}_t &= (r_{p,t} - r_{b,t}) - \sum_f a_{f,t} - a_{\text{carry},t} - a_{\text{dividends},t}\end{split}\]

Here \(r_{b,t} = \sum_i w^B_{i,t} r_{i,t}\) is the holdings benchmark return. Each date’s active effects add up to \(r_{p,t} - r_{b,t}\).

The cumulative active effects are linked with linking_method, using \(b = r_b\), the same way Brinson-Fachler links its effects (Multi-period linking). With carino or grap they add up to the compounded \(R_p - R_b\) on every date; with none they are running sums.

Requirements, as for textbook Brinson-Fachler:

  • factor_model_method on, and benchmark weights (the benchmark weights file, or benchmark_weights for a Backtest-Engine run);

  • a price file for every constituent with a non-zero weight on some loaded date. In a file run without textbook Brinson-Fachler, an explicit cash-ticker column in the benchmark weights is an ordinary constituent and needs a price file too (a Backtest-Engine run treats the cash ticker as a zero return instead). A weighted constituent with no return on a date on which the benchmark has one counts as 0 that day; one warning gives the count and the first ticker and date;

  • a column for each constituent in the factor files. The factor files are read for the benchmark’s tickers too. A constituent without a column in a file has no exposure to that factor, so its factor return lands in the active idiosyncratic residual. The factor-coverage INFO line is logged for each side (“throughout the portfolio” and “throughout the benchmark”), so low benchmark coverage shows there. A factor present on only one side counts as zero exposure on the other.

In a run without textbook Brinson-Fachler the benchmark weights are used as given: they are not topped up with implied cash. Weights that do not sum to 1 leave the remainder as implied cash that earns 0 and has no factor exposure (\(r_b = \sum_i w^B_i r_i\)), so topping up would change no number. Weights above 1 are used as given too; nothing is raised. One warning gives the number of active dates whose net benchmark weights differ from 1 by more than 1e-6, the first such date and its sum. If the benchmark is fully invested, complete or rescale the weights: weights at 98% of it give 98% of its return and of its factor contributions on each date, and the missing 2% of each is reported as active. If the benchmark does hold cash, give that cash a weight column (in a file run it then needs a price file, as said above) and the warning stops. The cross-check below also flags the gap against the reported benchmark, but only above 1 bp on a date.

Turning active_factor_model on never changes the portfolio’s own numbers (returns, contributions, totals, summary_stats), in file runs and in Backtest-Engine runs.

In a file run the benchmark weights file bounds the attribution window with the option on or off. Without textbook Brinson-Fachler, the constituents the portfolio does not hold are priced from their own files and their prices are taken on the portfolio’s price dates. A price date that only they have is not a period and adds no row to the portfolio’s returns: their return on the next portfolio date is measured from their previous price on a portfolio date, so a move made across that date is kept. A portfolio date they have no price for leaves their return empty, never 0, and their next priced date carries the move since their last price; prices are never carried forward. With textbook Brinson-Fachler the whole weighted benchmark universe is already priced together with the portfolio, as that method requires, so the active model adds nothing to the pricing.

In a Backtest-Engine run every ticker is priced from the engine’s one price table, on the engine’s dates. benchmark_weights bound the attribution window only when Brinson-Fachler runs, which needs them on every date. For the active model alone they do not: the dates they do not cover are left out of the active results only (see the active window below), and their dates outside the run are ignored. See Running from Python.

The holdings benchmark return is compared with the reported benchmark return (the benchmark returns file, or the engine benchmark), and a warning is logged when they differ by more than 1 bp on any date. The check runs once: textbook Brinson-Fachler already runs it on the same weights.

The active window can be shorter than the portfolio’s. Dates with a portfolio return but no benchmark return or benchmark factor data (for example gaps in the benchmark weights) are excluded from the active result; one warning counts them. With linking_method = none the portfolio’s tables also include the first price date, which has no portfolio return; the active tables never do. A non-finite return or contribution, or a return of -100% or below, raises PerformanceAttributionError naming the date.

The results are in result.factor_model.active, an ActiveFactorResult (see Getting results as data):

  • returns: date, portfolio_returns, benchmark_returns (holdings) and active_returns;

  • contributions: the daily active effect per factor (sorted), then the components present, then the active residual f_idio_returns;

  • cumulative_contributions: the same columns, linked;

  • cumulative_totals: portfolio_returns, benchmark_returns, active_returns, factor_returns, carry_returns / dividends_returns when present, and idiosyncratic_returns;

  • linking.

The dashboard does not show the active results yet.

Timing is not modelled here#

The factor model does not split out a beta- or market-timing effect. That split needs the factor return series and the portfolio’s factor exposures over time, and the factor files (exposure x return per asset, already multiplied) do not provide them separately. Timing in and out of the market is measured by textbook Brinson-Fachler with the cash segment: moving weight between cash and the market shows up in the cash segment’s allocation effect (see Brinson-Fachler).

Risk-free rate#

risk_free_rate (annual, decimal; default 0; set from Python) is used only by the Sharpe ratio in summary_stats, converted to a per-period rate \((1 + r_f)^{1/252} - 1\). Attribution effects are total returns and do not use it.

Implementation#

The PyArrow-based implementation lives in FactorModelArrowAttribution, implementing FactorModelArrowAttributionInterface. See Factor Model for the full API reference. decompose() computes the daily contributions and portfolio returns without cumulative linking; run() is decompose() followed by time_series_calculation(). The active decomposition lives in kaxanuk.attribution_analysis.modules.active_factor.

Enable this methodology by setting factor_model_method = yes in attribution_analysis_parameters.xlsx (see Configuration Reference). When the entry script runs with launch_dashboard=True, an interactive Dash dashboard is served on dashboard_port with the results of every enabled method (see Dashboard); with launch_dashboard=False static matplotlib plots are drawn instead.