use positive::Positive;
#[allow(dead_code)]
#[derive(Debug)]
pub struct StrategyProbabilityAnalysis {
pub probability_of_profit: Positive,
pub probability_of_max_profit: Positive,
pub probability_of_max_loss: Positive,
pub expected_value: Positive,
pub break_even_points: Vec<Positive>,
pub risk_reward_ratio: Positive,
}
#[cfg(test)]
mod tests {
use super::*;
use positive::pos_or_panic;
use rust_decimal_macros::dec;
#[test]
fn test_strategy_analysis_creation() {
let analysis = StrategyProbabilityAnalysis {
probability_of_profit: pos_or_panic!(0.65),
probability_of_max_profit: pos_or_panic!(0.30),
probability_of_max_loss: pos_or_panic!(0.20),
expected_value: pos_or_panic!(250.00),
break_even_points: vec![pos_or_panic!(45.50), pos_or_panic!(55.50)],
risk_reward_ratio: pos_or_panic!(0.75),
};
assert_eq!(analysis.probability_of_profit.to_dec(), dec!(0.65));
assert_eq!(analysis.probability_of_max_profit.to_dec(), dec!(0.30));
assert_eq!(analysis.probability_of_max_loss.to_dec(), dec!(0.20));
assert_eq!(analysis.expected_value.to_dec(), dec!(250.00));
assert_eq!(analysis.break_even_points.len(), 2);
assert_eq!(analysis.break_even_points[0].to_dec(), dec!(45.50));
assert_eq!(analysis.break_even_points[1].to_dec(), dec!(55.50));
assert_eq!(analysis.risk_reward_ratio.to_dec(), dec!(0.75));
}
#[test]
fn test_debug_implementation() {
let analysis = StrategyProbabilityAnalysis {
probability_of_profit: pos_or_panic!(0.60),
probability_of_max_profit: pos_or_panic!(0.25),
probability_of_max_loss: pos_or_panic!(0.15),
expected_value: pos_or_panic!(100.00),
break_even_points: vec![pos_or_panic!(50.00)],
risk_reward_ratio: pos_or_panic!(1.00),
};
let debug_str = format!("{analysis:?}");
assert!(!debug_str.is_empty());
assert!(debug_str.contains("StrategyProbabilityAnalysis"));
}
#[test]
fn test_with_empty_break_even_points() {
let analysis = StrategyProbabilityAnalysis {
probability_of_profit: pos_or_panic!(0.70),
probability_of_max_profit: pos_or_panic!(0.40),
probability_of_max_loss: pos_or_panic!(0.10),
expected_value: pos_or_panic!(350.00),
break_even_points: vec![],
risk_reward_ratio: pos_or_panic!(0.50),
};
assert_eq!(analysis.break_even_points.len(), 0);
}
#[test]
fn test_with_multiple_break_even_points() {
let analysis = StrategyProbabilityAnalysis {
probability_of_profit: pos_or_panic!(0.55),
probability_of_max_profit: pos_or_panic!(0.20),
probability_of_max_loss: pos_or_panic!(0.25),
expected_value: pos_or_panic!(150.00),
break_even_points: vec![
pos_or_panic!(40.00),
pos_or_panic!(50.00),
pos_or_panic!(60.00),
],
risk_reward_ratio: pos_or_panic!(1.25),
};
assert_eq!(analysis.break_even_points.len(), 3);
assert_eq!(analysis.break_even_points[0].to_dec(), dec!(40.00));
assert_eq!(analysis.break_even_points[1].to_dec(), dec!(50.00));
assert_eq!(analysis.break_even_points[2].to_dec(), dec!(60.00));
}
#[test]
fn test_probability_values_within_range() {
let analysis = StrategyProbabilityAnalysis {
probability_of_profit: pos_or_panic!(0.65),
probability_of_max_profit: pos_or_panic!(0.30),
probability_of_max_loss: pos_or_panic!(0.20),
expected_value: pos_or_panic!(250.00),
break_even_points: vec![pos_or_panic!(45.50), pos_or_panic!(55.50)],
risk_reward_ratio: pos_or_panic!(0.75),
};
assert!(
analysis.probability_of_profit.to_dec() >= dec!(0)
&& analysis.probability_of_profit.to_dec() <= dec!(1)
);
assert!(
analysis.probability_of_max_profit.to_dec() >= dec!(0)
&& analysis.probability_of_max_profit.to_dec() <= dec!(1)
);
assert!(
analysis.probability_of_max_loss.to_dec() >= dec!(0)
&& analysis.probability_of_max_loss.to_dec() <= dec!(1)
);
}
}