-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,8 @@ pub enum ConfirmConfig { | |
k_period: f32, | ||
d_period: f32, | ||
}, | ||
Vi { | ||
atr_period: f32, | ||
period: f32, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters