-
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
7 changed files
with
50 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
class StopLossType(Enum): | ||
Atr = "Atr" | ||
Dch = "Dch" | ||
|
||
def __str__(self): | ||
return self.value.upper() | ||
|
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 .base import StopLoss, StopLossType | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DchStopLoss(StopLoss): | ||
type: StopLossType = StopLossType.Dch | ||
period: Parameter = StaticParameter(21.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,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) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod atr; | ||
mod dch; | ||
|
||
pub use atr::AtrStopLoss; | ||
pub use dch::DchStopLoss; |
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 |
---|---|---|
|
@@ -8,4 +8,7 @@ pub enum StopLossConfig { | |
period: f32, | ||
factor: f32, | ||
}, | ||
Dch { | ||
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