Utilities
Experiments
core
ExperimentJob
dataclass
Defines a single atomic unit of work for the backtesting engine.
Contains all necessary information to run and reproduce a specific experiment.
Source code in src/quantrl_lab/experiments/backtesting/core.py
ExperimentResult
dataclass
Standardized result object containing all artifacts from a job.
Source code in src/quantrl_lab/experiments/backtesting/core.py
JobGenerator
Helper to generate combinatorial lists of jobs.
Source code in src/quantrl_lab/experiments/backtesting/core.py
generate_grid(algorithms, env_configs, algorithm_configs=None, **job_kwargs)
staticmethod
Generate a grid of experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithms
|
List[Type]
|
List of algorithm classes |
required |
env_configs
|
Dict[str, BacktestEnvironmentConfig]
|
Dictionary of name -> BacktestEnvironmentConfig |
required |
algorithm_configs
|
Optional[List[Dict[str, Any]]]
|
List of configuration dictionaries to try. If None, uses a single empty dict (defaults). |
None
|
**job_kwargs
|
Common arguments for all jobs (total_timesteps, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
List[ExperimentJob]
|
List[ExperimentJob]: List of jobs to be executed |
Source code in src/quantrl_lab/experiments/backtesting/core.py
runner
BacktestRunner
Orchestrates complete backtesting workflows by chaining training and evaluation.
This class provides high-level interfaces for running comprehensive experiments that train multiple algorithms on different environment configurations and evaluate their performance.
Source code in src/quantrl_lab/experiments/backtesting/runner.py
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 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 | |
run_job(job)
Executes a single experiment job using the new Job/Batch architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
ExperimentJob
|
The job description containing all parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExperimentResult |
ExperimentResult
|
The result of the experiment. |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
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 | |
run_batch(jobs)
Executes a batch of jobs sequentially (can be upgraded to parallel later).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jobs
|
List[ExperimentJob]
|
List of jobs to run. |
required |
Returns:
| Type | Description |
|---|---|
List[ExperimentResult]
|
List[ExperimentResult]: Results for each job. |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
inspect_result(result)
staticmethod
Inspect and display the results of a single experiment job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ExperimentResult
|
The result object to inspect. |
required |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
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 | |
inspect_batch(results)
staticmethod
Inspect and display a summary of a batch of experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
List[ExperimentResult]
|
List of experiment results. |
required |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
create_env_config(train_env_factory, test_env_factory)
staticmethod
Helper method to create env_config from individual factory functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_env_factory
|
Callable
|
Function that creates training environment |
required |
test_env_factory
|
Callable
|
Function that creates test environment |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BacktestEnvironmentConfig |
BacktestEnvironmentConfig
|
Environment configuration object |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
create_env_config_factory(train_data, test_data, action_strategy, reward_strategy, observation_strategy, eval_data=None, initial_balance=100000.0, transaction_cost_pct=0.001, slippage_pct=0.0005, window_size=20, order_expiration_steps=5)
staticmethod
Creates a configuration object with environment factories. DEPRECATED: Use BacktestEnvironmentBuilder instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
DataFrame
|
DataFrame for the training environment. |
required |
test_data
|
DataFrame
|
DataFrame for the test environment. |
required |
action_strategy
|
BaseActionStrategy
|
The action strategy to use. |
required |
reward_strategy
|
BaseRewardStrategy
|
The reward strategy to use. |
required |
observation_strategy
|
BaseObservationStrategy
|
The observation strategy. |
required |
eval_data
|
Optional[DataFrame]
|
DataFrame for evaluation. |
None
|
initial_balance
|
float
|
Initial portfolio balance. |
100000.0
|
transaction_cost_pct
|
float
|
Transaction cost percentage. |
0.001
|
window_size
|
int
|
The size of the observation window. |
20
|
Returns:
| Name | Type | Description |
|---|---|---|
BacktestEnvironmentConfig |
BacktestEnvironmentConfig
|
Configuration object containing factories and metadata. |
Source code in src/quantrl_lab/experiments/backtesting/runner.py
optuna_runner
OptunaRunner
A hyperparameter tuning runner using Optuna with SQLite storage.
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
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 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 | |
__init__(runner, storage_url=None)
Initialize the runner with Optuna configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runner
|
BacktestRunner
|
BacktestRunner instance |
required |
storage_url
|
Optional[str]
|
Optuna storage URL (defaults to sqlite:///optuna_studies.db) |
None
|
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
create_objective_function(algo_class, env_config, search_space, fixed_params=None, total_timesteps=50000, num_eval_episodes=5, optimization_metric='test_avg_return_pct')
Create an objective function for Optuna optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algo_class
|
RL algorithm class (PPO, SAC, A2C, etc.) |
required | |
env_config
|
Union[Dict[str, Any], BacktestEnvironmentConfig]
|
Environment configuration object or dictionary |
required |
search_space
|
Dict[str, Any]
|
Dictionary defining the hyperparameter search space |
required |
fixed_params
|
Optional[Dict[str, Any]]
|
Fixed parameters that won't be optimized |
None
|
total_timesteps
|
int
|
Number of training timesteps |
50000
|
num_eval_episodes
|
int
|
Number of evaluation episodes |
5
|
optimization_metric
|
str
|
Metric to optimize (default: test_avg_return_pct). Can use any metric from MetricsCalculator (e.g., 'test_avg_sharpe_ratio'). |
'test_avg_return_pct'
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
The objective function for Optuna. |
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
optimize_hyperparameters(algo_class, env_config, search_space, study_name, n_trials=100, fixed_params=None, total_timesteps=50000, num_eval_episodes=5, optimization_metric='test_avg_return_pct', direction='maximize', timeout=None, n_jobs=1, sampler=None, pruner=None)
Run hyperparameter optimization using Optuna.
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
create_ppo_search_space()
Create a default search space for PPO hyperparameters.
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
create_sac_search_space()
Create a default search space for SAC hyperparameters.
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
create_a2c_search_space()
Create a default search space for A2C hyperparameters.
Source code in src/quantrl_lab/experiments/tuning/optuna_runner.py
Data Partitioning
date_range
Date range-based data splitter for time series data.
DateRangeSplitter
Split DataFrame by explicit date ranges.
This splitter divides data based on specified date ranges, useful for creating specific train/test periods.
Example
splitter = DateRangeSplitter({ ... "train": ("2020-01-01", "2021-12-31"), ... "test": ("2022-01-01", "2022-12-31") ... }) splits = splitter.split(df) train_df = splits["train"] test_df = splits["test"]
Source code in src/quantrl_lab/data/partitioning/date_range.py
8 9 10 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 142 143 144 145 146 147 148 149 150 | |
__init__(ranges)
Initialize DateRangeSplitter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
Dict[str, Tuple[str, str]]
|
Dictionary mapping split names to (start_date, end_date) tuples. Dates can be strings or datetime objects. Example: {"train": ("2020-01-01", "2021-12-31")} |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ranges are invalid or empty. |
Source code in src/quantrl_lab/data/partitioning/date_range.py
split(df)
Split DataFrame by date ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame to split. Must have a date column (Date, date, timestamp, or Timestamp). |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Dictionary of split DataFrames. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If DataFrame is empty or date column not found. |
Source code in src/quantrl_lab/data/partitioning/date_range.py
get_metadata()
Return metadata about the split.
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Dictionary containing: - type: "date_range" - ranges: Configuration used - date_ranges: Actual date ranges in each split - final_shapes: Shape of each split DataFrame |
Source code in src/quantrl_lab/data/partitioning/date_range.py
ratio
Ratio-based data splitter for time series data.
RatioSplitter
Split DataFrame by ratio (e.g., 70% train, 30% test).
This splitter divides data sequentially based on specified ratios, maintaining temporal order for time series data.
Example
splitter = RatioSplitter({"train": 0.7, "test": 0.3}) splits = splitter.split(df) train_df = splits["train"] test_df = splits["test"]
Source code in src/quantrl_lab/data/partitioning/ratio.py
8 9 10 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 | |
__init__(ratios)
Initialize RatioSplitter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratios
|
Dict[str, float]
|
Dictionary mapping split names to ratios. Ratios must sum to <= 1.0. Example: {"train": 0.7, "test": 0.3} |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ratios sum to > 1.0 or any ratio is invalid. |
Source code in src/quantrl_lab/data/partitioning/ratio.py
split(df)
Split DataFrame by ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame to split. Should be sorted by time. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Dictionary of split DataFrames. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If DataFrame is empty. |
Source code in src/quantrl_lab/data/partitioning/ratio.py
get_metadata()
Return metadata about the split.
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Dictionary containing: - type: "ratio" - ratios: Configuration used - date_ranges: Date ranges for each split (if date column exists) - final_shapes: Shape of each split DataFrame |
Source code in src/quantrl_lab/data/partitioning/ratio.py
Indicator Registry
registry
IndicatorMetadata
dataclass
Metadata for registered indicators.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Indicator name (e.g., 'SMA', 'RSI') |
func |
Callable
|
The callable function that computes the indicator |
required_columns |
Set[str]
|
Set of required DataFrame columns (e.g., {'close', 'volume'}) |
output_columns |
List[str]
|
List of column names this indicator adds to DataFrame |
dependencies |
List[str]
|
List of other indicator names that must be computed first |
description |
str
|
Human-readable description of what the indicator computes |
Source code in src/quantrl_lab/data/indicators/registry.py
IndicatorRegistry
Registry for technical indicators with metadata and validation.
This registry uses a decorator pattern to register indicator functions along with metadata about their requirements and outputs. It provides validation to ensure DataFrames have the required columns before applying indicators.
Example
@IndicatorRegistry.register( ... name='SMA', ... required_columns={'close'}, ... output_columns=['SMA'], ... description="Simple Moving Average" ... ) ... def sma(df, window=20, column='close'): ... df[f'SMA_{window}'] = df[column].rolling(window=window).mean() ... return df
Use with validation
df = IndicatorRegistry.apply_safe('SMA', df, window=20)
Source code in src/quantrl_lab/data/indicators/registry.py
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 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 | |
register(name=None, required_columns=None, output_columns=None, dependencies=None, description='')
classmethod
Register an indicator function with metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Indicator name. If None, uses function name. |
None
|
required_columns
|
Optional[Set[str]]
|
Set of required DataFrame columns (case-insensitive). Example: {'close'}, {'high', 'low', 'close'} |
None
|
output_columns
|
Optional[List[str]]
|
List of column names this indicator will add. If None, defaults to [name]. |
None
|
dependencies
|
Optional[List[str]]
|
List of other indicator names that must be applied first. |
None
|
description
|
str
|
Human-readable description of the indicator. |
''
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator function that registers the indicator. |
Example
@IndicatorRegistry.register( ... name='RSI', ... required_columns={'close'}, ... output_columns=['RSI'], ... description="Relative Strength Index" ... ) ... def rsi(df, window=14): ... # calculation ... return df
Source code in src/quantrl_lab/data/indicators/registry.py
get(name)
classmethod
Get the indicator function by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the indicator |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the name is not found in the registry |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
Indicator function |
Source code in src/quantrl_lab/data/indicators/registry.py
get_metadata(name)
classmethod
Get the full metadata for an indicator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the indicator |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the name is not found in the registry |
Returns:
| Name | Type | Description |
|---|---|---|
IndicatorMetadata |
IndicatorMetadata
|
Metadata object for the indicator |
Source code in src/quantrl_lab/data/indicators/registry.py
list_all()
classmethod
List all registered indicators.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of indicator names |
validate_compatibility(df, indicator_name)
classmethod
Check if DataFrame has required columns for indicator.
Performs case-insensitive column checking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to validate |
required |
indicator_name
|
str
|
Name of the indicator to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if DataFrame has all required columns |
Raises:
| Type | Description |
|---|---|
KeyError
|
If indicator is not registered |
Source code in src/quantrl_lab/data/indicators/registry.py
get_missing_columns(df, indicator_name)
classmethod
Get the set of missing required columns for an indicator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to check |
required |
indicator_name
|
str
|
Name of the indicator |
required |
Returns:
| Type | Description |
|---|---|
Set[str]
|
Set[str]: Set of missing column names (from required_columns) |
Raises:
| Type | Description |
|---|---|
KeyError
|
If indicator is not registered |
Source code in src/quantrl_lab/data/indicators/registry.py
apply(name, df, **kwargs)
classmethod
Apply the indicator function to the dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the indicator |
required |
df
|
DataFrame
|
Input dataframe |
required |
**kwargs
|
Additional keyword arguments to be passed to the indicator function |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with the indicator added |
Raises:
| Type | Description |
|---|---|
KeyError
|
If indicator is not registered |
Source code in src/quantrl_lab/data/indicators/registry.py
apply_safe(name, df, **kwargs)
classmethod
Apply indicator with validation.
Validates that the DataFrame has all required columns before applying the indicator. Raises a descriptive error if columns are missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the indicator |
required |
df
|
DataFrame
|
Input dataframe |
required |
**kwargs
|
Additional keyword arguments to be passed to the indicator function |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with the indicator added |
Raises:
| Type | Description |
|---|---|
KeyError
|
If indicator is not registered |
ValueError
|
If DataFrame is missing required columns |
Source code in src/quantrl_lab/data/indicators/registry.py
Environment Utilities
market_data
detect_column_index(df, candidates)
Detect a column index from a list of candidates (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to search. |
required |
candidates
|
List[str]
|
List of column names to look for. |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The index of the first matching column, or None if not found. |
Source code in src/quantrl_lab/environments/utils/market_data.py
auto_detect_price_column(df)
Auto-detect the price column index from a DataFrame using standard naming conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with price data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Index of the detected price column. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no suitable price column is found. |
Source code in src/quantrl_lab/environments/utils/market_data.py
calc_trend(prices)
Calculate the trend strength of a price series using linear regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prices
|
ndarray
|
Array of price data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The calculated trend strength (slope / max_price). Returns 0.0 if not enough data. |