mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-06 14:01:28 +08:00
* Intermediate version * Fix yaml template & Successfully run rolling * Be compatible with benchmark * Get same results with previous linear model * Black formatting * Update black * Update the placeholder mechanism * Update CI * Update CI * Upgrade Black * Fix CI and simplify code * Fix CI * Move the data processing caching mechanism into utils. * Adjusting DDG-DA * Organize import
49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
import qlib
|
|
import optuna
|
|
from qlib.constant import REG_CN
|
|
from qlib.utils import init_instance_by_config
|
|
from qlib.tests.data import GetData
|
|
from qlib.tests.config import get_dataset_config, CSI300_MARKET, DATASET_ALPHA360_CLASS
|
|
|
|
DATASET_CONFIG = get_dataset_config(market=CSI300_MARKET, dataset_class=DATASET_ALPHA360_CLASS)
|
|
|
|
|
|
def objective(trial):
|
|
task = {
|
|
"model": {
|
|
"class": "LGBModel",
|
|
"module_path": "qlib.contrib.model.gbdt",
|
|
"kwargs": {
|
|
"loss": "mse",
|
|
"colsample_bytree": trial.suggest_uniform("colsample_bytree", 0.5, 1),
|
|
"learning_rate": trial.suggest_uniform("learning_rate", 0, 1),
|
|
"subsample": trial.suggest_uniform("subsample", 0, 1),
|
|
"lambda_l1": trial.suggest_loguniform("lambda_l1", 1e-8, 1e4),
|
|
"lambda_l2": trial.suggest_loguniform("lambda_l2", 1e-8, 1e4),
|
|
"max_depth": 10,
|
|
"num_leaves": trial.suggest_int("num_leaves", 1, 1024),
|
|
"feature_fraction": trial.suggest_uniform("feature_fraction", 0.4, 1.0),
|
|
"bagging_fraction": trial.suggest_uniform("bagging_fraction", 0.4, 1.0),
|
|
"bagging_freq": trial.suggest_int("bagging_freq", 1, 7),
|
|
"min_data_in_leaf": trial.suggest_int("min_data_in_leaf", 1, 50),
|
|
"min_child_samples": trial.suggest_int("min_child_samples", 5, 100),
|
|
},
|
|
},
|
|
}
|
|
|
|
evals_result = dict()
|
|
model = init_instance_by_config(task["model"])
|
|
model.fit(dataset, evals_result=evals_result)
|
|
return min(evals_result["valid"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
provider_uri = "~/.qlib/qlib_data/cn_data"
|
|
GetData().qlib_data(target_dir=provider_uri, region=REG_CN, exists_skip=True)
|
|
qlib.init(provider_uri=provider_uri, region=REG_CN)
|
|
|
|
dataset = init_instance_by_config(DATASET_CONFIG)
|
|
|
|
study = optuna.Study(study_name="LGBM_360", storage="sqlite:///db.sqlite3")
|
|
study.optimize(objective, n_jobs=6)
|