Coverage for src / monte_neo / core / generator_utils.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-28 16:27 +0200
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-28 16:27 +0200
1from __future__ import annotations
3import time
4from typing import TYPE_CHECKING, Any
6import pandas as pd
8if TYPE_CHECKING:
9 pass
11# Parameter search spaces for each indicator type
12PARAM_SPACES = {
13 "sma": {
14 "fast_period": (5, 50),
15 "slow_period": (20, 200),
16 },
17 "rsi": {
18 "period": (5, 30),
19 "overbought": (65, 85),
20 "oversold": (15, 35),
21 },
22 "macd": {
23 "fast": (8, 20),
24 "slow": (20, 40),
25 "signal": (5, 15),
26 },
27 "dynamic": {},
28}
31def estimate_time(generator: Any, data: pd.DataFrame) -> float:
32 """Estimate generation time in minutes.
34 Args:
35 generator: IndicatorGenerator instance (typed as Any to avoid circular import)
36 data: Sample data.
38 Returns:
39 Estimated time in minutes.
40 """
41 # Run small sample
42 sample_iterations = 10
43 start = time.time()
45 for _ in range(sample_iterations):
46 indicator = generator._generate_random_indicator()
47 signals = indicator.generate_signals(data)
48 _ = generator.metrics_calc.calculate_all(data, signals)
50 elapsed = time.time() - start
51 time_per_iter = elapsed / sample_iterations
53 # Account for MC validation (~10x slower)
54 mc_factor = (
55 10
56 if any(
57 [
58 generator.config.use_mc_shuffling,
59 generator.config.use_mc_noise,
60 ]
61 )
62 else 2
63 )
65 total_seconds = time_per_iter * generator.config.max_iterations * mc_factor
66 return total_seconds / 60