Assets API Reference¶
The assets package manages asset selection, classification, and universe definitions.
Overview¶
The assets package contains:
- Selection - Asset filtering and selection logic
- Classification - Asset type classification
- Universes - Universe management and validation
Assets Package¶
portfolio_management.assets
¶
Handles the definition, selection, and classification of financial assets.
This package forms the core of the asset management layer, responsible for transforming raw instrument data into well-defined, filtered, and classified investment universes. It acts as the bridge between raw data sources and the portfolio construction engine.
Pipeline Position
Data Layer -> Assets Layer -> Portfolio Layer
- Input: Raw asset metadata (e.g., from
tradeable_matches.csv). - Process:
selection: Filters assets based on data quality, history, and market criteria.classification: Assigns assets to categories like asset class, geography, and sub-class.universes: Combines selection and classification rules defined in YAML to build complete, investable universes.
- Output: A structured collection of assets, their classifications, and associated returns, ready for analysis and optimization.
Key Classes
AssetSelector: Filters assets using a multi-stage pipeline.AssetClassifier: Classifies assets using a rule-based engine.UniverseManager: The main entry point for loading and managing universes defined in a configuration file.FilterCriteria: Defines the rules for asset selection.UniverseDefinition: Defines the complete configuration for a universe.
Usage Example
This example demonstrates the end-to-end workflow of loading a universe.¶
In a real application, the config file and data would already exist.¶
from pathlib import Path import pandas as pd from portfolio_management.assets import UniverseManager
Assume the following setup:¶
1. A universe configuration file 'config/universes.yaml' with a¶
'global_equity' universe defined.¶
2. A DataFrame 'matches_df' containing metadata for all tradeable assets.¶
3. A directory 'prices/' containing historical price data for the assets.¶
Conceptual initialization (replace with actual paths and data):¶
>>> manager = UniverseManager(¶
... config_path=Path("config/universes.yaml"),¶
... matches_df=matches_df,¶
... prices_dir=Path("prices/")¶
... )¶
Load the 'global_equity' universe:¶
>>> universe_data = manager.load_universe("global_equity")¶
The resulting 'universe_data' is a dictionary containing:¶
- universe_data['assets']: DataFrame of selected asset metadata.¶
- universe_data['classifications']: DataFrame of asset classifications.¶
- universe_data['returns']: DataFrame of historical asset returns.¶
- universe_data['metadata']: Series containing universe definition.¶
>>> if universe_data:¶
... print(f"Loaded {len(universe_data['assets'])} assets for 'global_equity'.")¶
... print("Asset Classifications:")¶
... print(universe_data['classifications'][['symbol', 'asset_class']].head())¶
AssetClass
¶
Bases: str, Enum
Broad asset classes.
Source code in src/portfolio_management/assets/classification/classification.py
AssetClassification
dataclass
¶
Represents the classification of a single asset.
This data structure holds the complete classification profile for an asset
after it has been processed by the AssetClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
str
|
The unique ticker symbol for the asset. |
isin |
str
|
The International Securities Identification Number. |
name |
str
|
The human-readable name of the asset. |
asset_class |
str
|
The broad asset class (e.g., 'equity', 'fixed_income'). |
sub_class |
str
|
The more granular sub-class (e.g., 'large_cap', 'government'). |
geography |
Geography
|
The geographical region of the asset. |
sector |
str | None
|
The industry sector (optional, often populated by external data). |
confidence |
float
|
A score from 0.0 to 1.0 indicating the classifier's confidence in the result. 1.0 indicates a manual override. |
Source code in src/portfolio_management/assets/classification/classification.py
AssetClassifier
¶
Applies a rule-based engine to classify assets.
This classifier determines an asset's class, sub-class, and geography by applying a series of rules based on keywords found in the asset's metadata (e.g., name, category). It is designed to provide a baseline classification that can be augmented with manual overrides for improved accuracy.
The classification logic is primarily handled by the _classify_dataframe
method, which uses vectorized pandas operations for efficiency.
Attributes:
| Name | Type | Description |
|---|---|---|
overrides |
ClassificationOverrides
|
A collection of manual overrides that will take precedence over the rule-based engine. |
Methods:
| Name | Description |
|---|---|
- `classify_universe` |
Classifies a list of assets and returns a DataFrame. |
- `classify_asset` |
Classifies a single asset. |
Example
from portfolio_management.assets.selection import SelectedAsset
assets = [ ... SelectedAsset( ... symbol="AAPL.US", isin="US0378331005", name="Apple Inc. Equity", ... market="US", region="North America", currency="USD", category="stock", ... price_start="2010-01-01", price_end="2023-01-01", price_rows=3276, ... data_status="ok", data_flags="", stooq_path="", resolved_currency="USD", ... currency_status="matched" ... ) ... ] classifier = AssetClassifier() results = classifier.classify_universe(assets) result_series = results.iloc[0] result_series['symbol'] 'AAPL.US' result_series['asset_class'] 'equity' result_series['geography'] 'north_america'
Source code in src/portfolio_management/assets/classification/classification.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
classify_asset(asset)
¶
Classifies a single asset using keyword-based rules.
This method first checks for a manual override for the asset. If none
is found, it applies rules based on the asset's name and category to
determine its classification. This method is suitable for classifying
individual assets but is less efficient than classify_universe for
large batches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset
|
SelectedAsset
|
The |
required |
Returns:
| Type | Description |
|---|---|
AssetClassification
|
An |
Source code in src/portfolio_management/assets/classification/classification.py
classify_universe(assets)
¶
Classifies a list of assets and returns a DataFrame of results.
This is the primary method for bulk classification. It converts the list of assets into a pandas DataFrame and uses efficient, vectorized operations to apply the classification rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assets
|
list[SelectedAsset]
|
A list of |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame where each row represents an asset and columns |
DataFrame
|
contain the classification results (e.g., 'asset_class', 'geography'). |
Raises:
| Type | Description |
|---|---|
DataValidationError
|
If the input is None or not a list. |
ClassificationError
|
If assets cannot be serialized for processing. |
Source code in src/portfolio_management/assets/classification/classification.py
ClassificationOverrides
dataclass
¶
Manages manual classification overrides loaded from a CSV file.
This class provides a mechanism to manually set the classification for specific assets, bypassing the rule-based engine. Overrides are indexed by ISIN or symbol, with ISIN taking precedence.
Attributes:
| Name | Type | Description |
|---|---|---|
overrides |
dict[str, dict[str, str]]
|
A dictionary where keys are asset identifiers (ISIN or symbol) and values are dictionaries of classification fields to override. |
Configuration (CSV Format):
The CSV file should contain columns that match the AssetClassification
attributes. The 'symbol' or 'isin' column is required for matching.
Example `overrides.csv`:
```csv
symbol,isin,asset_class,sub_class,geography
AMZN.US,US0231351067,equity,large_cap,north_america
BRK.A,US0846701086,equity,value,north_america
```
Example
from pathlib import Path import io
csv_lines = [ ... "symbol,isin,asset_class,sub_class,geography", ... "AMZN.US,US0231351067,equity,large_cap,north_america", ... "BRK.A,US0846701086,equity,value,north_america" ... ] csv_content = "\n".join(csv_lines)
In a real scenario, you would provide a file path.¶
For this example, we simulate the file with an in-memory buffer.¶
with open("overrides.csv", "w") as f: ... _ = f.write(csv_content)
overrides = ClassificationOverrides.from_csv("overrides.csv") amzn_override = overrides.overrides.get("US0231351067") print(amzn_override['asset_class']) equity import os os.remove("overrides.csv")
Source code in src/portfolio_management/assets/classification/classification.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
from_csv(path)
classmethod
¶
Load classification overrides from a CSV file.
The CSV file must contain a 'symbol' or 'isin' column to identify the
asset. Other columns should correspond to AssetClassification fields
(e.g., 'asset_class', 'sub_class', 'geography').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file path to the CSV containing the overrides. |
required |
Returns:
| Type | Description |
|---|---|
ClassificationOverrides
|
A |
ClassificationOverrides
|
the CSV file. Returns an empty instance if the path does not exist. |
Source code in src/portfolio_management/assets/classification/classification.py
Geography
¶
Bases: str, Enum
Geographical classifications for assets.
Source code in src/portfolio_management/assets/classification/classification.py
SubClass
¶
Bases: str, Enum
Granular asset sub-classes.
Source code in src/portfolio_management/assets/classification/classification.py
AssetSelector
¶
Filters a universe of assets based on a set of criteria.
This class acts as a preselection engine, applying a multi-stage filtering
pipeline to a DataFrame of asset metadata. It is stateless and its primary
entry point is the select_assets method.
The filtering pipeline is executed in a specific order to ensure that the most efficient filters are applied first.
Filtering Stages
- Data Quality: Removes assets with unacceptable
data_statusorzero_volume_severity. - History: Enforces minimum data history (
min_history_days) and row count (min_price_rows). - Characteristics: Filters by market, region, currency, and category.
- Allow/Block Lists: Applies manual overrides to include or exclude specific assets.
Example
import pandas as pd from portfolio_management.assets.selection import AssetSelector, FilterCriteria
Assume 'matches_df' is a DataFrame with asset metadata.¶
matches_df = pd.DataFrame({ ... 'symbol': ['AAPL.US', 'BAD.UK'], 'isin': ['US0378331005', 'GB00B1XFGM60'], ... 'name': ['Apple Inc', 'Bad Data PLC'], 'market': ['US', 'UK'], ... 'region': ['North America', 'Europe'], 'currency': ['USD', 'GBP'], ... 'category': ['Stock', 'Stock'], 'price_start': ['2010-01-01', '2023-01-01'], ... 'price_end': ['2023-12-31', '2023-12-31'], 'price_rows': [3522, 252], ... 'data_status': ['ok', 'error'], 'data_flags': ['' , ''], ... 'stooq_path': ['' , ''], 'resolved_currency': ['USD', 'GBP'], ... 'currency_status': ['matched', 'matched'] ... })
criteria = FilterCriteria(data_status=['ok'], markets=['US']) selector = AssetSelector() selected_assets = selector.select_assets(matches_df, criteria) print(selected_assets[0].symbol) AAPL.US
Source code in src/portfolio_management/assets/selection/selection.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
select_assets(matches_df, criteria)
¶
Runs the full asset selection pipeline on a DataFrame of assets.
This is the main entry point for the AssetSelector. It takes a DataFrame
of asset metadata and a FilterCriteria object, then applies the
entire filtering pipeline in sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matches_df
|
DataFrame
|
A DataFrame containing the raw metadata for all assets
to be considered for selection. Must include columns specified
in |
required |
criteria
|
FilterCriteria
|
A |
required |
Returns:
| Type | Description |
|---|---|
list[SelectedAsset]
|
A list of |
list[SelectedAsset]
|
passed all stages of the filtering pipeline. Returns an empty list |
list[SelectedAsset]
|
if no assets pass the filters. |
Raises:
| Type | Description |
|---|---|
DataValidationError
|
If |
AssetSelectionError
|
If an allowlist is provided but no assets are selected, indicating a potential configuration issue. |
Source code in src/portfolio_management/assets/selection/selection.py
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
FilterCriteria
dataclass
¶
Defines the parameters for filtering assets.
This dataclass holds all configurable parameters used by the AssetSelector
to filter the tradeable universe. It allows for detailed control over data
quality, history requirements, market characteristics, and inclusion/exclusion lists.
Attributes:
| Name | Type | Description |
|---|---|---|
data_status |
list[str]
|
List of acceptable data quality status values (e.g., ["ok"]). |
min_history_days |
int
|
The minimum number of calendar days of price history required. |
max_gap_days |
int
|
Maximum allowed gap in days between consecutive price points. |
min_price_rows |
int
|
The minimum number of data rows (e.g., trading days) required. |
zero_volume_severity |
list[str] | None
|
Filters assets based on the severity of zero-volume trading days (e.g., ["low", "medium"]). If None, this filter is disabled. |
markets |
list[str] | None
|
A list of market codes to include (e.g., ["US", "UK"]). If None, assets from all markets are considered. |
regions |
list[str] | None
|
A list of geographic regions to include (e.g., ["North America"]). If None, assets from all regions are considered. |
currencies |
list[str] | None
|
A list of currency codes to include (e.g., ["USD", "EUR"]). If None, assets in all currencies are considered. |
categories |
list[str] | None
|
A list of asset categories to include (e.g., ["Stock", "ETF"]). If None, assets of all categories are considered. |
allowlist |
set[str] | None
|
A set of symbols or ISINs to include, bypassing other filters. These assets will be included if they exist in the input data. |
blocklist |
set[str] | None
|
A set of symbols or ISINs to explicitly exclude from the output. Blocklisted assets are removed regardless of whether they pass other filters. |
regime_config |
RegimeConfig | None
|
Configuration for macroeconomic regime-based filtering. If None, no regime-based gating is applied. |
Example
Create a strict filter for US large-cap stocks¶
criteria = FilterCriteria( ... min_history_days=365 * 5, ... data_status=['ok'], ... markets=['US'], ... categories=['Stock'], ... blocklist={'DO-NOT-TRADE.US'} ... ) criteria.validate() # No error raised
Source code in src/portfolio_management/assets/selection/selection.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
validate()
¶
Validate filter criteria parameters.
Raises:
| Type | Description |
|---|---|
ValueError
|
If any parameter is invalid (e.g., negative values, empty required lists). |
Example
This will raise a ValueError because min_history_days is negative.¶
criteria = FilterCriteria(min_history_days=-1)¶
criteria.validate()¶
Source code in src/portfolio_management/assets/selection/selection.py
default()
classmethod
¶
Create default filter criteria suitable for most portfolios.
Returns:
| Type | Description |
|---|---|
FilterCriteria
|
FilterCriteria with conservative defaults: |
FilterCriteria
|
|
FilterCriteria
|
|
FilterCriteria
|
|
FilterCriteria
|
|
FilterCriteria
|
|
FilterCriteria
|
|
Example
criteria = FilterCriteria.default() criteria.min_history_days 252
Source code in src/portfolio_management/assets/selection/selection.py
SelectedAsset
dataclass
¶
Represents a selected asset with metadata from the match report.
This dataclass captures all relevant information about an asset that has passed filtering criteria. It combines instrument metadata (symbol, ISIN, name) with market information (market, region, currency, category) and data quality metrics (date ranges, row counts, status flags).
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
str
|
Stooq ticker symbol (e.g., "1pas.uk", "aapl.us"). |
isin |
str
|
International Securities Identification Number. |
name |
str
|
Human-readable asset name. |
market |
str
|
Market code (e.g., "UK", "US", "DE"). |
region |
str
|
Geographic region (e.g., "Europe", "North America"). |
currency |
str
|
Trading currency code (e.g., "GBP", "USD", "EUR"). |
category |
str
|
Asset category (e.g., "ETF", "Stock", "Bond"). |
price_start |
str
|
First available price date as ISO string (YYYY-MM-DD). |
price_end |
str
|
Last available price date as ISO string (YYYY-MM-DD). |
price_rows |
int
|
Total number of price observations available. |
data_status |
str
|
Overall data quality status ("ok", "warning", "error"). |
data_flags |
str
|
Pipe-separated flags with additional quality information. Example: "zero_volume_severity=low|other_flag=value" |
stooq_path |
str
|
Relative path to price file in Stooq data directory. |
resolved_currency |
str
|
Currency after harmonization/resolution logic. |
currency_status |
str
|
Status of currency resolution ("matched", "resolved", etc.). |
Example
asset = SelectedAsset( ... symbol="1pas.uk", ... isin="GB00BD3RYZ16", ... name="iShares Core MSCI Asia ex Japan UCITS ETF", ... market="UK", ... region="Europe", ... currency="GBP", ... category="ETF", ... price_start="2020-01-02", ... price_end="2025-10-15", ... price_rows=1500, ... data_status="ok", ... data_flags="zero_volume_severity=low", ... stooq_path="d_uk_txt/data/daily/uk/1pas.txt", ... resolved_currency="GBP", ... currency_status="matched" ... )
Source code in src/portfolio_management/assets/selection/selection.py
UniverseConfigLoader
¶
Loads and parses universe definitions from a YAML configuration file.
This is a static utility class that provides a single method, load_config,
to read a YAML file and convert it into a dictionary of UniverseDefinition
objects.
Configuration (YAML Format):
The YAML file must have a top-level key universes, which contains a
mapping of universe names to their definitions.
Example `universes.yaml`:
```yaml
universes:
us_equity_large_cap:
description: "US Large Cap Equities"
filter_criteria:
min_history_days: 1825 # 5 years
markets: ["US"]
categories: ["Stock"]
classification_requirements:
asset_class: ["equity"]
sub_class: ["large_cap"]
return_config:
window: 252
min_periods: 200
```
Source code in src/portfolio_management/assets/universes/loader.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
load_config(path)
staticmethod
¶
Loads and parses the universe configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file path to the universe YAML configuration. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, UniverseDefinition]
|
A dictionary mapping universe names to |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If the file is not found, cannot be parsed, is badly structured, or contains invalid parameter values. |
Source code in src/portfolio_management/assets/universes/loader.py
UniverseDefinition
dataclass
¶
Represents the complete configuration for a single investment universe.
This dataclass holds all the parameters needed to construct a universe,
from initial filtering to final return calculation. It is typically
instantiated by UniverseConfigLoader from a YAML file.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
A human-readable description of the universe. |
filter_criteria |
FilterCriteria
|
An instance of |
classification_requirements |
dict[str, list[str]]
|
A dictionary specifying required classification
values. Assets not matching these values will be filtered out after
classification. Example: |
return_config |
ReturnConfig
|
A |
constraints |
dict[str, int | float]
|
A dictionary of hard constraints for the universe, such as
|
technical_indicators |
IndicatorConfig
|
An |
Source code in src/portfolio_management/assets/universes/universe.py
UniverseManager
¶
Orchestrates the loading and construction of investment universes.
Source code in src/portfolio_management/assets/universes/manager.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
list_universes()
¶
get_definition(name)
¶
Get the definition for a named universe.
Source code in src/portfolio_management/assets/universes/manager.py
load_universe(name, use_cache=True, strict=True)
¶
Loads and constructs a universe by its configured name.
Source code in src/portfolio_management/assets/universes/manager.py
options: show_root_heading: true show_source: false members_order: source group_by_category: true show_category_heading: true