Skip to content

Commit

Permalink
wcl price
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jul 3, 2023
1 parent 2e3f582 commit 607688d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions ta_lib/price/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod average;
pub mod median;
pub mod typical;
pub mod wcl;
30 changes: 30 additions & 0 deletions ta_lib/price/src/wcl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pub fn wcl(high: &[f64], low: &[f64], close: &[f64]) -> Vec<f64> {
let len = high.len();

if len != low.len() || len != close.len() {
return vec![0.0; len];
}

high.iter()
.zip(low)
.zip(close)
.map(|((&h, &l), &c)| (h + l + (c * 2.0)) / 4.0)
.collect()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_weighted_close_price() {
let high = vec![1.0, 2.0, 3.0];
let low = vec![0.5, 1.0, 1.5];
let close = vec![0.75, 1.5, 2.25];
let expected = vec![0.75, 1.5, 2.25];

let result = wcl(&high, &low, &close);

assert_eq!(result, expected);
}
}

0 comments on commit 607688d

Please sign in to comment.