Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 22, 2024
1 parent 16634c3 commit d2b0ea3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
7 changes: 5 additions & 2 deletions strategy/generator/bootstrap/_trend_follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
from strategy.generator.signal.neutrality.rsi_neutrality_rejection import (
RsiNautralityRejectionSignal,
)
from strategy.generator.signal.neutrality.tii_neutrality_cross import TiiNeutralityCrossSignal
from strategy.generator.signal.neutrality.tii_neutrality_cross import (
TiiNeutralityCrossSignal,
)
from strategy.generator.signal.pattern.ao_saucer import AoSaucerSignal
from strategy.generator.signal.pattern.candle_trend import CandlestickTrendSignal
from strategy.generator.signal.pattern.hl import HighLowSignal
Expand Down Expand Up @@ -90,6 +92,7 @@
from strategy.generator.signal.zerocross.trix_zerocross import TrixZeroCrossSignal
from strategy.generator.signal.zerocross.tsi_zerocross import TsiZeroCrossSignal
from strategy.generator.stop_loss.atr import AtrStopLoss
from strategy.generator.stop_loss.dch import DchStopLoss


class TrendSignalType(Enum):
Expand Down Expand Up @@ -197,7 +200,7 @@ def _generate_strategy(self):
WaePulse(),
]
)
stop_loss = np.random.choice([AtrStopLoss()])
stop_loss = np.random.choice([AtrStopLoss(), DchStopLoss()])
exit_signal = np.random.choice(
[
# AstExit(),
Expand Down
1 change: 1 addition & 0 deletions strategy/generator/stop_loss/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class StopLossType(Enum):
Atr = "Atr"
Dch = "Dch"

def __str__(self):
return self.value.upper()
Expand Down
11 changes: 11 additions & 0 deletions strategy/generator/stop_loss/dch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import dataclass

from core.models.parameter import Parameter, StaticParameter

from .base import StopLoss, StopLossType


@dataclass(frozen=True)
class DchStopLoss(StopLoss):
type: StopLossType = StopLossType.Dch
period: Parameter = StaticParameter(21.0)
27 changes: 27 additions & 0 deletions ta_lib/strategies/stop_loss/src/dch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use base::prelude::*;
use core::prelude::*;
use volatility::dch;

pub struct DchStopLoss {
period: usize,
}

impl DchStopLoss {
pub fn new(period: f32) -> Self {
Self {
period: period as usize,
}
}
}

impl StopLoss for DchStopLoss {
fn lookback(&self) -> usize {
self.period
}

fn find(&self, data: &OHLCVSeries) -> (Series<f32>, Series<f32>) {
let (upper, _, lower) = dch(&data.high, &data.low, self.period);

(lower, upper)
}
}
2 changes: 2 additions & 0 deletions ta_lib/strategies/stop_loss/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod atr;
mod dch;

pub use atr::AtrStopLoss;
pub use dch::DchStopLoss;
3 changes: 3 additions & 0 deletions ta_lib/strategies/trend_follow/src/config/stoploss_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ pub enum StopLossConfig {
period: f32,
factor: f32,
},
Dch {
period: f32,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ pub fn map_to_stoploss(config: StopLossConfig) -> Box<dyn StopLoss> {
period,
factor,
)),
StopLossConfig::Dch { period } => Box::new(DchStopLoss::new(period)),
}
}

0 comments on commit d2b0ea3

Please sign in to comment.