Global Settings & Variables
Relevant source files
The following files were used as context for generating this wiki page:
Global settings and variables in AlphaPy constitute the foundational configuration and state management system for the machine learning pipeline. This module defines the constants, enumerations, and configuration schemas used to control data partitioning, model selection, feature engineering, and market-specific analysis flows. Sources: alphapy/globals.py, alphapy/model.py:127-268
The system is designed around a centralized Model object that encapsulates specifications (specs) derived from YAML configuration files. These specs dictate the behavior of the training and prediction pipelines, including technical indicators, sampling methods, and evaluation metrics. Sources: alphapy/model.py:72-121, alphapy/market_flow.py:76-156
Core Enumerations and Constants
AlphaPy utilizes several Enum classes to standardize options across the pipeline, ensuring type safety and consistency when interpreting configuration files.
Pipeline Enums
| Enum Class | Purpose | Values |
|---|---|---|
ModelType | Defines the machine learning task. | classification, clustering, multiclass, oneclass, regression |
Partition | References specific data subsets. | predict, test, train |
Objective | Sets the goal for scoring functions. | maximize, minimize |
Encoders | Specifies categorical encoding types. | onehot, ordinal, target, woe, hashing, etc. |
Scalers | Defines feature scaling methods. | minmax, standard |
SamplingMethod | Methods for handling imbalanced data. | under_random, over_smote, ensemble_bc, etc. |
Sources: alphapy/globals.py:87-205
String and Numerical Constants
Standardized delimiters and separators are used throughout the project for path joining and log formatting.
- Delimiters:
BSEP(' '),CSEP(':'),PSEP('.'),SSEP('/'),USEP('_'). - Numerical Constants: Quartiles
Q1(0.25),Q2(0.50),Q3(0.75). - Time Offsets:
PD_INTRADAY_OFFSETSincludes 'H', 'T', 'min', 'S', etc., for Pandas compatibility.
Sources: alphapy/globals.py:38-76
Configuration Management
AlphaPy relies on structured YAML files (e.g., model.yml, market.yml, algos.yml) to populate global settings. These files are parsed into dictionaries and stored within the Model class attributes.
Configuration Loading Flow
The following diagram illustrates how configuration is ingested from local files into the active Model instance.
The get_model_config function specifically validates configuration keys against the predefined Enums like SamplingMethod and Scalers. Sources: alphapy/model.py:149-215, alphapy/market_flow.py:76-105
Model Specifications (Specs)
The specs dictionary is the primary data structure for global settings during runtime. It contains parameters for every stage of the pipeline.
| Section | Parameter | Description |
|---|---|---|
| Project | directory | Root path for input/output data. |
| Data | split | Ratio for train/test split (default 0.4). |
| Features | scaler_type | The Scalers enum value to apply. |
| Model | algorithms | List of algorithm abbreviations (e.g., ['RF', 'XGB']). |
| Pipeline | n_jobs | Number of parallel jobs for estimators. |
Sources: alphapy/model.py:157-268, alphapy/examples/Trading Model/config/model.yml:1-110
Estimator and Scorer Mapping
Global variables also include mappings that link algorithm abbreviations to their respective classes and scoring functions to their optimization objectives.
Estimator Mapping
The estimator_map connects short codes to Scikit-Learn, Keras, or XGBoost estimators.
- AB: AdaBoostClassifier
- RF: RandomForestClassifier
- KERASC: KerasClassifier
- XGB: XGBClassifier (if package is found)
Sources: alphapy/estimators.py:108-148
Scoring Objectives
The scorers dictionary defines whether a metric should be maximized or minimized during model selection.
scorers = {'accuracy' : (ModelType.classification, Objective.maximize),
'neg_log_loss' : (ModelType.classification, Objective.minimize),
'r2' : (ModelType.regression, Objective.maximize)}
Sources: alphapy/estimators.py:46-65
Utility Settings
Global utility functions provide shared logic for date manipulation and file tracking, which are essential for maintaining the state of model versions.
- get_datestamp: Returns the current date in
YYYYMMDDformat for file naming. Sources: alphapy/utilities.py:44-55 - most_recent_file: Scans a directory for the latest file matching a spec, used to load the most recent model predictor or feature map. Sources: alphapy/utilities.py:61-80
Summary
Global Settings & Variables in AlphaPy provide a robust framework for defining the operational environment of the machine learning pipeline. By centralizing constants in globals.py and configuration logic in model.py, the system ensures that every component—from data sampling to ensemble blending—operates under a unified set of parameters and definitions. Sources: alphapy/globals.py, alphapy/model.py:72-121