#[cfg(test)] mod hyperopt_kelly_params_tests { use ml::hyperopt::adapters::dqn::DQNParams; use ml::hyperopt::traits::ParameterSpace; #[test] fn test_search_space_has_22_dimensions() { let bounds = DQNParams::continuous_bounds(); assert_eq!(bounds.len(), 22, "Search space should be 22D after adding Kelly params"); } #[test] fn test_kelly_fractional_bounds() { let bounds = DQNParams::continuous_bounds(); let (min, max) = bounds[18]; // Kelly fractional at index 18 assert_eq!(min, 0.25, "Kelly fractional min should be 0.25 (quarter-Kelly)"); assert_eq!(max, 1.0, "Kelly fractional max should be 1.0 (full-Kelly)"); } #[test] fn test_kelly_max_fraction_bounds() { let bounds = DQNParams::continuous_bounds(); let (min, max) = bounds[19]; assert_eq!(min, 0.1, "Kelly max_fraction min should be 0.1 (10%)"); assert_eq!(max, 0.5, "Kelly max_fraction max should be 0.5 (50%)"); } #[test] fn test_kelly_min_trades_bounds() { let bounds = DQNParams::continuous_bounds(); let (min, max) = bounds[20]; assert_eq!(min, 10.0, "Kelly min_trades min should be 10"); assert_eq!(max, 50.0, "Kelly min_trades max should be 50"); } #[test] fn test_volatility_window_bounds() { let bounds = DQNParams::continuous_bounds(); let (min, max) = bounds[21]; assert_eq!(min, 10.0, "Volatility window min should be 10"); assert_eq!(max, 30.0, "Volatility window max should be 30"); } #[test] fn test_from_continuous_accepts_22d() { let x = vec![ // Existing 18 params (use mid-range values) (-4.5_f64).ln(), 112.0, 0.97, (75000.0_f64).ln(), 1.5, 6.0, (25.0_f64).ln(), 0.05, 1.25, 0.6, 0.4, -2.0, 2.0, (0.5_f64).ln(), 320.0, 3.0, 126.0, 1.55, // New Kelly params 0.5, 0.25, 30.0, 20.0 ]; let result = DQNParams::from_continuous(&x); assert!(result.is_ok(), "Should accept 22D parameter vector"); let params = result.unwrap(); assert!((params.kelly_fractional - 0.5).abs() < 0.01); assert!((params.kelly_max_fraction - 0.25).abs() < 0.01); assert_eq!(params.kelly_min_trades, 30); assert_eq!(params.volatility_window, 20); } #[test] fn test_from_continuous_rejects_18d() { let x = vec![ (-4.5_f64).ln(), 112.0, 0.97, (75000.0_f64).ln(), 1.5, 6.0, (25.0_f64).ln(), 0.05, 1.25, 0.6, 0.4, -2.0, 2.0, (0.5_f64).ln(), 320.0, 3.0, 126.0, 1.55, ]; let result = DQNParams::from_continuous(&x); assert!(result.is_err(), "Should reject old 18D parameter vector"); } }