mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 23:36:54 +08:00
Update training setting.
This commit is contained in:
@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
|
|||||||
fit_start_time: 2008-01-01
|
fit_start_time: 2008-01-01
|
||||||
fit_end_time: 2014-12-31
|
fit_end_time: 2014-12-31
|
||||||
instruments: *market
|
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
|
port_analysis_config: &port_analysis_config
|
||||||
strategy:
|
strategy:
|
||||||
class: TopkDropoutStrategy
|
class: TopkDropoutStrategy
|
||||||
@@ -37,7 +51,7 @@ task:
|
|||||||
lr: 1e-3
|
lr: 1e-3
|
||||||
early_stop: 20
|
early_stop: 20
|
||||||
batch_size: 800
|
batch_size: 800
|
||||||
metric: IC
|
metric: loss
|
||||||
loss: mse
|
loss: mse
|
||||||
seed: 0
|
seed: 0
|
||||||
GPU: 0
|
GPU: 0
|
||||||
@@ -47,7 +61,7 @@ task:
|
|||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
kwargs:
|
kwargs:
|
||||||
handler:
|
handler:
|
||||||
class: ALPHA360_Denoise
|
class: ALPHA360
|
||||||
module_path: qlib.contrib.data.handler
|
module_path: qlib.contrib.data.handler
|
||||||
kwargs: *data_handler_config
|
kwargs: *data_handler_config
|
||||||
segments:
|
segments:
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
|
|||||||
fit_start_time: 2008-01-01
|
fit_start_time: 2008-01-01
|
||||||
fit_end_time: 2014-12-31
|
fit_end_time: 2014-12-31
|
||||||
instruments: *market
|
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
|
port_analysis_config: &port_analysis_config
|
||||||
strategy:
|
strategy:
|
||||||
class: TopkDropoutStrategy
|
class: TopkDropoutStrategy
|
||||||
@@ -37,7 +51,7 @@ task:
|
|||||||
lr: 1e-3
|
lr: 1e-3
|
||||||
early_stop: 20
|
early_stop: 20
|
||||||
batch_size: 800
|
batch_size: 800
|
||||||
metric: IC
|
metric: loss
|
||||||
loss: mse
|
loss: mse
|
||||||
seed: 0
|
seed: 0
|
||||||
GPU: 0
|
GPU: 0
|
||||||
@@ -46,7 +60,7 @@ task:
|
|||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
kwargs:
|
kwargs:
|
||||||
handler:
|
handler:
|
||||||
class: ALPHA360_Denoise
|
class: ALPHA360
|
||||||
module_path: qlib.contrib.data.handler
|
module_path: qlib.contrib.data.handler
|
||||||
kwargs: *data_handler_config
|
kwargs: *data_handler_config
|
||||||
segments:
|
segments:
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
|
|||||||
fit_start_time: 2008-01-01
|
fit_start_time: 2008-01-01
|
||||||
fit_end_time: 2014-12-31
|
fit_end_time: 2014-12-31
|
||||||
instruments: *market
|
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
|
port_analysis_config: &port_analysis_config
|
||||||
strategy:
|
strategy:
|
||||||
class: TopkDropoutStrategy
|
class: TopkDropoutStrategy
|
||||||
@@ -36,7 +50,7 @@ task:
|
|||||||
n_epochs: 200
|
n_epochs: 200
|
||||||
lr: 1e-3
|
lr: 1e-3
|
||||||
early_stop: 20
|
early_stop: 20
|
||||||
metric: IC
|
metric: loss
|
||||||
loss: mse
|
loss: mse
|
||||||
base_model: GRU
|
base_model: GRU
|
||||||
seed: 0
|
seed: 0
|
||||||
@@ -46,7 +60,7 @@ task:
|
|||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
kwargs:
|
kwargs:
|
||||||
handler:
|
handler:
|
||||||
class: ALPHA360_Denoise
|
class: ALPHA360
|
||||||
module_path: qlib.contrib.data.handler
|
module_path: qlib.contrib.data.handler
|
||||||
kwargs: *data_handler_config
|
kwargs: *data_handler_config
|
||||||
segments:
|
segments:
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
|
|||||||
fit_start_time: 2008-01-01
|
fit_start_time: 2008-01-01
|
||||||
fit_end_time: 2014-12-31
|
fit_end_time: 2014-12-31
|
||||||
instruments: *market
|
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
|
port_analysis_config: &port_analysis_config
|
||||||
strategy:
|
strategy:
|
||||||
class: TopkDropoutStrategy
|
class: TopkDropoutStrategy
|
||||||
@@ -37,7 +51,7 @@ task:
|
|||||||
lr: 1e-3
|
lr: 1e-3
|
||||||
early_stop: 20
|
early_stop: 20
|
||||||
batch_size: 800
|
batch_size: 800
|
||||||
metric: IC
|
metric: loss
|
||||||
loss: mse
|
loss: mse
|
||||||
seed: 0
|
seed: 0
|
||||||
GPU: 0
|
GPU: 0
|
||||||
@@ -46,7 +60,7 @@ task:
|
|||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
kwargs:
|
kwargs:
|
||||||
handler:
|
handler:
|
||||||
class: ALPHA360_Denoise
|
class: ALPHA360
|
||||||
module_path: qlib.contrib.data.handler
|
module_path: qlib.contrib.data.handler
|
||||||
kwargs: *data_handler_config
|
kwargs: *data_handler_config
|
||||||
segments:
|
segments:
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ data_handler_config: &data_handler_config
|
|||||||
fit_start_time: 2008-01-01
|
fit_start_time: 2008-01-01
|
||||||
fit_end_time: 2014-12-31
|
fit_end_time: 2014-12-31
|
||||||
instruments: *market
|
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
|
port_analysis_config: &port_analysis_config
|
||||||
strategy:
|
strategy:
|
||||||
class: TopkDropoutStrategy
|
class: TopkDropoutStrategy
|
||||||
@@ -51,7 +65,7 @@ task:
|
|||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
kwargs:
|
kwargs:
|
||||||
handler:
|
handler:
|
||||||
class: ALPHA360_Denoise
|
class: ALPHA360
|
||||||
module_path: qlib.contrib.data.handler
|
module_path: qlib.contrib.data.handler
|
||||||
kwargs: *data_handler_config
|
kwargs: *data_handler_config
|
||||||
segments:
|
segments:
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class ALSTM(Model):
|
|||||||
dropout=0.0,
|
dropout=0.0,
|
||||||
n_epochs=200,
|
n_epochs=200,
|
||||||
lr=0.001,
|
lr=0.001,
|
||||||
metric="IC",
|
metric="",
|
||||||
batch_size=2000,
|
batch_size=2000,
|
||||||
early_stop=20,
|
early_stop=20,
|
||||||
loss="mse",
|
loss="mse",
|
||||||
@@ -142,21 +142,16 @@ class ALSTM(Model):
|
|||||||
|
|
||||||
def metric_fn(self, pred, label):
|
def metric_fn(self, pred, label):
|
||||||
mask = torch.isfinite(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
|
if self.metric == "" or self.metric == "loss": # use loss
|
||||||
return -self.loss_fn(pred[mask], label[mask])
|
return -self.loss_fn(pred[mask], label[mask])
|
||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
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):
|
def train_epoch(self, x_train, y_train):
|
||||||
|
|
||||||
x_train_values = x_train.values
|
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()
|
self.alstm_model.train()
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ class GAT(Model):
|
|||||||
d_feat=6,
|
d_feat=6,
|
||||||
hidden_size=64,
|
hidden_size=64,
|
||||||
num_layers=2,
|
num_layers=2,
|
||||||
dropout=0.7,
|
dropout=0.0,
|
||||||
n_epochs=200,
|
n_epochs=200,
|
||||||
lr=0.0001,
|
lr=0.001,
|
||||||
metric="loss",
|
metric="",
|
||||||
early_stop=20,
|
early_stop=20,
|
||||||
loss="mse",
|
loss="mse",
|
||||||
base_model="LSTM",
|
base_model="GRU",
|
||||||
with_pretrain=True,
|
with_pretrain=True,
|
||||||
optimizer="adam",
|
optimizer="adam",
|
||||||
GPU="0",
|
GPU="0",
|
||||||
@@ -148,17 +148,12 @@ class GAT(Model):
|
|||||||
def metric_fn(self, pred, label):
|
def metric_fn(self, pred, label):
|
||||||
|
|
||||||
mask = torch.isfinite(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
|
if self.metric == "" or self.metric == "loss": # use loss
|
||||||
return -self.loss_fn(pred[mask], label[mask])
|
return -self.loss_fn(pred[mask], label[mask])
|
||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
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):
|
def get_daily_inter(self, df, shuffle=False):
|
||||||
# organize the train data into daily inter as daily batches
|
# organize the train data into daily inter as daily batches
|
||||||
daily_count = df.groupby(level=0).size().values
|
daily_count = df.groupby(level=0).size().values
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ class GRU(Model):
|
|||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
raise ValueError("unknown metric `%s`" % self.metric)
|
||||||
|
|
||||||
|
|
||||||
def train_epoch(self, x_train, y_train):
|
def train_epoch(self, x_train, y_train):
|
||||||
|
|
||||||
x_train_values = x_train.values
|
x_train_values = x_train.values
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ class HATS(Model):
|
|||||||
num_layers=2,
|
num_layers=2,
|
||||||
dropout=0.5,
|
dropout=0.5,
|
||||||
n_epochs=200,
|
n_epochs=200,
|
||||||
lr=0.0001,
|
lr=0.01,
|
||||||
metric="loss",
|
metric="",
|
||||||
early_stop=20,
|
early_stop=20,
|
||||||
loss="mse",
|
loss="mse",
|
||||||
base_model="LSTM",
|
base_model="GRU",
|
||||||
with_pretrain=True,
|
with_pretrain=True,
|
||||||
optimizer="adam",
|
optimizer="adam",
|
||||||
GPU="0",
|
GPU="0",
|
||||||
@@ -154,17 +154,12 @@ class HATS(Model):
|
|||||||
|
|
||||||
def metric_fn(self, pred, label):
|
def metric_fn(self, pred, label):
|
||||||
mask = torch.isfinite(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
|
if self.metric == "" or self.metric == "loss": # use loss
|
||||||
return -self.loss_fn(pred[mask], label[mask])
|
return -self.loss_fn(pred[mask], label[mask])
|
||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
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):
|
def get_daily_inter(self, df, shuffle=False):
|
||||||
# organize the train data into daily inter as daily batches
|
# organize the train data into daily inter as daily batches
|
||||||
daily_count = df.groupby(level=0).size().values
|
daily_count = df.groupby(level=0).size().values
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class LSTM(Model):
|
|||||||
dropout=0.0,
|
dropout=0.0,
|
||||||
n_epochs=200,
|
n_epochs=200,
|
||||||
lr=0.001,
|
lr=0.001,
|
||||||
metric="loss",
|
metric="",
|
||||||
batch_size=2000,
|
batch_size=2000,
|
||||||
early_stop=20,
|
early_stop=20,
|
||||||
loss="mse",
|
loss="mse",
|
||||||
@@ -140,16 +140,12 @@ class LSTM(Model):
|
|||||||
def metric_fn(self, pred, label):
|
def metric_fn(self, pred, label):
|
||||||
|
|
||||||
mask = torch.isfinite(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
|
if self.metric == "" or self.metric == "loss": # use loss
|
||||||
return -self.loss_fn(pred[mask], label[mask])
|
return -self.loss_fn(pred[mask], label[mask])
|
||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
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):
|
def train_epoch(self, x_train, y_train):
|
||||||
|
|
||||||
@@ -193,7 +189,6 @@ class LSTM(Model):
|
|||||||
losses = []
|
losses = []
|
||||||
|
|
||||||
indices = np.arange(len(x_values))
|
indices = np.arange(len(x_values))
|
||||||
np.random.shuffle(indices)
|
|
||||||
|
|
||||||
for i in range(len(indices))[:: self.batch_size]:
|
for i in range(len(indices))[:: self.batch_size]:
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class SFM_Model(nn.Module):
|
|||||||
|
|
||||||
i = self.inner_activation(
|
i = self.inner_activation(
|
||||||
x_i + torch.matmul(h_tm1 * B_U[0], self.U_i)
|
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))
|
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))
|
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(
|
self.sfm_model = SFM_Model(
|
||||||
d_feat=self.d_feat,
|
d_feat=self.d_feat,
|
||||||
output_dim=self.output_dim,
|
output_dim=self.output_dim,
|
||||||
@@ -318,7 +314,6 @@ class SFM(Model):
|
|||||||
losses = []
|
losses = []
|
||||||
|
|
||||||
indices = np.arange(len(x_values))
|
indices = np.arange(len(x_values))
|
||||||
np.random.shuffle(indices)
|
|
||||||
|
|
||||||
for i in range(len(indices))[:: self.batch_size]:
|
for i in range(len(indices))[:: self.batch_size]:
|
||||||
|
|
||||||
@@ -428,17 +423,12 @@ class SFM(Model):
|
|||||||
def metric_fn(self, pred, label):
|
def metric_fn(self, pred, label):
|
||||||
|
|
||||||
mask = torch.isfinite(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
|
if self.metric == "" or self.metric == "loss": # use loss
|
||||||
return -self.loss_fn(pred[mask], label[mask])
|
return -self.loss_fn(pred[mask], label[mask])
|
||||||
|
|
||||||
raise ValueError("unknown metric `%s`" % self.metric)
|
raise ValueError("unknown metric `%s`" % self.metric)
|
||||||
|
|
||||||
def cal_ic(self, pred, label):
|
|
||||||
return torch.mean(pred * label)
|
|
||||||
|
|
||||||
def predict(self, dataset):
|
def predict(self, dataset):
|
||||||
if not self._fitted:
|
if not self._fitted:
|
||||||
raise ValueError("model is not fitted yet!")
|
raise ValueError("model is not fitted yet!")
|
||||||
|
|||||||
Reference in New Issue
Block a user