diff --git a/core/models/position_risk.py b/core/models/position_risk.py index bd2bbcd5..c1cad5c7 100644 --- a/core/models/position_risk.py +++ b/core/models/position_risk.py @@ -123,13 +123,16 @@ def _ats(closes: List[float], atr: List[float]) -> List[float]: return stop_prices +OHLCV_SIZE = 200 + + @dataclass(frozen=True) class PositionRisk(TaMixin): model: SGDRegressor scaler: StandardScaler ohlcv: List[OHLCV] = field(default_factory=list) type: PositionRiskType = PositionRiskType.NONE - trail_factor: float = field(default_factory=lambda: np.random.uniform(1.8, 2.2)) + trail_factor: float = field(default_factory=lambda: np.random.uniform(1.1, 1.8)) @property def curr_bar(self): @@ -246,7 +249,7 @@ def forecast(self, steps: int = 3): return predictions def next(self, bar: OHLCV): - ohlcv = self.ohlcv + [bar] + ohlcv = (self.ohlcv + [bar])[-OHLCV_SIZE:] ohlcv.sort(key=lambda x: x.timestamp) return replace(self, ohlcv=ohlcv)