1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-01 18:11:18 +08:00

Update training setting.

This commit is contained in:
lwwang1995
2020-11-27 10:09:17 +08:00
parent 13c2c41d23
commit 6fb19eb58d
11 changed files with 91 additions and 50 deletions

View File

@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
@@ -37,7 +51,7 @@ task:
lr: 1e-3
early_stop: 20
batch_size: 800
metric: IC
metric: loss
loss: mse
seed: 0
GPU: 0
@@ -47,7 +61,7 @@ task:
module_path: qlib.data.dataset
kwargs:
handler:
class: ALPHA360_Denoise
class: ALPHA360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:

View File

@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
@@ -37,7 +51,7 @@ task:
lr: 1e-3
early_stop: 20
batch_size: 800
metric: IC
metric: loss
loss: mse
seed: 0
GPU: 0
@@ -46,7 +60,7 @@ task:
module_path: qlib.data.dataset
kwargs:
handler:
class: ALPHA360_Denoise
class: ALPHA360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:

View File

@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
@@ -36,7 +50,7 @@ task:
n_epochs: 200
lr: 1e-3
early_stop: 20
metric: IC
metric: loss
loss: mse
base_model: GRU
seed: 0
@@ -46,7 +60,7 @@ task:
module_path: qlib.data.dataset
kwargs:
handler:
class: ALPHA360_Denoise
class: ALPHA360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:

View File

@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
@@ -37,7 +51,7 @@ task:
lr: 1e-3
early_stop: 20
batch_size: 800
metric: IC
metric: loss
loss: mse
seed: 0
GPU: 0
@@ -46,7 +60,7 @@ task:
module_path: qlib.data.dataset
kwargs:
handler:
class: ALPHA360_Denoise
class: ALPHA360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:

View File

@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
@@ -51,7 +65,7 @@ task:
module_path: qlib.data.dataset
kwargs:
handler:
class: ALPHA360_Denoise
class: ALPHA360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:

View File

@@ -44,7 +44,7 @@ class ALSTM(Model):
dropout=0.0,
n_epochs=200,
lr=0.001,
metric="IC",
metric="",
batch_size=2000,
early_stop=20,
loss="mse",
@@ -142,21 +142,16 @@ class ALSTM(Model):
def metric_fn(self, pred, label):
mask = torch.isfinite(label)
if self.metric == "IC":
return self.cal_ic(pred[mask], label[mask])
if self.metric == "" or self.metric == "loss": # use loss
return -self.loss_fn(pred[mask], label[mask])
raise ValueError("unknown metric `%s`" % self.metric)
def cal_ic(self, pred, label):
return torch.mean(pred * label)
def train_epoch(self, x_train, y_train):
x_train_values = x_train.values
y_train_values = np.squeeze(y_train.values) * 100
y_train_values = np.squeeze(y_train.values)
self.alstm_model.train()

View File

@@ -43,13 +43,13 @@ class GAT(Model):
d_feat=6,
hidden_size=64,
num_layers=2,
dropout=0.7,
dropout=0.0,
n_epochs=200,
lr=0.0001,
metric="loss",
lr=0.001,
metric="",
early_stop=20,
loss="mse",
base_model="LSTM",
base_model="GRU",
with_pretrain=True,
optimizer="adam",
GPU="0",
@@ -148,17 +148,12 @@ class GAT(Model):
def metric_fn(self, pred, label):
mask = torch.isfinite(label)
if self.metric == "IC":
return self.cal_ic(pred[mask], label[mask])
if self.metric == "" or self.metric == "loss": # use loss
return -self.loss_fn(pred[mask], label[mask])
raise ValueError("unknown metric `%s`" % self.metric)
def cal_ic(self, pred, label):
return torch.mean(pred * label)
def get_daily_inter(self, df, shuffle=False):
# organize the train data into daily inter as daily batches
daily_count = df.groupby(level=0).size().values

View File

@@ -146,6 +146,7 @@ class GRU(Model):
raise ValueError("unknown metric `%s`" % self.metric)
def train_epoch(self, x_train, y_train):
x_train_values = x_train.values

View File

@@ -52,11 +52,11 @@ class HATS(Model):
num_layers=2,
dropout=0.5,
n_epochs=200,
lr=0.0001,
metric="loss",
lr=0.01,
metric="",
early_stop=20,
loss="mse",
base_model="LSTM",
base_model="GRU",
with_pretrain=True,
optimizer="adam",
GPU="0",
@@ -154,17 +154,12 @@ class HATS(Model):
def metric_fn(self, pred, label):
mask = torch.isfinite(label)
if self.metric == "IC":
return self.cal_ic(pred[mask], label[mask])
if self.metric == "" or self.metric == "loss": # use loss
return -self.loss_fn(pred[mask], label[mask])
raise ValueError("unknown metric `%s`" % self.metric)
def cal_ic(self, pred, label):
return torch.mean(pred * label)
def get_daily_inter(self, df, shuffle=False):
# organize the train data into daily inter as daily batches
daily_count = df.groupby(level=0).size().values

View File

@@ -46,7 +46,7 @@ class LSTM(Model):
dropout=0.0,
n_epochs=200,
lr=0.001,
metric="loss",
metric="",
batch_size=2000,
early_stop=20,
loss="mse",
@@ -140,16 +140,12 @@ class LSTM(Model):
def metric_fn(self, pred, label):
mask = torch.isfinite(label)
if self.metric == "IC":
return self.cal_ic(pred[mask], label[mask])
if self.metric == "" or self.metric == "loss": # use loss
return -self.loss_fn(pred[mask], label[mask])
raise ValueError("unknown metric `%s`" % self.metric)
def cal_ic(self, pred, label):
return torch.mean(pred * label)
def train_epoch(self, x_train, y_train):
@@ -193,7 +189,6 @@ class LSTM(Model):
losses = []
indices = np.arange(len(x_values))
np.random.shuffle(indices)
for i in range(len(indices))[:: self.batch_size]:

View File

@@ -102,7 +102,7 @@ class SFM_Model(nn.Module):
i = self.inner_activation(
x_i + torch.matmul(h_tm1 * B_U[0], self.U_i)
)
) # not sure whether I am doing in the right unsquuze
ste = self.inner_activation(x_ste + torch.matmul(h_tm1 * B_U[0], self.U_ste))
fre = self.inner_activation(x_fre + torch.matmul(h_tm1 * B_U[0], self.U_fre))
@@ -283,10 +283,6 @@ class SFM(Model):
)
)
if loss not in {"mse", "binary"}:
raise NotImplementedError("loss {} is not supported!".format(loss))
self._scorer = mean_squared_error if loss == "mse" else roc_auc_score
self.sfm_model = SFM_Model(
d_feat=self.d_feat,
output_dim=self.output_dim,
@@ -318,7 +314,6 @@ class SFM(Model):
losses = []
indices = np.arange(len(x_values))
np.random.shuffle(indices)
for i in range(len(indices))[:: self.batch_size]:
@@ -428,17 +423,12 @@ class SFM(Model):
def metric_fn(self, pred, label):
mask = torch.isfinite(label)
if self.metric == "IC":
return self.cal_ic(pred[mask], label[mask])
if self.metric == "" or self.metric == "loss": # use loss
return -self.loss_fn(pred[mask], label[mask])
raise ValueError("unknown metric `%s`" % self.metric)
def cal_ic(self, pred, label):
return torch.mean(pred * label)
def predict(self, dataset):
if not self._fitted:
raise ValueError("model is not fitted yet!")