Skip to main content

total_return

Function total_return 

Source
pub fn total_return(price_start: f64, price_end: f64) -> FinanceResult<f64>
Expand description

Total simple return from first to last price: (end - start) / start.

ยงExamples

use finance_solution::{total_return, FinanceError};

let r = total_return(100.0, 125.0).unwrap();
assert!((r - 0.25).abs() < 1e-12);
assert!(matches!(
    total_return(0.0, 125.0),
    Err(FinanceError::ZeroValue { .. })
));