Skip to content

Commit

Permalink
udp
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed May 1, 2024
1 parent af6855e commit 1fc3d2c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/models/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Smooth(Enum):
WMA = 6
ZLEMA = 7
LSMA = 8
TEMA = 9

def __str__(self):
return self.name.upper()
10 changes: 10 additions & 0 deletions ta_lib/core/src/smoothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Smooth {
WMA,
ZLEMA,
LSMA,
TEMA,
}

impl Series<f32> {
Expand Down Expand Up @@ -63,6 +64,14 @@ impl Series<f32> {
self.ew(&alpha, &seed)
}

fn tema(&self, period: usize) -> Self {
let ema1 = self.ema(period);
let ema2 = ema1.ema(period);
let ema3 = ema2.ema(period);

3. * (ema1 - ema2) + ema3
}

fn wma(&self, period: usize) -> Self {
let weights = (0..period).map(|i| (period - i) as f32).collect::<Vec<_>>();

Expand Down Expand Up @@ -130,6 +139,7 @@ impl Series<f32> {
Smooth::WMA => self.wma(period),
Smooth::ZLEMA => self.zlema(period),
Smooth::LSMA => self.linreg(period),
Smooth::TEMA => self.tema(period),
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions ta_lib/indicators/trend/src/tema.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use core::prelude::*;

pub fn tema(source: &Series<f32>, period: usize) -> Series<f32> {
let ema1 = source.smooth(Smooth::EMA, period);
let ema2 = ema1.smooth(Smooth::EMA, period);
let ema3 = ema2.smooth(Smooth::EMA, period);

3. * (ema1 - ema2) + ema3
source.smooth(Smooth::TEMA, period)
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions ta_lib/indicators/trend/src/zlhma.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::prelude::*;

pub fn zlhma(source: &Series<f32>, period: usize, smooth_period: usize) -> Series<f32> {
let hma = source.smooth(Smooth::HMA, period);

hma.smooth(Smooth::HMA, smooth_period)
source
.smooth(Smooth::HMA, period)
.smooth(Smooth::HMA, smooth_period)
}

#[cfg(test)]
Expand Down
14 changes: 3 additions & 11 deletions ta_lib/indicators/trend/src/zltema.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use core::prelude::*;

pub fn zltema(source: &Series<f32>, period: usize) -> Series<f32> {
let ema1 = source.smooth(Smooth::EMA, period);
let ema2 = ema1.smooth(Smooth::EMA, period);
let ema3 = ema2.smooth(Smooth::EMA, period);

let tema = 3. * (ema1 - ema2) + ema3;

let tema1 = tema.smooth(Smooth::EMA, period);
let tema2 = tema1.smooth(Smooth::EMA, period);
let tema3 = tema2.smooth(Smooth::EMA, period);

3. * (tema1 - tema2) + tema3
source
.smooth(Smooth::TEMA, period)
.smooth(Smooth::TEMA, period)
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn smooth_deserialize(smooth: usize) -> Smooth {
6 => Smooth::WMA,
7 => Smooth::ZLEMA,
8 => Smooth::LSMA,
9 => Smooth::TEMA,
_ => Smooth::EMA,
}
}

0 comments on commit 1fc3d2c

Please sign in to comment.