From bfe89fe1259639ee91d1f54666cebcb1c592da41 Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Tue, 16 Apr 2024 14:48:25 +0300 Subject: [PATCH] upd --- strategy/generator/pulse/braid.py | 2 +- strategy/generator/pulse/wae.py | 6 +++--- strategy/generator/signal/bb/macd_bb.py | 1 + strategy/generator/signal/bb/vwap_bb.py | 2 +- ta_lib/strategies/signal/src/bb/macd_bb.rs | 5 ++++- ta_lib/strategies/signal/src/bb/vwap_bb.rs | 8 ++++---- .../strategies/trend_follow/src/config/signal_config.rs | 3 ++- .../strategies/trend_follow/src/mapper/signal_mapper.rs | 6 ++++-- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/strategy/generator/pulse/braid.py b/strategy/generator/pulse/braid.py index 36c17dad..cc81bb26 100644 --- a/strategy/generator/pulse/braid.py +++ b/strategy/generator/pulse/braid.py @@ -12,7 +12,7 @@ @dataclass(frozen=True) class BraidPulse(Pulse): type: PulseType = PulseType.Braid - smooth_type: Parameter = StaticParameter(Smooth.LSMA) + smooth_type: Parameter = StaticParameter(Smooth.WMA) fast_period: Parameter = StaticParameter(3.0) slow_period: Parameter = StaticParameter(14.0) open_period: Parameter = StaticParameter(7.0) diff --git a/strategy/generator/pulse/wae.py b/strategy/generator/pulse/wae.py index 99d136c2..3638ef2a 100644 --- a/strategy/generator/pulse/wae.py +++ b/strategy/generator/pulse/wae.py @@ -10,10 +10,10 @@ class WaePulse(Pulse): type: PulseType = PulseType.Wae smooth_type: Parameter = StaticParameter(Smooth.EMA) - fast_period: Parameter = StaticParameter(20.0) - slow_period: Parameter = StaticParameter(40.0) + fast_period: Parameter = StaticParameter(15.0) + slow_period: Parameter = StaticParameter(30.0) smooth_bb: Parameter = StaticParameter(Smooth.SMA) - bb_period: Parameter = StaticParameter(20.0) + bb_period: Parameter = StaticParameter(15.0) factor: Parameter = StaticParameter(2.0) strength: Parameter = StaticParameter(150.0) atr_period: Parameter = StaticParameter(100.0) diff --git a/strategy/generator/signal/bb/macd_bb.py b/strategy/generator/signal/bb/macd_bb.py index b8eed39f..817185f4 100644 --- a/strategy/generator/signal/bb/macd_bb.py +++ b/strategy/generator/signal/bb/macd_bb.py @@ -15,5 +15,6 @@ class MacdBbSignal(Signal): fast_period: Parameter = StaticParameter(8.0) slow_period: Parameter = StaticParameter(26.0) signal_period: Parameter = StaticParameter(9.0) + bb_smooth: Parameter = StaticParameter(Smooth.SMA) bb_period: Parameter = StaticParameter(9.0) factor: Parameter = StaticParameter(0.8) diff --git a/strategy/generator/signal/bb/vwap_bb.py b/strategy/generator/signal/bb/vwap_bb.py index bf43208c..db62aef7 100644 --- a/strategy/generator/signal/bb/vwap_bb.py +++ b/strategy/generator/signal/bb/vwap_bb.py @@ -9,6 +9,6 @@ class VwapBbSignal(Signal): type: SignalType = SignalType.VwapBb period: Parameter = StaticParameter(100.0) - smooth_type: Parameter = StaticParameter(Smooth.EMA) + bb_smooth: Parameter = StaticParameter(Smooth.EMA) bb_period: Parameter = StaticParameter(50.0) factor: Parameter = StaticParameter(2.0) diff --git a/ta_lib/strategies/signal/src/bb/macd_bb.rs b/ta_lib/strategies/signal/src/bb/macd_bb.rs index 7b4bf20b..f939e03a 100644 --- a/ta_lib/strategies/signal/src/bb/macd_bb.rs +++ b/ta_lib/strategies/signal/src/bb/macd_bb.rs @@ -8,6 +8,7 @@ pub struct MacdBbSignal { fast_period: usize, slow_period: usize, signal_period: usize, + bb_smooth: Smooth, bb_period: usize, factor: f32, } @@ -18,6 +19,7 @@ impl MacdBbSignal { fast_period: f32, slow_period: f32, signal_period: f32, + bb_smooth: Smooth, bb_period: f32, factor: f32, ) -> Self { @@ -26,6 +28,7 @@ impl MacdBbSignal { fast_period: fast_period as usize, slow_period: slow_period as usize, signal_period: signal_period as usize, + bb_smooth, bb_period: bb_period as usize, factor, } @@ -48,7 +51,7 @@ impl Signal for MacdBbSignal { self.signal_period, ); - let (upper_bb, _, lower_bb) = bb(&macd_line, self.smooth_type, self.bb_period, self.factor); + let (upper_bb, _, lower_bb) = bb(&macd_line, self.bb_smooth, self.bb_period, self.factor); ( macd_line.cross_over(&upper_bb), diff --git a/ta_lib/strategies/signal/src/bb/vwap_bb.rs b/ta_lib/strategies/signal/src/bb/vwap_bb.rs index f199276b..705efa7a 100644 --- a/ta_lib/strategies/signal/src/bb/vwap_bb.rs +++ b/ta_lib/strategies/signal/src/bb/vwap_bb.rs @@ -5,16 +5,16 @@ use volume::vwap; pub struct VwapBbSignal { period: usize, - smooth_type: Smooth, + bb_smooth: Smooth, bb_period: usize, factor: f32, } impl VwapBbSignal { - pub fn new(period: f32, smooth_type: Smooth, bb_period: f32, factor: f32) -> Self { + pub fn new(period: f32, bb_smooth: Smooth, bb_period: f32, factor: f32) -> Self { Self { period: period as usize, - smooth_type, + bb_smooth, bb_period: bb_period as usize, factor, } @@ -28,7 +28,7 @@ impl Signal for VwapBbSignal { fn generate(&self, data: &OHLCVSeries) -> (Series, Series) { let vwap = vwap(&data.hlc3(), &data.volume); - let (upper_bb, _, lower_bb) = bb(&vwap, self.smooth_type, self.bb_period, self.factor); + let (upper_bb, _, lower_bb) = bb(&vwap, self.bb_smooth, self.bb_period, self.factor); (vwap.cross_over(&upper_bb), vwap.cross_under(&lower_bb)) } diff --git a/ta_lib/strategies/trend_follow/src/config/signal_config.rs b/ta_lib/strategies/trend_follow/src/config/signal_config.rs index 700a60fa..a9422d4a 100644 --- a/ta_lib/strategies/trend_follow/src/config/signal_config.rs +++ b/ta_lib/strategies/trend_follow/src/config/signal_config.rs @@ -116,12 +116,13 @@ pub enum SignalConfig { fast_period: f32, slow_period: f32, signal_period: f32, + bb_smooth: f32, bb_period: f32, factor: f32, }, VwapBb { period: f32, - smooth_type: f32, + bb_smooth: f32, bb_period: f32, factor: f32, }, diff --git a/ta_lib/strategies/trend_follow/src/mapper/signal_mapper.rs b/ta_lib/strategies/trend_follow/src/mapper/signal_mapper.rs index 0ae18bda..1d18f4f4 100644 --- a/ta_lib/strategies/trend_follow/src/mapper/signal_mapper.rs +++ b/ta_lib/strategies/trend_follow/src/mapper/signal_mapper.rs @@ -237,6 +237,7 @@ pub fn map_to_signal(config: SignalConfig) -> Box { fast_period, slow_period, signal_period, + bb_smooth, bb_period, factor, } => Box::new(MacdBbSignal::new( @@ -244,17 +245,18 @@ pub fn map_to_signal(config: SignalConfig) -> Box { fast_period, slow_period, signal_period, + smooth_deserialize(bb_smooth as usize), bb_period, factor, )), SignalConfig::VwapBb { period, - smooth_type, + bb_smooth, bb_period, factor, } => Box::new(VwapBbSignal::new( period, - smooth_deserialize(smooth_type as usize), + smooth_deserialize(bb_smooth as usize), bb_period, factor, )),