Data Formats#

Market data (Input/Data/)#

One file per ticker (e.g. AAPL.csv, MSFT.parquet). Each file needs a date column and a price column; their names are configurable (user_column_date, user_column_price). Returns are computed internally from the price series. Extra columns are ignored. Every portfolio ticker needs a price file; with the textbook Brinson-Fachler formula, so does every benchmark constituent with a non-zero weight on some date (constituents weighted 0 throughout need none).

m_date,m_close_split_adjusted
2020-01-02,73.87
2020-01-03,73.07
2020-01-06,73.75

Format

File naming

Notes

CSV

{TICKER}.csv

Headers required, dates as YYYY-MM-DD

Parquet

{TICKER}.parquet

Efficient for large datasets. The date column may be text (YYYY-MM-DD) or a native date / timestamp type (a time-zone-aware timestamp keeps its local calendar date). The price column may be text or a native integer, float or decimal type. Null, NaN or infinite prices are rejected with an error naming the column and the ticker.

Portfolio & benchmark weights (Input/Portfolios/, Input/Benchmark_Portfolios/)#

Weight files give the weights held on every trading day: one column (or row) per day, not just the rebalancing dates. A weight dated t is held from the close of t-1 to the close of t (start-of-day weights) and multiplies the return of t; see Conventions and limitations. If you only have rebalancing dates, carry each allocation forward to the following trading days before saving the file. The loader checks the density of the series: when it spans at least a year, the first and the last year must each hold between 240 and 260 dates, otherwise it rejects the file. The loader auto-detects orientation.

Horizontal (first column must be Ticker, then one column per trading day):

Ticker | 2020-01-02 | 2020-01-03 | 2020-01-06 | ...
AAPL   | 0.40       | 0.40       | 0.40       | ...
MSFT   | 0.35       | 0.35       | 0.35       | ...
GOOGL  | 0.25       | 0.25       | 0.25       | ...

Vertical (first column must be a date header, then one row per trading day). The first header may be date, m_date or date_column, in any capitalization:

date       | AAPL | MSFT | GOOGL
2020-01-02 | 0.40 | 0.35 | 0.25
2020-01-03 | 0.40 | 0.35 | 0.25
2020-01-06 | 0.40 | 0.35 | 0.25
...

Rules: weights are decimals, no null values, supported formats .csv / .xlsx.

Benchmark returns (Input/Benchmark_Portfolios/)#

The daily benchmark returns file uses the same weight-file format (a Ticker row with one column per date), read through the portfolio loader, so it follows the same daily-series rules. It is used for date-range alignment and as a cross-check of the holdings-based benchmark return.

Factor returns (Input/Factor_Models/)#

One file per factor (e.g. f_momentum.csv). First column is the date, followed by one column per asset. Each cell is the asset’s contribution from that factor on that date: its exposure to the factor times the factor’s return, in decimals. It is not the factor return itself. The portfolio’s factor contribution is the weighted sum of these cells. Only assets present in the portfolio (and, with active_factor_model, in the benchmark weights) are read.

Files named f_total_factor_returns.csv, f_total_excess_returns.csv or f_idyo_returns.csv hold vendor totals, not factors. They are not loaded (one INFO line names them), so they never change the date window or the results; the totals come from the portfolio’s own returns.

Two names are reserved for return components, not factors: f_carry.csv and f_dividends.csv. Same format; each cell is the asset’s simple carry or dividend return that day. They are never converted from log returns, even with factor_return_type = log, and are reported separately from the factors and taken out of the idiosyncratic residual (see Factor Model). Like any factor file, a component file that covers fewer dates narrows the common date window. They must already be part of the asset returns: with f_dividends, use total-return (dividend-adjusted) prices, or the residual is understated by the dividends.

These reserved names (the three totals and the two components) are matched whatever the case of the file name, on every operating system: F_Dividends.csv is the dividends component, reported as f_dividends, and F_Idyo_Returns.csv is not loaded. Two files for the same component (for example f_carry.csv and F_Carry.csv in a case-sensitive folder) raise DataValidationError naming both. Any other factor keeps the case of its file name.

Only regular files ending in .csv are read. Anything else in the folder (README.md, .gitkeep, sub-folders) and hidden or temporary files (names starting with . or ~$) are skipped. The factor name is the file name without the final .csv; dots inside the name are kept (f_value.v2.csv is the factor f_value.v2), so make sure two files do not end up with the same name. A file that cannot be read stops the run with an error naming it.

date,AAPL,MSFT,GOOGL
2020-01-02,0.010,-0.004,0.006
2020-01-03,0.008,0.002,-0.003

Every factor column read must correspond to a ticker present in the portfolio or, with active_factor_model, in the benchmark weights; other columns are not read.

Segment map (optional)#

A CSV in the input directory named by segment_map_file_name (without extension), with a header row ticker,segment. Every ticker in the portfolio and benchmark weights files must appear; the cash ticker may be omitted. Keep long and short positions that offset each other in separate segments: a segment whose net weight is ~0 on a date while its P&L is not stops the run. Example:

ticker,segment
AAPL,Information Technology
XOM,Energy

Cash#

With the textbook Brinson-Fachler formula, net weights that sum below 1 on a date are topped up with cash_ticker (default CASH). A file can also list that ticker explicitly. It needs no price file and earns 0; a price file named after it is ignored, with a warning. With the legacy formula or the factor model alone, cash_ticker is an ordinary ticker and needs a price file like any other.

With active_factor_model and without the textbook formula, the benchmark weights are used as given: a cash_ticker column in them is an ordinary constituent that needs a price file, and weights that do not sum to 1 leave the remainder as implied cash that earns 0 and has no factor exposure. 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. The holdings benchmark return is then compared with the benchmark returns file, and a gap of more than 1 bp on any date logs a warning. A Backtest-Engine run instead treats the cash ticker as a zero return.

Pre-Execution Checklist#

Before running, verify:

  • Portfolio and benchmark weight files are in their directories with the correct format (no nulls) and hold one entry per trading day, not just rebalancing dates.

  • A market data file exists in Input/Data/ for every ticker in the portfolio and, with the textbook Brinson-Fachler formula or active_factor_model, for every benchmark constituent with a non-zero weight.

  • Factor files in Input/Factor_Models/ hold columns for the portfolio’s tickers (and, with active_factor_model, the benchmark’s); other columns are not read.

  • With f_dividends.csv in the factor folder, the price files are total-return (dividend-adjusted) prices.

  • All input date ranges overlap (otherwise the common-range alignment yields no data).

  • user_column_date / user_column_price match the actual headers in your market-data files.

  • Config/attribution_analysis_parameters.xlsx parameters_format_version matches the package (run kaxanuk.attribution_analysis update excel if it asks you to).