Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod correlation;
pub mod momentum;
pub mod performance;
pub mod smooth;
pub mod statistic;
pub mod trend;
Expand Down
18 changes: 18 additions & 0 deletions src/performance.rs
Original file line number Diff line number Diff line change
@@ -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<Item = f64> + '_ {
data.iter().scan(data[0], |state, &x| {
*state = state.max(x);
Some(1.0 - (x / *state))
})
}