Data Processing API
DataProcessor
Source code in src/quantrl_lab/data/processing/processor.py
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 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 246 247 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 | |
load_indicators(file_path)
staticmethod
Load indicator configuration from a YAML or JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the configuration file (.yaml, .yml, or .json) |
required |
Returns:
| Type | Description |
|---|---|
List[Union[str, Dict]]
|
List[Union[str, Dict]]: List of indicator configurations |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist |
ValueError
|
If the file format is unsupported or invalid |
Source code in src/quantrl_lab/data/processing/processor.py
append_technical_indicators(df, indicators=None, **kwargs)
Add technical indicators to existing OHLCV DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
raw OHLCV data |
required |
indicators
|
Optional[List[Union[str, Dict]]]
|
Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if input DataFrame is empty |
ValueError
|
if required columns are missing |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with added technical indicators |
Source code in src/quantrl_lab/data/processing/processor.py
append_news_sentiment_data(df, fillna_strategy='neutral')
Append news sentiment data to the OHLCV DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input OHLCV DataFrame. |
required |
fillna_strategy
|
str
|
Strategy for handling missing sentiment scores. Defaults to "neutral". |
'neutral'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input DataFrame is empty or if the strategy is unsupported. |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with appended news sentiment data. |
Source code in src/quantrl_lab/data/processing/processor.py
drop_unwanted_columns(df, columns_to_drop=None, keep_date=False)
Drop unwanted columns from the DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
columns_to_drop
|
Optional[List[str]]
|
List of column names to drop. If None, will drop default columns ('Date', 'Timestamp', 'Symbol'). Defaults to None. |
None
|
keep_date
|
bool
|
If True, date-related columns will not be dropped. |
False
|
Returns: pd.DataFrame: DataFrame with specified columns dropped.
Source code in src/quantrl_lab/data/processing/processor.py
convert_columns_to_numeric(df, columns=None)
Convert specified columns to numeric, handling date columns carefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame |
required |
columns
|
Optional[List[str]]
|
Specific columns to convert. If None, converts all object columns. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with numeric conversions applied |
Source code in src/quantrl_lab/data/processing/processor.py
data_processing_pipeline(indicators=None, alpha_selection_config=None, fillna_strategy='neutral', split_config=None, **kwargs)
Main data processing pipeline.
Applies technical indicators, sentiment analysis, and data transformations
This method uses the DataPipeline infrastructure internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicators
|
Optional[List[Union[str, Dict]]]
|
List of indicators to apply. Supports: - String format: ["SMA", "RSI"] - Dict format: [{"SMA": {"window": 20}}, {"RSI": {"window": 14}}] Defaults to None (no indicators). |
None
|
alpha_selection_config
|
Optional[Dict]
|
Configuration for dynamic alpha selection. If provided, the pipeline will automatically select and apply the best indicators. Keys: "metric" (default "ic"), "threshold", "top_k", "candidates". |
None
|
fillna_strategy
|
str
|
Strategy for handling missing sentiment scores. Options: "neutral" (fill with 0.0) or "fill_forward" (forward fill). Defaults to "neutral". |
'neutral'
|
split_config
|
Optional[Dict]
|
Configuration for data splitting. If None, returns a single DataFrame. Otherwise, returns dict of DataFrames. Ratio-based: {'train': 0.7, 'test': 0.3} Date-based: {'train': ('2020-01-01', '2021-12-31'), 'test': ('2022-01-01', '2022-12-31')} |
None
|
**kwargs
|
Any
|
Additional arguments: - columns_to_drop: List of columns to drop (overrides default) - columns_to_convert: List of columns to convert to numeric |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[DataFrame, Dict[str, DataFrame]], Dict]
|
Tuple[Union[pd.DataFrame, Dict[str, pd.DataFrame]], Dict]: A tuple containing: - Processed DataFrame if split_config is None - Dictionary of DataFrames if split_config is provided (keys: split names) - Metadata dictionary with processing information |
Source code in src/quantrl_lab/data/processing/processor.py
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 | |
Data Pipeline
The DataPipeline allows for flexible, composable data transformations.
DataPipeline
Composable data processing pipeline.
DataPipeline allows chaining multiple processing steps together using a builder pattern. Each step transforms the DataFrame and can update the processing metadata.
Example
pipeline = (DataPipeline() ... .add_step(TechnicalIndicatorStep(indicators=["SMA", "RSI"])) ... .add_step(SentimentEnrichmentStep(news_data=news_df)) ... .add_step(ColumnCleanupStep(columns_to_drop=["Date"])))
result_df, metadata = pipeline.execute(raw_df) print(metadata.technical_indicators) # ["SMA", "RSI"]
Source code in src/quantrl_lab/data/processing/pipeline.py
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 119 | |
__init__()
add_step(step)
Add a processing step to the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
ProcessingStep
|
ProcessingStep instance to add |
required |
Returns:
| Type | Description |
|---|---|
DataPipeline
|
Self for method chaining (builder pattern) |
Example
pipeline = DataPipeline() pipeline.add_step(TechnicalIndicatorStep(["SMA"])) pipeline.add_step(ColumnCleanupStep())
Source code in src/quantrl_lab/data/processing/pipeline.py
execute(df, symbol=None)
Execute all steps in the pipeline.
Processes the DataFrame through each step sequentially, maintaining metadata throughout the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame to process |
required |
symbol
|
str
|
Optional symbol name for metadata tracking |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, ProcessingMetadata]
|
Tuple of (processed DataFrame, processing metadata) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any step raises a validation error |
Example
pipeline = DataPipeline().add_step(TechnicalIndicatorStep(["SMA"])) result_df, metadata = pipeline.execute(raw_df) assert "SMA_20" in result_df.columns
Source code in src/quantrl_lab/data/processing/pipeline.py
get_steps()
Get list of all steps in the pipeline.
Returns:
| Type | Description |
|---|---|
List[ProcessingStep]
|
List of ProcessingStep instances |
__len__()
__repr__()
Return string representation of pipeline.
Processing Steps
Processing steps encapsulate individual transformations. They can be chained together in a pipeline.
Base Interface
ProcessingStep
Bases: Protocol
Protocol for pipeline processing steps.
Steps are composable transformations that take a DataFrame and metadata, apply a transformation, and return the modified DataFrame. Steps should update the metadata to track what transformations were applied.
Example
step = TechnicalIndicatorStep(indicators=["SMA", "RSI"]) result_df = step.process(input_df, metadata) assert "SMA_20" in result_df.columns
Source code in src/quantrl_lab/data/processing/steps/base.py
process(data, metadata)
Apply transformation to DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input DataFrame to process |
required |
metadata
|
ProcessingMetadata
|
Processing metadata to track transformations |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Transformed DataFrame (may be modified in-place or copied) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is invalid or missing required columns |
Source code in src/quantrl_lab/data/processing/steps/base.py
get_step_name()
Return human-readable name of this processing step.
Returns:
| Type | Description |
|---|---|
str
|
Step name (e.g., "Technical Indicators", "Sentiment Enrichment") |
Available Steps
TechnicalIndicatorStep
Apply technical indicators to DataFrame.
This step wraps TechnicalFeatureGenerator to add technical indicators as new columns. Indicators can be specified as strings (use defaults) or dicts (with custom parameters).
Example
step = TechnicalIndicatorStep(indicators=["SMA", {"RSI": {"window": 14}}]) result = step.process(df, metadata)
Source code in src/quantrl_lab/data/processing/steps/features/technical.py
__init__(indicators=None)
Initialize technical indicator step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicators
|
Optional[List[Union[str, Dict]]]
|
List of indicators to apply. Can be strings ("SMA") or dicts ({"SMA": {"window": 20}}). |
None
|
Source code in src/quantrl_lab/data/processing/steps/features/technical.py
process(data, metadata)
Apply technical indicators to DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input DataFrame with OHLCV data |
required |
metadata
|
ProcessingMetadata
|
Processing metadata (updated with applied indicators) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with technical indicator columns added |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required columns are missing |
Source code in src/quantrl_lab/data/processing/steps/features/technical.py
SentimentEnrichmentStep
Add news sentiment scores to DataFrame.
This step enriches OHLCV data with sentiment scores computed from news data. Requires news_data to be provided.
Example
step = SentimentEnrichmentStep( ... news_data=news_df, ... provider=HuggingFaceProvider(), ... fillna_strategy="neutral" ... ) result = step.process(df, metadata)
Source code in src/quantrl_lab/data/processing/steps/alternative/sentiment.py
__init__(news_data, provider=None, config=None, fillna_strategy='neutral')
Initialize sentiment enrichment step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
news_data
|
DataFrame
|
DataFrame with news articles |
required |
provider
|
SentimentProvider
|
Sentiment analysis provider (default: HuggingFaceProvider) |
None
|
config
|
SentimentConfig
|
Sentiment configuration |
None
|
fillna_strategy
|
str
|
Strategy for filling missing scores ("neutral" or "fill_forward") |
'neutral'
|
Source code in src/quantrl_lab/data/processing/steps/alternative/sentiment.py
process(data, metadata)
Add sentiment scores to DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input OHLCV DataFrame |
required |
metadata
|
ProcessingMetadata
|
Processing metadata (updated with sentiment flag) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with sentiment scores added |
Raises:
| Type | Description |
|---|---|
ValueError
|
If news_data is empty or invalid |
Source code in src/quantrl_lab/data/processing/steps/alternative/sentiment.py
AnalystEstimatesStep
Merge analyst grades and ratings into the DataFrame.
This step merges historical analyst data (grades, ratings) onto the main OHLCV DataFrame based on timestamps. Since analyst updates are sparse, values are forward-filled to represent the "current" analyst consensus at each time step.
Attributes:
| Name | Type | Description |
|---|---|---|
grades_df |
DataFrame
|
Historical grades data. |
ratings_df |
DataFrame
|
Historical ratings data. |
Source code in src/quantrl_lab/data/processing/steps/alternative/analyst.py
11 12 13 14 15 16 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
process(data, metadata)
Merge and forward-fill analyst data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input OHLCV DataFrame (must have datetime index or 'Date'/'Timestamp' column) |
required |
metadata
|
ProcessingMetadata
|
Processing metadata |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with added analyst features |
Source code in src/quantrl_lab/data/processing/steps/alternative/analyst.py
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 | |
MarketContextStep
Merge broad market context (Sector/Industry performance) into the DataFrame.
This step allows the agent to see how the specific stock's sector or industry is performing relative to the stock itself.
Attributes:
| Name | Type | Description |
|---|---|---|
sector_perf_df |
DataFrame
|
Historical sector performance. |
industry_perf_df |
DataFrame
|
Historical industry performance. |
Source code in src/quantrl_lab/data/processing/steps/features/context.py
11 12 13 14 15 16 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 | |
process(data, metadata)
Merge sector and industry data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input OHLCV DataFrame |
required |
metadata
|
ProcessingMetadata
|
Processing metadata |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with added context features (prefixed with sector_ or industry_) |
Source code in src/quantrl_lab/data/processing/steps/features/context.py
NumericConversionStep
Convert DataFrame columns to numeric types.
This step converts object columns to numeric, while preserving date columns. Useful for ensuring proper data types before feeding to ML models.
Example
step = NumericConversionStep(columns=["volume", "price"]) result = step.process(df, metadata)
Source code in src/quantrl_lab/data/processing/steps/cleaning/conversion.py
__init__(columns=None)
Initialize numeric conversion step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
List[str]
|
Specific columns to convert. If None, converts all object columns excluding date columns. Defaults to None. |
None
|
Source code in src/quantrl_lab/data/processing/steps/cleaning/conversion.py
process(data, metadata)
Convert specified columns to numeric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input DataFrame. |
required |
metadata
|
ProcessingMetadata
|
Processing metadata (not modified). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with numeric columns. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If columns is not a list. |
Source code in src/quantrl_lab/data/processing/steps/cleaning/conversion.py
ColumnCleanupStep
Drop unwanted columns from DataFrame.
This step removes specified columns or default columns (Date, Timestamp, Symbol) from the DataFrame.
Example
step = ColumnCleanupStep(columns_to_drop=["Date", "Symbol"]) result = step.process(df, metadata)
Source code in src/quantrl_lab/data/processing/steps/cleaning/cleanup.py
__init__(columns_to_drop=None, keep_date=False)
Initialize column cleanup step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns_to_drop
|
Optional[List[str]]
|
List of columns to drop. If None, drops default columns. |
None
|
keep_date
|
bool
|
If True, preserve date columns even if in columns_to_drop. |
False
|
Source code in src/quantrl_lab/data/processing/steps/cleaning/cleanup.py
process(data, metadata)
Drop specified columns from DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input DataFrame |
required |
metadata
|
ProcessingMetadata
|
Processing metadata (updated with dropped columns) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns removed |