2022-01-04 11:44:35 +01:00
|
|
|
from __future__ import annotations
|
2021-12-21 10:30:09 +01:00
|
|
|
import numpy as np
|
2022-02-17 16:36:35 +01:00
|
|
|
from .base import Model
|
|
|
|
|
from sklearn.base import BaseEstimator, ClassifierMixin
|
2021-12-21 10:30:09 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
class StaticMomentumModel(BaseEstimator, ClassifierMixin, Model):
|
2021-12-21 10:30:09 +01:00
|
|
|
'''
|
|
|
|
|
Model that uses only one feature: momentum. It's positive if momentum is greater than 0, otherwise it's negative.
|
|
|
|
|
'''
|
|
|
|
|
|
2022-01-12 23:22:55 +01:00
|
|
|
data_transformation = 'original'
|
2021-12-21 10:30:09 +01:00
|
|
|
only_column = 'mom'
|
2022-01-04 11:44:35 +01:00
|
|
|
predict_window_size = 'single_timestamp'
|
2021-12-21 10:30:09 +01:00
|
|
|
|
|
|
|
|
def __init__(self, allow_short: bool) -> None:
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.allow_short = allow_short
|
|
|
|
|
|
2022-01-04 11:44:35 +01:00
|
|
|
def fit(self, X: np.ndarray, y: np.ndarray) -> None:
|
2021-12-21 10:30:09 +01:00
|
|
|
# This is a static model, it can' learn anything
|
|
|
|
|
pass
|
|
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
def predict(self, X) -> np.ndarray:
|
2021-12-21 10:30:09 +01:00
|
|
|
negative_class = -1.0 if self.allow_short == True else 0.0
|
|
|
|
|
prediction = 1.0 if X[-1][0] > 0 else negative_class
|
2022-02-17 16:36:35 +01:00
|
|
|
return np.array(prediction)
|
|
|
|
|
|
|
|
|
|
def predict_proba(self, X) -> np.ndarray:
|
|
|
|
|
return np.array([])
|