feat(Core): added the first classification model & the feature necessary (#4)

* feat(Core): added the first classification model & the feature necessary

* feat(Models): added basic transformers model
This commit is contained in:
Mark Aron Szulyovszky
2021-11-16 10:02:02 +01:00
committed by GitHub
parent 797791d2f4
commit 1d6eed3a94
6 changed files with 300 additions and 6 deletions
+25
View File
@@ -65,4 +65,29 @@ def __load_df(path: str, prefix: str, add_features: bool, log_returns: bool, nar
def create_target_cum_forward_returns(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
df['target'] = df[source_column].diff(period).shift(-period)
df = df.iloc[:-period]
return df
#%%
def create_target_pos_neg_classes(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
df['target'] = df[source_column].diff(period).shift(-period)
df['target'] = df['target'].map(lambda x: 0 if x <= 0.0 else 1)
df = df.iloc[:-period]
return df
def create_target_four_classes(df: pd.DataFrame, source_column: str, period: int) -> pd.DataFrame:
def __get_class(x):
treshold = 0.08
if x <= -treshold:
return 0
elif x > -treshold and x <= 0:
return 1
elif x > 0 and x <= treshold:
return 2
else:
return 3
df['target'] = df[source_column].diff(period).shift(-period)
df['target'] = df['target'].map(__get_class)
df = df.iloc[:-period]
return df