Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Sep 14, 2024
1 parent e017398 commit b129f47
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/models/position_risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b129f47

Please sign in to comment.