Configuration#
The Excel configurator that reads and validates the run configuration, the abstract contracts it implements, and the configuration entity it produces. See Configuration Reference for the Excel parameters workbook this powers.
Loads and returns a Configuration entity from an Excel file
Functions#
- init:
Loads and returns Configuration
- class ExcelConfigurator(file_path: str, logger_format: str = '[%(levelname)s] %(message)s')[source]#
Bases:
ConfiguratorInterfaceBuild a Configuration and dashboard port from an Excel parameters file.
On construction, the workbook at file_path is loaded and its
Generalsheet is parsed according to SHEET_KEY_VALUES. Theparameters_format_versioncell is checked against the package’s __parameters_format_version__, method-flag cells (e.g.brinson_fachler_method) are coerced to booleans, and thedashboard_portcell is validated as an integer in range. Any ConfigurationError or ConfigurationHandlerError raised while parsing is logged as critical and terminates the process via sys.exit, rather than propagating to the caller.- Parameters:
file_path (str) – Path to the Excel configuration file.
logger_format (str) – Format string injected into the temporary bootstrap logger used while parsing file_path.
- Variables:
METHOD_FLAG_VALUES (Mapping[str, bool]) – Accepted case-insensitive text values (
'yes'/'no') for method-flag fields, mapped to their boolean equivalent.SHEET_KEY_VALUES (Mapping[str, tuple[str, ...]]) – Schema of required sheets and the key values to extract from each, passed to _extract_workbook_key_values_by_schema.
- METHOD_FLAG_VALUES = mappingproxy({'yes': True, 'no': False})#
- OPTIONAL_SHEET_KEY_DEFAULTS = mappingproxy({'General': mappingproxy({'brinson_fachler_formula': 'textbook', 'segment_map_file_name': None, 'cash_ticker': 'CASH', 'factor_return_type': 'simple', 'linking_method': 'carino', 'output_directory': 'Output'})})#
- SHEET_KEY_VALUES = mappingproxy({'General': ('input_directory', 'weights_portfolio_directory', 'weights_benchmark_directory', 'benchmark_returns_directory', 'investable_assets_directory', 'factor_returns_by_factor_directory', 'user_column_date', 'user_column_price', 'market_data_input_format', 'portfolio_input_format', 'start_date', 'end_date', 'portfolio_file_name', 'benchmark_file_name', 'benchmark_return_file_name', 'brinson_fachler_method', 'factor_model_method', 'dashboard_port', 'parameters_format_version')})#
- get_configuration() Configuration[source]#
Return the configuration parsed from the Excel parameters file.
- Returns:
The configuration built during __init__.
- Return type:
Interface for classes creating Configuration entities and related dependencies.
- class ConfiguratorInterface[source]#
Bases:
objectAbstract base class for classes that create Configuration entities.
Concrete implementations must provide the run Configuration and the port on which the dashboard should be served.
- Variables:
DASHBOARD_PORT_MIN (int) – Minimum allowed value for the dashboard port.
DASHBOARD_PORT_MAX (int) – Maximum allowed value for the dashboard port.
- DASHBOARD_PORT_MAX = 9999#
- DASHBOARD_PORT_MIN = 1#
- abstractmethod get_configuration() Configuration[source]#
Build and return the validated run configuration.
- Returns:
The configuration for the current attribution analysis run.
- Return type:
Dataclass encapsulating the user’s selected configuration.
Configuration instances are typically built by config handlers (e.g. kaxanuk.attribution_analysis.config_handlers.excel_configurator) from user-supplied settings, and consumed by the attribution engine to locate input files and select processing options.
- class Configuration(input_directory: str, weights_portfolio_directory: str, weights_benchmark_directory: str, benchmark_returns_directory: str, investable_assets_directory: str, factor_returns_by_factor_directory: str, portfolio_file_name: str, benchmark_file_name: str, benchmark_return_file_name: str, user_column_date: str, user_column_price: str, market_data_input_format: str, portfolio_input_format: str, start_date: DateConfig, end_date: DateConfig, brinson_fachler_method: bool, factor_model_method: bool, brinson_fachler_formula: BrinsonFachlerFormula | str = BrinsonFachlerFormula.TEXTBOOK, segment_map_file_name: str | None = None, cash_ticker: str = 'CASH', factor_return_type: FactorReturnType | str = FactorReturnType.SIMPLE, linking_method: LinkingMethod | str = LinkingMethod.CARINO, risk_free_rate: float = 0.0, active_factor_model: bool = False, output_directory: str = 'Output')[source]#
Bases:
objectImmutable, validated configuration for a single attribution analysis run.
All fields are validated in __post_init__, which raises
ConfigurationErroron the first invalid field found. start_date and end_date are additionally normalized fromdatetime.datetimetodatetime.dateif needed.- Parameters:
input_directory (str) – Base directory containing market data input files.
weights_portfolio_directory (str) – Directory containing portfolio weights files.
weights_benchmark_directory (str) – Directory containing benchmark weights files.
benchmark_returns_directory (str) – Directory containing benchmark returns files.
investable_assets_directory (str) – Directory containing investable assets market data files.
factor_returns_by_factor_directory (str) – Directory containing per-factor returns files, one file per factor.
portfolio_file_name (str) – File name (without extension) of the portfolio weights file, in weights_portfolio_directory.
benchmark_file_name (str) – File name (without extension) of the benchmark weights file, in weights_benchmark_directory.
benchmark_return_file_name (str) – File name (without extension) of the benchmark returns file, in benchmark_returns_directory.
user_column_date (str) – Name of the date column as it appears in the user’s input files.
user_column_price (str) – Name of the price column as it appears in the user’s input files.
market_data_input_format ({"csv", "parquet"}) – File format of the market data input files.
portfolio_input_format ({"csv", "excel"}) – File format of the portfolio/benchmark weights input files.
start_date (datetime.date or datetime.datetime or {"auto"}) – Start date of the analysis period, or
"auto"to derive it from the portfolio data.datetime.datetimevalues are normalized todatetime.dateafter validation.end_date (datetime.date or datetime.datetime or {"auto"}) – End date of the analysis period, or
"auto"to derive it from the portfolio data.datetime.datetimevalues are normalized todatetime.dateafter validation.brinson_fachler_method (bool) – Whether to run the Brinson-Fachler attribution method.
factor_model_method (bool) – Whether to run the factor model attribution method.
brinson_fachler_formula ({"textbook", "legacy"}, default "textbook") – Brinson-Fachler variant.
"legacy"reproduces the previous asset-level numbers (0.3.x and earlier) and is deprecated. Normalized toBrinsonFachlerFormula.segment_map_file_name (str or None, default None) – File name (without extension) of a
ticker,segmentCSV in input_directory.Nonemakes every ticker its own segment.cash_ticker (str, default "CASH") – Ticker that holds cash with the textbook formula: implied cash fills weights that sum below 1, it needs no price file and its return is 0 (a price file for it is ignored, with a warning). With the legacy formula or the factor model alone it is an ordinary ticker.
factor_return_type ({"simple", "log"}, default "simple") – Compounding convention of the per-factor return files. Normalized to
FactorReturnType.linking_method ({"carino", "grap", "none"}, default "carino") – How per-period effects are combined over time (see
LinkingMethod). Legacy Brinson-Fachler always uses “none”.risk_free_rate (float, default 0.0) – Annual risk-free rate as a decimal for the Sharpe ratio. Set from Python only (no row in the Excel parameters file), e.g.
dataclasses.replace(configuration, risk_free_rate=0.03).active_factor_model (bool, default False) – Also decompose the active return (portfolio minus the benchmark built from the benchmark weights file) by factor. Set from Python only (no row in the Excel parameters file). Needs factor_model_method; every weighted benchmark constituent needs a price file.
output_directory (str, default "Output") – Directory
main()writes the Excel report to (created when missing; relative paths are relative to the working directory).run_attributionnever writes. Optional row of the Excel parameters file.
- Raises:
ConfigurationError – If any field fails validation (see __post_init__).
- active_factor_model: bool#
- attribution_settings() AttributionSettings[source]#
The method options of this configuration as
AttributionSettings.- Returns:
Same flags, formula, factor return type, linking, cash ticker and risk-free rate.
- Return type:
- benchmark_file_name: str#
- benchmark_return_file_name: str#
- benchmark_returns_directory: str#
- brinson_fachler_formula: BrinsonFachlerFormula | str#
- brinson_fachler_method: bool#
- cash_ticker: str#
- end_date: DateConfig#
- factor_model_method: bool#
- factor_return_type: FactorReturnType | str#
- factor_returns_by_factor_directory: str#
- input_directory: str#
- investable_assets_directory: str#
- linking_method: LinkingMethod | str#
- market_data_input_format: str#
- output_directory: str#
- portfolio_file_name: str#
- portfolio_input_format: str#
- risk_free_rate: float#
- segment_map_file_name: str | None#
- start_date: DateConfig#
- user_column_date: str#
- user_column_price: str#
- weights_benchmark_directory: str#
- weights_portfolio_directory: str#
- type DateConfig = date | Literal['auto']#