Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 2, 2024
1 parent bf3e6b1 commit 69582c5
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 50 deletions.
8 changes: 4 additions & 4 deletions strategy/generator/pulse/braid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
@dataclass(frozen=True)
class BraidPulse(Pulse):
type: PulseType = PulseType.Braid
smooth_type: Parameter = StaticParameter(Smooth.WMA)
period_one: Parameter = StaticParameter(3.0)
period_two: Parameter = StaticParameter(7.0)
period_three: Parameter = StaticParameter(14.0)
smooth_type: Parameter = StaticParameter(Smooth.LSMA)
fast_period: Parameter = StaticParameter(3.0)
slow_period: Parameter = StaticParameter(14.0)
open_period: Parameter = StaticParameter(7.0)
strength: Parameter = StaticParameter(40.0)
atr_period: Parameter = StaticParameter(14.0)
8 changes: 6 additions & 2 deletions ta_lib/indicators/momentum/src/dso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ mod tests {
let k_period = 2;
let d_period = 2;

let expected_k = vec![0.0, 66.66667, 88.88889, 96.2963, 98.76544, 99.588486, 99.86283];
let expected_d = vec![0.0, 44.44445, 74.07408, 88.8889, 95.47326, 98.21674, 99.31413];
let expected_k = vec![
0.0, 66.66667, 88.88889, 96.2963, 98.76544, 99.588486, 99.86283,
];
let expected_d = vec![
0.0, 44.44445, 74.07408, 88.8889, 95.47326, 98.21674, 99.31413,
];

let (k, d) = dso(&close, Smooth::EMA, period, k_period, d_period);

Expand Down
3 changes: 2 additions & 1 deletion ta_lib/indicators/momentum/src/stc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ mod tests {
let d_first = 3;
let d_second = 3;
let expected = vec![
0.0, 50.0, 75.0, 87.5, 93.75, 46.875, 73.4375, 36.71875, 68.359375, 34.179688, 67.08984, 83.54492,
0.0, 50.0, 75.0, 87.5, 93.75, 46.875, 73.4375, 36.71875, 68.359375, 34.179688,
67.08984, 83.54492,
];

let result: Vec<f32> = stc(
Expand Down
137 changes: 137 additions & 0 deletions ta_lib/strategies/confirm/src/dso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,140 @@ impl Confirm for DSOConfirm {
(k.sgt(&d), k.slt(&d))
}
}

#[cfg(test)]
mod tests {
use super::*;
use core::prelude::*;
use std::collections::VecDeque;

#[test]
fn test_confirm_dso() {
let confirm = DSOConfirm::new(Smooth::EMA, 13.0, 8.0, 9.0);
let data = VecDeque::from([
OHLCV {
open: 4.8914,
high: 4.9045,
low: 4.8895,
close: 4.8995,
volume: 100.0,
},
OHLCV {
open: 4.8995,
high: 4.9073,
low: 4.8995,
close: 4.9061,
volume: 100.0,
},
OHLCV {
open: 4.9061,
high: 4.9070,
low: 4.9001,
close: 4.9001,
volume: 100.0,
},
OHLCV {
open: 4.9001,
high: 4.9053,
low: 4.8995,
close: 4.9053,
volume: 100.0,
},
OHLCV {
open: 4.9053,
high: 4.9093,
low: 4.9046,
close: 4.9087,
volume: 100.0,
},
OHLCV {
open: 4.9087,
high: 4.9154,
low: 4.9087,
close: 4.9131,
volume: 100.0,
},
OHLCV {
open: 4.9131,
high: 4.9131,
low: 4.9040,
close: 4.9041,
volume: 100.0,
},
OHLCV {
open: 4.9041,
high: 4.9068,
low: 4.8988,
close: 4.9023,
volume: 100.0,
},
OHLCV {
open: 4.9023,
high: 4.9051,
low: 4.8949,
close: 4.9010,
volume: 100.0,
},
OHLCV {
open: 4.9010,
high: 4.9052,
low: 4.8969,
close: 4.8969,
volume: 100.0,
},
OHLCV {
open: 4.8969,
high: 4.8969,
low: 4.8819,
close: 4.8895,
volume: 100.0,
},
OHLCV {
open: 4.8895,
high: 4.8928,
low: 4.8851,
close: 4.8901,
volume: 100.0,
},
OHLCV {
open: 4.8901,
high: 4.8910,
low: 4.8813,
close: 4.8855,
volume: 100.0,
},
OHLCV {
open: 4.8855,
high: 4.8864,
low: 4.8816,
close: 4.8824,
volume: 100.0,
},
OHLCV {
open: 4.8824,
high: 4.8934,
low: 4.8814,
close: 4.8925,
volume: 100.0,
},
]);
let series = OHLCVSeries::from_data(&data);

let (long_signal, short_signal) = confirm.validate(&series);

let expected_long_signal = vec![
false, true, true, true, true, true, true, true, true, true, false, false, false,
false, false,
];
let expected_short_signal = vec![
false, false, false, false, false, false, false, false, false, false, true, true, true,
true, true,
];

let result_long_signal: Vec<bool> = long_signal.into();
let result_short_signal: Vec<bool> = short_signal.into();

assert_eq!(result_long_signal, expected_long_signal);
assert_eq!(expected_short_signal, result_short_signal);
}
}
Loading

0 comments on commit 69582c5

Please sign in to comment.