From 18bd95305e7d890ae1636d4ca7cebf1b6d3fb696 Mon Sep 17 00:00:00 2001 From: gord chung <5091603+chungg@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:18:45 -0400 Subject: [PATCH] performance functions --- src/lib.rs | 1 + src/performance.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/performance.rs diff --git a/src/lib.rs b/src/lib.rs index 5665480..89a7388 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod correlation; pub mod momentum; +pub mod performance; pub mod smooth; pub mod statistic; pub mod trend; diff --git a/src/performance.rs b/src/performance.rs new file mode 100644 index 0000000..7cd7e38 --- /dev/null +++ b/src/performance.rs @@ -0,0 +1,18 @@ +use itertools::izip; + +use crate::smooth; + +/// Drawdown +/// +/// Measures an investment or trading account's decline from the peak before it recovers back +/// to that peak. +/// +/// ## Sources +/// +/// [[1]](https://www.investopedia.com/terms/d/drawdown.asp) +pub fn drawdown(data: &[f64]) -> impl Iterator + '_ { + data.iter().scan(data[0], |state, &x| { + *state = state.max(x); + Some(1.0 - (x / *state)) + }) +}