Schemas
Pydantic configuration schemas
Pydantic schema models for TheStrat configuration validation.
This module provides comprehensive validation schemas that replace all manual validation logic in the Factory class. Models use Pydantic v2 features for maximum performance, type safety, and detailed error reporting.
Classes:
| Name | Description |
|---|---|
AggregationConfig |
Complete configuration for aggregation component with market-aware settings. |
AssetClassConfig |
Configuration for a specific asset class with comprehensive market metadata. |
FactoryConfig |
Root configuration for Factory.create_all method with complete pipeline setup. |
GapDetectionConfig |
Configuration for gap detection with comprehensive threshold documentation. |
IndicatorSchema |
Complete Indicator Schema |
IndicatorsConfig |
Complete configuration for indicators component with per-timeframe settings. |
SwingPointsConfig |
Configuration for swing point detection with comprehensive parameter documentation. |
TargetConfig |
Configuration for multi-target detection. |
TimeframeConfig |
Configuration and validation for timeframes with comprehensive metadata. |
TimeframeItemConfig |
Configuration for a single timeframe item with flexible timeframe targeting. |
AggregationConfig
Bases: BaseModel
Complete configuration for aggregation component with market-aware settings.
Methods:
| Name | Description |
|---|---|
apply_asset_class_defaults |
Apply AssetClassConfig defaults for timezone, hour_boundary, and session_start. |
validate_and_expand_target_timeframes |
Validate target_timeframes field and expand 'all' keyword. |
apply_asset_class_defaults
classmethod
Apply AssetClassConfig defaults for timezone, hour_boundary, and session_start.
Source code in thestrat/schemas.py
validate_and_expand_target_timeframes
classmethod
Validate target_timeframes field and expand 'all' keyword.
This Pydantic field validator is automatically called when AggregationConfig is instantiated. It validates individual timeframes and expands ['all'] to all supported timeframes.
Source code in thestrat/schemas.py
AssetClassConfig
Bases: BaseModel
Configuration for a specific asset class with comprehensive market metadata.
Methods:
| Name | Description |
|---|---|
get_config |
Get configuration for specific asset class. |
get_config
classmethod
get_config(asset_class: str) -> AssetClassConfig
FactoryConfig
Bases: BaseModel
Root configuration for Factory.create_all method with complete pipeline setup.
Methods:
| Name | Description |
|---|---|
validate_configuration_consistency |
Validate consistency between aggregation and indicators configurations. |
validate_configuration_consistency
Validate consistency between aggregation and indicators configurations.
Source code in thestrat/schemas.py
GapDetectionConfig
Bases: BaseModel
Configuration for gap detection with comprehensive threshold documentation.
IndicatorSchema
Bases: BaseModel
Complete Indicator Schema
Defines all columns that are created by TheStrat processing pipeline. All columns are required as the indicators component creates them all.
Methods:
| Name | Description |
|---|---|
get_all_input_columns |
Get list of all input columns (required + optional). |
get_column_categories |
Get columns organized by functional categories. |
get_column_descriptions |
Get descriptions for all possible DataFrame columns. |
get_field_metadata |
Get json_schema_extra metadata for a field, safely handling missing data. |
get_optional_input_columns |
Get list of optional input columns based on schema definition. |
get_output_columns |
Get list of all output columns based on schema definition. |
get_polars_dtypes |
Get Polars data types for all DataFrame columns. |
get_precision_metadata |
Get precision metadata for all fields. |
get_required_input_columns |
Get list of required input columns based on schema definition. |
get_standard_column_order |
Get the standard column ordering for aggregation output. |
validate_dataframe |
Validate input DataFrame columns and data types against IndicatorSchema input requirements. |
get_all_input_columns
classmethod
Get list of all input columns (required + optional).
Returns:
| Type | Description |
|---|---|
list[str]
|
List of all input column names |
Source code in thestrat/schemas.py
get_column_categories
classmethod
Get columns organized by functional categories.
Dynamically extracts categories from the IndicatorSchema metadata.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dictionary mapping category names to lists of column names |
Source code in thestrat/schemas.py
get_column_descriptions
classmethod
Get descriptions for all possible DataFrame columns.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping column names to their descriptions |
Source code in thestrat/schemas.py
get_field_metadata
classmethod
Get json_schema_extra metadata for a field, safely handling missing data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the field to get metadata for |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of metadata from json_schema_extra, empty dict if not found |
Source code in thestrat/schemas.py
get_optional_input_columns
classmethod
Get list of optional input columns based on schema definition.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of column names that are optional for input data |
Source code in thestrat/schemas.py
get_output_columns
classmethod
Get list of all output columns based on schema definition.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of column names marked as output in schema metadata |
Source code in thestrat/schemas.py
get_polars_dtypes
classmethod
Get Polars data types for all DataFrame columns.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary mapping column names to their Polars data types |
Source code in thestrat/schemas.py
get_precision_metadata
classmethod
Get precision metadata for all fields.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dict mapping field_name → {'precision_type': str, 'decimal_places': int | None} |
Source code in thestrat/schemas.py
get_required_input_columns
classmethod
Get list of required input columns based on schema definition.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of column names that are required for input data |
Source code in thestrat/schemas.py
get_standard_column_order
classmethod
Get the standard column ordering for aggregation output.
validate_dataframe
classmethod
Validate input DataFrame columns and data types against IndicatorSchema input requirements.
Automatically converts Pandas DataFrames to Polars for consistent validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Polars or Pandas DataFrame to validate |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with validation results including missing/extra columns, type issues, |
dict[str, Any]
|
and the converted Polars DataFrame if conversion occurred |
Source code in thestrat/schemas.py
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 | |
IndicatorsConfig
Bases: BaseModel
Complete configuration for indicators component with per-timeframe settings.
SwingPointsConfig
Bases: BaseModel
Configuration for swing point detection with comprehensive parameter documentation.
TargetConfig
Bases: BaseModel
Configuration for multi-target detection.
TimeframeConfig
Bases: BaseModel
Configuration and validation for timeframes with comprehensive metadata.
Methods:
| Name | Description |
|---|---|
get_optimal_source_timeframe |
Get optimal source timeframe for aggregating to target. |
get_polars_format |
Get the Polars format for a timeframe. |
validate_timeframe |
Validate that the timeframe is supported (strict mode only). |
get_optimal_source_timeframe
classmethod
get_optimal_source_timeframe(
target_timeframe: str, available_timeframes: list[str]
) -> str | None
Get optimal source timeframe for aggregating to target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_timeframe
|
str
|
Target timeframe to aggregate to |
required |
available_timeframes
|
list[str]
|
List of available source timeframes |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Optimal source timeframe or None if target already exists or no valid source |
Source code in thestrat/schemas.py
get_polars_format
classmethod
Get the Polars format for a timeframe.
validate_timeframe
classmethod
TimeframeItemConfig
Bases: BaseModel
Configuration for a single timeframe item with flexible timeframe targeting.
Methods:
| Name | Description |
|---|---|
validate_timeframe_combinations |
Validate that 'all' is not mixed with specific timeframes. |
validate_timeframe_combinations
Validate that 'all' is not mixed with specific timeframes.