Skip to main content

log_return

Function log_return 

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

Logarithmic return: ln(p1 / p0). Requires strictly positive prices.

ยงExamples

use finance_solution::{log_return, FinanceError};

assert!(log_return(100.0, 110.0).is_ok());
match log_return(-1.0, 110.0) {
    Err(FinanceError::InvalidCashflow { message }) => {
        assert!(message.contains("positive"));
    }
    other => panic!("expected InvalidCashflow, got {other:?}"),
}