Aliases & Naming Conventions
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Aliases and naming conventions in AlphaPy provide a standardized framework for identifying data structures, technical indicators, and system components. By mapping complex expressions to concise keys, the system enables users to define features and trading variables in a readable format. This mechanism is central to the MarketFlow and SportFlow pipelines, allowing for consistent data addressing across different time fractals and schemas.
The project utilizes a combination of global delimiters, alias mapping classes, and namespace generators to maintain architectural integrity. These conventions ensure that identifiers remain valid for Python's internal parsing and compatible with external data sources such as Yahoo Finance or Quandl.
Sources: alphapy/alias.py, alphapy/globals.py, alphapy/space.py
Global Delimiters and Identifiers
AlphaPy defines a set of standard delimiters to manage string operations and file path construction. These constants are used throughout the library to ensure consistency in how filenames, groups, and namespaces are concatenated.
Standard Delimiters
| Constant | Character | Purpose |
|---|---|---|
BSEP | ' ' | Blank separator for titles and labels |
CSEP | ':' | Colon separator for specific mappings |
PSEP | '.' | Period separator for technical indicator prefixes |
SSEP | '/' | System separator for directory paths |
USEP | '_' | Underscore separator for internal identifiers |
Sources: alphapy/globals.py:43-51, alphapy/utilities.py:32
Alphanumeric Validation
All identifiers (aliases, group names, etc.) must adhere to strict alphanumeric rules. A valid name must start with a letter or underscore and contain only alphanumeric characters. This is enforced using the regex pattern r"^[^\d\W]\w*\Z".
Sources: alphapy/utilities.py:192-214, alphapy/alias.py:68-75
Alias System
The Alias class allows users to map short keys to longer technical indicator expressions. Aliases are stored in a class-level dictionary Alias.aliases to ensure uniqueness across the application lifecycle.
Alias Architecture
The system prevents duplicate expressions by checking if a value already exists under a different key. It also validates both the key (name) and the expression (expr) against standard naming conventions before registration.
The diagram shows the logic flow for registering a new alias, including validation steps for expressions and keys.
Sources: alphapy/alias.py:41-86
Common Market Aliases
Standard technical indicator aliases are typically configured in market.yml.
| Alias Key | Internal Expression | Description |
|---|---|---|
atr | ma_truerange | Moving Average of True Range |
hc | higher_close | Boolean check for higher close price |
net | net_close | Net change in closing price |
vma | ma_volume | Moving Average of Volume |
Sources: alphapy/examples/Trading Model/config/market.yml:104-135
Namespacing and Spaces
The Space class defines the context for data frames, grouping them by subject, schema, and fractal. This structured naming convention allows AlphaPy to manage data across different instruments and timeframes without collision.
Space Components
A Space consists of three primary attributes joined by an underscore (USEP):
- Subject: The broad category (e.g.,
stock,game). - Schema: The data source or format (e.g.,
prices,yahoo,scores). - Fractal: The time resolution (e.g.,
1dfor daily,5mfor five minutes).
Sources: alphapy/space.py:46-77
Frame Naming Logic
Frames are named by combining a group name with its associated Space. This ensures that a "Tech" group for daily stocks is distinct from a "Tech" group for intraday stocks.
This diagram illustrates the derivation of unique frame identifiers used for storage and memory retrieval.
Sources: alphapy/frame.py:44-67, alphapy/market_flow.py:126-128
Data Offsets and Constants
AlphaPy utilizes standard naming for time series offsets, largely following pandas offset aliases.
Intraday Offsets
The constant PD_INTRADAY_OFFSETS contains recognized identifiers for high-frequency data:
H: HourlyTormin: MinutesS: SecondsLorms: MillisecondsUorus: MicrosecondsN: Nanoseconds
Sources: alphapy/globals.py:73, alphapy/market_flow.py:228
Quantile Constants
Numerical constants for quartiles are standardized as:
Q1: 0.25Q2: 0.50Q3: 0.75
Sources: alphapy/globals.py:57-59
Conclusion
Naming conventions in AlphaPy are not merely stylistic but are functional requirements for the pipeline's automation. The strict enforcement of alphanumeric identifiers, combined with the flexible Alias system and the rigid Space hierarchy, ensures that data remains traceable from configuration files through feature engineering to model output. This consistency allows for complex blended models and portfolios to be generated across disparate market and sport data sources.
Sources: alphapy/market_flow.py:140-150, alphapy/alias.py:38-40