-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |