Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 15, 2024
1 parent ed3687e commit f6fab54
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion strategy/generator/bootstrap/_trend_follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from strategy.generator.confirm.rsi_neutrality import RsiNeutralityConfirm
from strategy.generator.confirm.rsi_signalline import RsiSignalLineConfirm
from strategy.generator.confirm.stc import StcConfirm
from strategy.generator.confirm.vi import ViConfirm
from strategy.generator.exit.ast import AstExit
from strategy.generator.exit.cci import CciExit
from strategy.generator.exit.highlow import HighLowExit
Expand All @@ -43,6 +44,7 @@
from strategy.generator.signal.flip.supertrend_flip import SupertrendFlipSignal
from strategy.generator.signal.ma.ma2_rsi import Ma2RsiSignal
from strategy.generator.signal.ma.ma3_cross import Ma3CrossSignal
from strategy.generator.signal.ma.ma_cross import MaCrossSignal
from strategy.generator.signal.ma.ma_testing_ground import MaTestingGroundSignal
from strategy.generator.signal.ma.vwap_cross import VwapCrossSignal
from strategy.generator.signal.neutrality.dso_neutrality_cross import (
Expand Down Expand Up @@ -181,6 +183,7 @@ def _generate_strategy(self):
StcConfirm(),
DsoConfirm(),
CciConfirm(),
ViConfirm(),
]
)
pulse = np.random.choice(
Expand Down Expand Up @@ -374,7 +377,7 @@ def _generate_signal(self, signal: TrendSignalType):
MaTestingGroundSignal(),
# MaQuadrupleSignal(),
# MaSurpassSignal(),
# MaCrossSignal(),
MaCrossSignal(),
]
)
if signal == TrendSignalType.BREAKOUT:
Expand Down
1 change: 1 addition & 0 deletions strategy/generator/confirm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ConfirmType(Enum):
RsiSignalLine = "RsiSignalLine"
RsiNeutrality = "RsiNeutrality"
Stc = "Stc"
Vi = "Vi"

def __str__(self):
return self.value.upper()
Expand Down
11 changes: 11 additions & 0 deletions strategy/generator/confirm/vi.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 strategy.generator.confirm.base import Confirm, ConfirmType


@dataclass(frozen=True)
class ViConfirm(Confirm):
type: ConfirmType = ConfirmType.Vi
atr_period: Parameter = StaticParameter(1.0)
period: Parameter = StaticParameter(14.0)
34 changes: 34 additions & 0 deletions ta_lib/strategies/confirm/src/vi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use base::prelude::*;
use core::prelude::*;
use trend::vi;

pub struct ViConfirm {
atr_period: usize,
period: usize,
}

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

impl Confirm for ViConfirm {
fn lookback(&self) -> usize {
std::cmp::max(self.atr_period, self.period)
}

fn validate(&self, data: &OHLCVSeries) -> (Series<bool>, Series<bool>) {
let (vip, vim) = vi(
&data.high,
&data.low,
&data.atr(self.atr_period, Smooth::SMMA),
self.period,
);

(vip.sgt(&vim), vip.slt(&vim))
}
}
4 changes: 4 additions & 0 deletions ta_lib/strategies/trend_follow/src/config/confirm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ pub enum ConfirmConfig {
k_period: f32,
d_period: f32,
},
Vi {
atr_period: f32,
period: f32,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub fn map_to_confirm(config: ConfirmConfig) -> Box<dyn Confirm> {
threshold,
)),
ConfirmConfig::Roc { period } => Box::new(RocConfirm::new(period)),
ConfirmConfig::Vi { atr_period, period } => Box::new(ViConfirm::new(atr_period, period)),
ConfirmConfig::Stc {
smooth_type,
fast_period,
Expand Down

0 comments on commit f6fab54

Please sign in to comment.