Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 27, 2024
1 parent 91531d7 commit eec14b7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions ta_lib/core/src/smoothing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::iff;
use crate::series::Series;
use crate::{iff, nz};

#[derive(Copy, Clone)]
pub enum Smooth {
Expand Down Expand Up @@ -27,7 +27,7 @@ impl Series<f32> {
sum
}

pub fn wg(&self, weights: &[f32], period: usize) -> Self {
pub fn wg(&self, weights: &[f32]) -> Self {
let mut sum = Series::zero(self.len());
let norm = weights.iter().sum::<f32>();

Expand Down Expand Up @@ -60,7 +60,7 @@ impl Series<f32> {
fn wma(&self, period: usize) -> Self {
let weights = (0..period).map(|i| (period - i) as f32).collect::<Vec<_>>();

self.wg(&weights, period)
self.wg(&weights)
}

fn swma(&self) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion ta_lib/indicators/trend/src/alma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn alma(source: &Series<f32>, period: usize, offset: f32, sigma: f32) -> Ser
.map(|i| ((-1. * (i as f32 - m).powi(2)) / (2. * s.powi(2))).exp())
.collect::<Vec<_>>();

source.wg(&weights, period)
source.wg(&weights)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion ta_lib/indicators/trend/src/sinwma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn sinwma(source: &Series<f32>, period: usize) -> Series<f32> {
.map(|i| ((i as f32 + 1.) * std::f32::consts::PI / (period as f32 + 1.)).sin())
.collect::<Vec<_>>();

source.wg(&weights, period)
source.wg(&weights)
}

#[cfg(test)]
Expand Down
38 changes: 19 additions & 19 deletions ta_lib/strategies/base/src/strategy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::source::Source;
use crate::{BaseLine, Confirm, Exit, OHLCVSeries, Pulse, Signal, StopLoss, Strategy, OHLCV};
use core::prelude::*;
use std::collections::VecDeque;

const DEFAULT_LOOKBACK: usize = 55;
const DEFAULT_STOP_LEVEL: f32 = -1.0;
const DEFAULT_BUFF_SIZE: f32 = 1.3;

#[derive(Debug, PartialEq)]
pub enum TradeAction {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl BaseStrategy {
}

fn store(&mut self, data: OHLCV) {
let buf_size = (self.lookback_period as f32 * 1.3) as usize;
let buf_size = (self.lookback_period as f32 * DEFAULT_BUFF_SIZE) as usize;

if self.data.len() > buf_size {
self.data.pop_front();
Expand Down Expand Up @@ -174,6 +174,9 @@ mod tests {
};
use core::Series;

const DEFAULT_BUFF_SIZE: f32 = 1.3;
const DEFAULT_LOOKBACK: usize = 55;

struct MockSignal {
fast_period: usize,
}
Expand Down Expand Up @@ -300,19 +303,16 @@ mod tests {
}),
Box::new(MockExit {}),
);
let lookback = 55;

let ohlcvs = vec![
OHLCV {
ts: 1710297600000,
open: 1.0,
high: 2.0,
low: 0.5,
close: 1.5,
volume: 100.0,
};
lookback
];
let lookback = (DEFAULT_BUFF_SIZE * DEFAULT_LOOKBACK as f32) as usize;
let data = OHLCV {
ts: 1710297600000,
open: 1.0,
high: 2.0,
low: 0.5,
close: 1.5,
volume: 100.0,
};
let ohlcvs = vec![data; lookback];

let mut action = TradeAction::DoNothing;

Expand All @@ -327,10 +327,10 @@ mod tests {
let hlcc4: Vec<f32> = series.hlcc4().into();
let ohlc4: Vec<f32> = series.ohlc4().into();

assert_eq!(hl2, vec![1.25; lookback]);
assert_eq!(hlc3, vec![1.333_333_4; lookback]);
assert_eq!(hlcc4, vec![1.375; lookback]);
assert_eq!(ohlc4, vec![1.25; lookback]);
assert_eq!(hl2, vec![1.25]);
assert_eq!(hlc3, vec![1.333_333_4]);
assert_eq!(hlcc4, vec![1.375]);
assert_eq!(ohlc4, vec![1.25]);
assert_eq!(action, TradeAction::DoNothing);
}
}
22 changes: 11 additions & 11 deletions ta_lib/strategies/pulse/src/braid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,87 +101,87 @@ mod tests {
volume: 100.0,
},
OHLCV {
ts: 1679828100,
ts: 1679828400,
open: 4.9053,
high: 4.9093,
low: 4.9046,
close: 4.9087,
volume: 100.0,
},
OHLCV {
ts: 1679828400,
ts: 1679828700,
open: 4.9087,
high: 4.9154,
low: 4.9087,
close: 4.9131,
volume: 100.0,
},
OHLCV {
ts: 1679828700,
ts: 1679829000,
open: 4.9131,
high: 4.9131,
low: 4.9040,
close: 4.9041,
volume: 100.0,
},
OHLCV {
ts: 1679829000,
ts: 1679829300,
open: 4.9041,
high: 4.9068,
low: 4.8988,
close: 4.9023,
volume: 100.0,
},
OHLCV {
ts: 1679829300,
ts: 1679829600,
open: 4.9023,
high: 4.9051,
low: 4.8949,
close: 4.9010,
volume: 100.0,
},
OHLCV {
ts: 1679829600,
ts: 1679829900,
open: 4.9010,
high: 4.9052,
low: 4.8969,
close: 4.8969,
volume: 100.0,
},
OHLCV {
ts: 1679829900,
ts: 1679830200,
open: 4.8969,
high: 4.8969,
low: 4.8819,
close: 4.8895,
volume: 100.0,
},
OHLCV {
ts: 1679830200,
ts: 1679830500,
open: 4.8895,
high: 4.8928,
low: 4.8851,
close: 4.8901,
volume: 100.0,
},
OHLCV {
ts: 1679830500,
ts: 1679830800,
open: 4.8901,
high: 4.8910,
low: 4.8813,
close: 4.8855,
volume: 100.0,
},
OHLCV {
ts: 1679830800,
ts: 1679831100,
open: 4.8855,
high: 4.8864,
low: 4.8816,
close: 4.8824,
volume: 100.0,
},
OHLCV {
ts: 1679831100,
ts: 1679831400,
open: 4.8824,
high: 4.8934,
low: 4.8814,
Expand Down

0 comments on commit eec14b7

Please sign in to comment.