Showing preview only (3,367K chars total). Download the full file or copy to clipboard to get everything.
Repository: microsoft/qlib
Branch: main
Commit: 3097dcc9953b
Files: 571
Total size: 3.1 MB
Directory structure:
gitextract_o4krgpl4/
├── .commitlintrc.js
├── .deepsource.toml
├── .dockerignore
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug-report.md
│ │ ├── documentation.md
│ │ ├── feature-request.md
│ │ └── question.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── brew_install.sh
│ ├── release-drafter.yml
│ └── workflows/
│ ├── lint_title.yml
│ ├── release.yml
│ ├── stale.yml
│ ├── test_qlib_from_pip.yml
│ ├── test_qlib_from_source.yml
│ └── test_qlib_from_source_slow.yml
├── .gitignore
├── .mypy.ini
├── .pre-commit-config.yaml
├── .pylintrc
├── .readthedocs.yaml
├── CHANGELOG.md
├── CHANGES.rst
├── CODE_OF_CONDUCT.md
├── Dockerfile
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── SECURITY.md
├── build_docker_image.sh
├── docs/
│ ├── FAQ/
│ │ └── FAQ.rst
│ ├── Makefile
│ ├── _static/
│ │ └── demo.sh
│ ├── advanced/
│ │ ├── PIT.rst
│ │ ├── alpha.rst
│ │ ├── serial.rst
│ │ ├── server.rst
│ │ └── task_management.rst
│ ├── changelog/
│ │ └── changelog.rst
│ ├── component/
│ │ ├── data.rst
│ │ ├── highfreq.rst
│ │ ├── meta.rst
│ │ ├── model.rst
│ │ ├── online.rst
│ │ ├── recorder.rst
│ │ ├── report.rst
│ │ ├── rl/
│ │ │ ├── framework.rst
│ │ │ ├── guidance.rst
│ │ │ ├── overall.rst
│ │ │ ├── quickstart.rst
│ │ │ └── toctree.rst
│ │ ├── strategy.rst
│ │ └── workflow.rst
│ ├── conf.py
│ ├── developer/
│ │ ├── code_standard_and_dev_guide.rst
│ │ └── how_to_build_image.rst
│ ├── hidden/
│ │ ├── client.rst
│ │ ├── online.rst
│ │ └── tuner.rst
│ ├── index.rst
│ ├── introduction/
│ │ ├── introduction.rst
│ │ └── quick.rst
│ ├── make.bat
│ ├── reference/
│ │ └── api.rst
│ ├── requirements.txt
│ └── start/
│ ├── getdata.rst
│ ├── initialization.rst
│ ├── installation.rst
│ └── integration.rst
├── examples/
│ ├── README.md
│ ├── benchmarks/
│ │ ├── ADARNN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_adarnn_Alpha360.yaml
│ │ ├── ADD/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_add_Alpha360.yaml
│ │ ├── ALSTM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_alstm_Alpha158.yaml
│ │ │ └── workflow_config_alstm_Alpha360.yaml
│ │ ├── CatBoost/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_catboost_Alpha158.yaml
│ │ │ ├── workflow_config_catboost_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_catboost_Alpha360.yaml
│ │ │ └── workflow_config_catboost_Alpha360_csi500.yaml
│ │ ├── DoubleEnsemble/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_doubleensemble_Alpha158.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha360.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha360_csi500.yaml
│ │ │ └── workflow_config_doubleensemble_early_stop_Alpha158.yaml
│ │ ├── GATs/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_gats_Alpha158.yaml
│ │ │ └── workflow_config_gats_Alpha360.yaml
│ │ ├── GRU/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_gru_Alpha158.yaml
│ │ │ └── workflow_config_gru_Alpha360.yaml
│ │ ├── GeneralPtNN/
│ │ │ ├── README.md
│ │ │ ├── workflow_config_gru.yaml
│ │ │ ├── workflow_config_gru2mlp.yaml
│ │ │ └── workflow_config_mlp.yaml
│ │ ├── HIST/
│ │ │ ├── README.md
│ │ │ ├── qlib_csi300_stock_index.npy
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_hist_Alpha360.yaml
│ │ ├── IGMTF/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_igmtf_Alpha360.yaml
│ │ ├── KRNN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_krnn_Alpha360.yaml
│ │ ├── LSTM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_lstm_Alpha158.yaml
│ │ │ └── workflow_config_lstm_Alpha360.yaml
│ │ ├── LightGBM/
│ │ │ ├── README.md
│ │ │ ├── features_resample_N.py
│ │ │ ├── features_sample.py
│ │ │ ├── multi_freq_handler.py
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_lightgbm_Alpha158.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha158_multi_freq.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha360.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha360_csi500.yaml
│ │ │ ├── workflow_config_lightgbm_configurable_dataset.yaml
│ │ │ └── workflow_config_lightgbm_multi_freq.yaml
│ │ ├── Linear/
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_linear_Alpha158.yaml
│ │ │ ├── workflow_config_linear_Alpha158_csi500.yaml
│ │ │ └── workflow_config_linear_Alpha158_multi_pass_bt.yaml
│ │ ├── Localformer/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_localformer_Alpha158.yaml
│ │ │ └── workflow_config_localformer_Alpha360.yaml
│ │ ├── MLP/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_mlp_Alpha158.yaml
│ │ │ ├── workflow_config_mlp_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_mlp_Alpha360.yaml
│ │ │ └── workflow_config_mlp_Alpha360_csi500.yaml
│ │ ├── README.md
│ │ ├── SFM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_sfm_Alpha360.yaml
│ │ ├── Sandwich/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_sandwich_Alpha360.yaml
│ │ ├── TCN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_tcn_Alpha158.yaml
│ │ │ └── workflow_config_tcn_Alpha360.yaml
│ │ ├── TCTS/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_tcts_Alpha360.yaml
│ │ ├── TFT/
│ │ │ ├── README.md
│ │ │ ├── data_formatters/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── base.py
│ │ │ │ └── qlib_Alpha158.py
│ │ │ ├── expt_settings/
│ │ │ │ ├── __init__.py
│ │ │ │ └── configs.py
│ │ │ ├── libs/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── hyperparam_opt.py
│ │ │ │ ├── tft_model.py
│ │ │ │ └── utils.py
│ │ │ ├── requirements.txt
│ │ │ ├── tft.py
│ │ │ └── workflow_config_tft_Alpha158.yaml
│ │ ├── TRA/
│ │ │ ├── README.md
│ │ │ ├── configs/
│ │ │ │ ├── config_alstm.yaml
│ │ │ │ ├── config_alstm_tra.yaml
│ │ │ │ ├── config_alstm_tra_init.yaml
│ │ │ │ ├── config_transformer.yaml
│ │ │ │ ├── config_transformer_tra.yaml
│ │ │ │ └── config_transformer_tra_init.yaml
│ │ │ ├── data/
│ │ │ │ └── README.md
│ │ │ ├── example.py
│ │ │ ├── requirements.txt
│ │ │ ├── run.sh
│ │ │ ├── src/
│ │ │ │ ├── dataset.py
│ │ │ │ └── model.py
│ │ │ ├── workflow_config_tra_Alpha158.yaml
│ │ │ ├── workflow_config_tra_Alpha158_full.yaml
│ │ │ └── workflow_config_tra_Alpha360.yaml
│ │ ├── TabNet/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_TabNet_Alpha158.yaml
│ │ │ └── workflow_config_TabNet_Alpha360.yaml
│ │ ├── Transformer/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_transformer_Alpha158.yaml
│ │ │ └── workflow_config_transformer_Alpha360.yaml
│ │ └── XGBoost/
│ │ ├── README.md
│ │ ├── requirements.txt
│ │ ├── workflow_config_xgboost_Alpha158.yaml
│ │ └── workflow_config_xgboost_Alpha360.yaml
│ ├── benchmarks_dynamic/
│ │ ├── DDG-DA/
│ │ │ ├── Makefile
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── vis_data.py
│ │ │ └── workflow.py
│ │ ├── README.md
│ │ └── baseline/
│ │ ├── README.md
│ │ ├── rolling_benchmark.py
│ │ ├── workflow_config_lightgbm_Alpha158.yaml
│ │ └── workflow_config_linear_Alpha158.yaml
│ ├── data_demo/
│ │ ├── README.md
│ │ ├── data_cache_demo.py
│ │ └── data_mem_resuse_demo.py
│ ├── highfreq/
│ │ ├── README.md
│ │ ├── highfreq_handler.py
│ │ ├── highfreq_ops.py
│ │ ├── highfreq_processor.py
│ │ ├── workflow.py
│ │ └── workflow_config_High_Freq_Tree_Alpha158.yaml
│ ├── hyperparameter/
│ │ └── LightGBM/
│ │ ├── Readme.md
│ │ ├── hyperparameter_158.py
│ │ ├── hyperparameter_360.py
│ │ └── requirements.txt
│ ├── model_interpreter/
│ │ └── feature.py
│ ├── model_rolling/
│ │ ├── requirements.txt
│ │ └── task_manager_rolling.py
│ ├── nested_decision_execution/
│ │ ├── README.md
│ │ └── workflow.py
│ ├── online_srv/
│ │ ├── online_management_simulate.py
│ │ ├── rolling_online_management.py
│ │ └── update_online_pred.py
│ ├── orderbook_data/
│ │ ├── README.md
│ │ ├── create_dataset.py
│ │ └── example.py
│ ├── portfolio/
│ │ ├── README.md
│ │ ├── config_enhanced_indexing.yaml
│ │ └── prepare_riskdata.py
│ ├── rl_order_execution/
│ │ ├── README.md
│ │ ├── exp_configs/
│ │ │ ├── backtest_opds.yml
│ │ │ ├── backtest_ppo.yml
│ │ │ ├── backtest_twap.yml
│ │ │ ├── train_opds.yml
│ │ │ └── train_ppo.yml
│ │ └── scripts/
│ │ ├── gen_pickle_data.py
│ │ ├── gen_training_orders.py
│ │ ├── merge_orders.py
│ │ └── pickle_data_config.yml
│ ├── rolling_process_data/
│ │ ├── README.md
│ │ ├── rolling_handler.py
│ │ └── workflow.py
│ ├── run_all_model.py
│ └── workflow_by_code.py
├── pyproject.toml
├── qlib/
│ ├── __init__.py
│ ├── backtest/
│ │ ├── __init__.py
│ │ ├── account.py
│ │ ├── backtest.py
│ │ ├── decision.py
│ │ ├── exchange.py
│ │ ├── executor.py
│ │ ├── high_performance_ds.py
│ │ ├── position.py
│ │ ├── profit_attribution.py
│ │ ├── report.py
│ │ ├── signal.py
│ │ └── utils.py
│ ├── cli/
│ │ ├── __init__.py
│ │ ├── data.py
│ │ └── run.py
│ ├── config.py
│ ├── constant.py
│ ├── contrib/
│ │ ├── __init__.py
│ │ ├── data/
│ │ │ ├── __init__.py
│ │ │ ├── data.py
│ │ │ ├── dataset.py
│ │ │ ├── handler.py
│ │ │ ├── highfreq_handler.py
│ │ │ ├── highfreq_processor.py
│ │ │ ├── highfreq_provider.py
│ │ │ ├── loader.py
│ │ │ ├── processor.py
│ │ │ └── utils/
│ │ │ ├── __init__.py
│ │ │ └── sepdf.py
│ │ ├── eva/
│ │ │ ├── __init__.py
│ │ │ └── alpha.py
│ │ ├── evaluate.py
│ │ ├── evaluate_portfolio.py
│ │ ├── meta/
│ │ │ ├── __init__.py
│ │ │ └── data_selection/
│ │ │ ├── __init__.py
│ │ │ ├── dataset.py
│ │ │ ├── model.py
│ │ │ ├── net.py
│ │ │ └── utils.py
│ │ ├── model/
│ │ │ ├── __init__.py
│ │ │ ├── catboost_model.py
│ │ │ ├── double_ensemble.py
│ │ │ ├── gbdt.py
│ │ │ ├── highfreq_gdbt_model.py
│ │ │ ├── linear.py
│ │ │ ├── pytorch_adarnn.py
│ │ │ ├── pytorch_add.py
│ │ │ ├── pytorch_alstm.py
│ │ │ ├── pytorch_alstm_ts.py
│ │ │ ├── pytorch_gats.py
│ │ │ ├── pytorch_gats_ts.py
│ │ │ ├── pytorch_general_nn.py
│ │ │ ├── pytorch_gru.py
│ │ │ ├── pytorch_gru_ts.py
│ │ │ ├── pytorch_hist.py
│ │ │ ├── pytorch_igmtf.py
│ │ │ ├── pytorch_krnn.py
│ │ │ ├── pytorch_localformer.py
│ │ │ ├── pytorch_localformer_ts.py
│ │ │ ├── pytorch_lstm.py
│ │ │ ├── pytorch_lstm_ts.py
│ │ │ ├── pytorch_nn.py
│ │ │ ├── pytorch_sandwich.py
│ │ │ ├── pytorch_sfm.py
│ │ │ ├── pytorch_tabnet.py
│ │ │ ├── pytorch_tcn.py
│ │ │ ├── pytorch_tcn_ts.py
│ │ │ ├── pytorch_tcts.py
│ │ │ ├── pytorch_tra.py
│ │ │ ├── pytorch_transformer.py
│ │ │ ├── pytorch_transformer_ts.py
│ │ │ ├── pytorch_utils.py
│ │ │ ├── tcn.py
│ │ │ └── xgboost.py
│ │ ├── online/
│ │ │ ├── __init__.py
│ │ │ ├── manager.py
│ │ │ ├── online_model.py
│ │ │ ├── operator.py
│ │ │ ├── user.py
│ │ │ └── utils.py
│ │ ├── ops/
│ │ │ ├── __init__.py
│ │ │ └── high_freq.py
│ │ ├── report/
│ │ │ ├── __init__.py
│ │ │ ├── analysis_model/
│ │ │ │ ├── __init__.py
│ │ │ │ └── analysis_model_performance.py
│ │ │ ├── analysis_position/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── cumulative_return.py
│ │ │ │ ├── parse_position.py
│ │ │ │ ├── rank_label.py
│ │ │ │ ├── report.py
│ │ │ │ ├── risk_analysis.py
│ │ │ │ └── score_ic.py
│ │ │ ├── data/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── ana.py
│ │ │ │ └── base.py
│ │ │ ├── graph.py
│ │ │ └── utils.py
│ │ ├── rolling/
│ │ │ ├── __init__.py
│ │ │ ├── __main__.py
│ │ │ ├── base.py
│ │ │ └── ddgda.py
│ │ ├── strategy/
│ │ │ ├── __init__.py
│ │ │ ├── cost_control.py
│ │ │ ├── optimizer/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── base.py
│ │ │ │ ├── enhanced_indexing.py
│ │ │ │ └── optimizer.py
│ │ │ ├── order_generator.py
│ │ │ ├── rule_strategy.py
│ │ │ └── signal_strategy.py
│ │ ├── torch.py
│ │ ├── tuner/
│ │ │ ├── __init__.py
│ │ │ ├── config.py
│ │ │ ├── launcher.py
│ │ │ ├── pipeline.py
│ │ │ ├── space.py
│ │ │ └── tuner.py
│ │ └── workflow/
│ │ ├── __init__.py
│ │ └── record_temp.py
│ ├── data/
│ │ ├── __init__.py
│ │ ├── _libs/
│ │ │ ├── __init__.py
│ │ │ ├── expanding.pyx
│ │ │ └── rolling.pyx
│ │ ├── base.py
│ │ ├── cache.py
│ │ ├── client.py
│ │ ├── data.py
│ │ ├── dataset/
│ │ │ ├── __init__.py
│ │ │ ├── handler.py
│ │ │ ├── loader.py
│ │ │ ├── processor.py
│ │ │ ├── storage.py
│ │ │ ├── utils.py
│ │ │ └── weight.py
│ │ ├── filter.py
│ │ ├── inst_processor.py
│ │ ├── ops.py
│ │ ├── pit.py
│ │ └── storage/
│ │ ├── __init__.py
│ │ ├── file_storage.py
│ │ └── storage.py
│ ├── log.py
│ ├── model/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── ens/
│ │ │ ├── __init__.py
│ │ │ ├── ensemble.py
│ │ │ └── group.py
│ │ ├── interpret/
│ │ │ ├── __init__.py
│ │ │ └── base.py
│ │ ├── meta/
│ │ │ ├── __init__.py
│ │ │ ├── dataset.py
│ │ │ ├── model.py
│ │ │ └── task.py
│ │ ├── riskmodel/
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── poet.py
│ │ │ ├── shrink.py
│ │ │ └── structured.py
│ │ ├── trainer.py
│ │ └── utils.py
│ ├── rl/
│ │ ├── __init__.py
│ │ ├── aux_info.py
│ │ ├── contrib/
│ │ │ ├── __init__.py
│ │ │ ├── backtest.py
│ │ │ ├── naive_config_parser.py
│ │ │ ├── train_onpolicy.py
│ │ │ └── utils.py
│ │ ├── data/
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── integration.py
│ │ │ ├── native.py
│ │ │ └── pickle_styled.py
│ │ ├── interpreter.py
│ │ ├── order_execution/
│ │ │ ├── __init__.py
│ │ │ ├── interpreter.py
│ │ │ ├── network.py
│ │ │ ├── policy.py
│ │ │ ├── reward.py
│ │ │ ├── simulator_qlib.py
│ │ │ ├── simulator_simple.py
│ │ │ ├── state.py
│ │ │ ├── strategy.py
│ │ │ └── utils.py
│ │ ├── reward.py
│ │ ├── seed.py
│ │ ├── simulator.py
│ │ ├── strategy/
│ │ │ ├── __init__.py
│ │ │ └── single_order.py
│ │ ├── trainer/
│ │ │ ├── __init__.py
│ │ │ ├── api.py
│ │ │ ├── callbacks.py
│ │ │ ├── trainer.py
│ │ │ └── vessel.py
│ │ └── utils/
│ │ ├── __init__.py
│ │ ├── data_queue.py
│ │ ├── env_wrapper.py
│ │ ├── finite_env.py
│ │ └── log.py
│ ├── strategy/
│ │ ├── __init__.py
│ │ └── base.py
│ ├── tests/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ └── data.py
│ ├── typehint.py
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── data.py
│ │ ├── exceptions.py
│ │ ├── file.py
│ │ ├── index_data.py
│ │ ├── mod.py
│ │ ├── objm.py
│ │ ├── paral.py
│ │ ├── pickle_utils.py
│ │ ├── resam.py
│ │ ├── serial.py
│ │ └── time.py
│ └── workflow/
│ ├── __init__.py
│ ├── exp.py
│ ├── expm.py
│ ├── online/
│ │ ├── __init__.py
│ │ ├── manager.py
│ │ ├── strategy.py
│ │ ├── update.py
│ │ └── utils.py
│ ├── record_temp.py
│ ├── recorder.py
│ ├── task/
│ │ ├── __init__.py
│ │ ├── collect.py
│ │ ├── gen.py
│ │ ├── manage.py
│ │ └── utils.py
│ └── utils.py
├── scripts/
│ ├── README.md
│ ├── check_data_health.py
│ ├── check_dump_bin.py
│ ├── collect_info.py
│ ├── data_collector/
│ │ ├── README.md
│ │ ├── baostock_5min/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── base.py
│ │ ├── br_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── cn_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── contrib/
│ │ │ ├── fill_cn_1min_data/
│ │ │ │ ├── README.md
│ │ │ │ ├── fill_cn_1min_data.py
│ │ │ │ └── requirements.txt
│ │ │ └── future_trading_date_collector/
│ │ │ ├── README.md
│ │ │ ├── future_trading_date_collector.py
│ │ │ └── requirements.txt
│ │ ├── crowd_source/
│ │ │ └── README.md
│ │ ├── crypto/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirement.txt
│ │ ├── fund/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── future_calendar_collector.py
│ │ ├── index.py
│ │ ├── pit/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── us_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── utils.py
│ │ └── yahoo/
│ │ ├── README.md
│ │ ├── collector.py
│ │ └── requirements.txt
│ ├── dump_bin.py
│ ├── dump_pit.py
│ └── get_data.py
├── setup.py
└── tests/
├── backtest/
│ ├── test_file_strategy.py
│ ├── test_high_freq_trading.py
│ ├── test_soft_topk_strategy.py
│ └── test_soft_topk_strategy_cold_start.py
├── conftest.py
├── data_mid_layer_tests/
│ ├── README.md
│ ├── test_dataloader.py
│ ├── test_dataset.py
│ ├── test_handler.py
│ ├── test_handler_storage.py
│ └── test_processor.py
├── dataset_tests/
│ ├── README.md
│ └── test_datalayer.py
├── dependency_tests/
│ ├── README.md
│ └── test_mlflow.py
├── misc/
│ ├── test_get_multi_proc.py
│ ├── test_index_data.py
│ ├── test_sepdf.py
│ └── test_utils.py
├── model/
│ └── test_general_nn.py
├── ops/
│ ├── test_elem_operator.py
│ └── test_special_ops.py
├── pytest.ini
├── rl/
│ ├── test_data_queue.py
│ ├── test_finite_env.py
│ ├── test_logger.py
│ ├── test_qlib_simulator.py
│ ├── test_saoe_simple.py
│ └── test_trainer.py
├── rolling_tests/
│ └── test_update_pred.py
├── storage_tests/
│ └── test_storage.py
├── test_all_pipeline.py
├── test_contrib_model.py
├── test_contrib_workflow.py
├── test_dump_data.py
├── test_get_data.py
├── test_pit.py
├── test_register_ops.py
├── test_structured_cov_estimator.py
└── test_workflow.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .commitlintrc.js
================================================
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
// Configuration Format: [level, applicability, value]
// level: Error level, usually expressed as a number:
// 0 - disable rule
// 1 - Warning (does not prevent commits)
// 2 - Error (will block the commit)
// applicability: the conditions under which the rule applies, commonly used values:
// “always” - always apply the rule
// “never” - never apply the rule
// value: the specific value of the rule, e.g. a maximum length of 100.
// Refs: https://commitlint.js.org/reference/rules-configuration.html
"header-max-length": [2, "always", 100],
"type-enum": [
2,
"always",
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "Release-As"]
]
}
};
================================================
FILE: .deepsource.toml
================================================
version = 1
test_patterns = ["tests/test_*.py"]
exclude_patterns = ["examples/**"]
[[analyzers]]
name = "python"
enabled = true
[analyzers.meta]
runtime_version = "3.x.x"
================================================
FILE: .dockerignore
================================================
__pycache__
*.pyc
*.pyo
*.pyd
.Python
.env
.git
================================================
FILE: .github/ISSUE_TEMPLATE/bug-report.md
================================================
---
name: "\U0001F41B Bug Report"
about: Submit a bug report to help us improve Qlib
labels: bug
---
## 🐛 Bug Description
<!-- A clear and concise description of what the bug is. -->
## To Reproduce
Steps to reproduce the behavior:
1.
1.
1.
## Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
## Screenshot
<!-- A screenshot of the error message or anything shouldn't appear-->
## Environment
**Note**: User could run `cd scripts && python collect_info.py all` under project directory to get system information
and paste them here directly.
- Qlib version:
- Python version:
- OS (`Windows`, `Linux`, `MacOS`):
- Commit number (optional, please provide it if you are using the dev version):
## Additional Notes
<!-- Add any other information about the problem here. -->
================================================
FILE: .github/ISSUE_TEMPLATE/documentation.md
================================================
---
name: "\U0001F4D6 Documentation"
about: Report an issue related to documentation
---
## 📖 Documentation
<!-- Please specify whether it's tutorial part or API reference part, and describe it.-->
================================================
FILE: .github/ISSUE_TEMPLATE/feature-request.md
================================================
---
name: "\U0001F31FFeature Request"
about: Request for a new Qlib feature
labels: enhancement
---
## 🌟 Feature Description
<!-- A clear and concise description of the feature proposal -->
## Motivation
1. Application scenario
2. Related works (Papers, Github repos etc.):
3. Any other relevant and important information:
<!-- Please describe why the feature is important. -->
## Alternatives
<!-- A short description of any alternative solutions or features you've considered. -->
## Additional Notes
<!-- Add any other context or screenshots about the feature request here. -->
================================================
FILE: .github/ISSUE_TEMPLATE/question.md
================================================
---
name: "❓Questions & Help"
about: Have some questions? We can offer help.
labels: question
---
## ❓ Questions and Help
We sincerely suggest you to carefully read the [documentation](http://qlib.readthedocs.io/) of our library as well as the official [paper](https://arxiv.org/abs/2009.11189). After that, if you still feel puzzled, please describe the question clearly under this issue.
================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
<!--- Thank you for submitting a Pull Request! In order to make our work smoother. -->
<!--- please make sure your Pull Request meets the following requirements: -->
<!--- 1. Provide a general summary of your changes in the Title above; -->
<!--- 2. Add appropriate prefixes to titles, such as `build:`, `chore:`, `ci:`, `docs:`, `feat:`, `fix:`, `perf:`, `refactor:`, `revert:`, `style:`, `test:`(Ref: https://www.conventionalcommits.org/). -->
<!--- Category: -->
<!--- Patch Updates: `fix:` -->
<!--- Example: fix(auth): correct login validation issue -->
<!--- minor update (introduces new functionality): `feat` -->
<!--- Example: feature(parser): add ability to parse arrays -->
<!--- major update(destructive update): Include BREAKING CHANGE in the commit message footer, or add `! ` in the commit footer to indicate that there is a destructive update. -->
<!--- Example: feat(auth)! : remove support for old authentication method -->
<!--- Other updates: `build:`, `chore:`, `ci:`, `docs:`, `perf:`, `refactor:`, `revert:`, `style:`, `test:`. -->
<!--- Provide a general summary of your changes in the Title above -->
## Description
<!--- Describe your changes in detail -->
## Motivation and Context
<!--- Are there any related issues? If so, please put the link here. -->
<!--- Why is this change required? What problem does it solve? -->
## How Has This Been Tested?
<!--- Put an `x` in all the boxes that apply: --->
- [ ] Pass the test by running: `pytest qlib/tests/test_all_pipeline.py` under upper directory of `qlib`.
- [ ] If you are adding a new feature, test on your own test scripts.
<!--- **ATTENTION**: If you are adding a new feature, please make sure your codes are **correctly tested**. If our test scripts do not cover your cases, please provide your own test scripts under the `tests` folder and test them. More information about test scripts can be found [here](https://docs.python.org/3/library/unittest.html#basic-example), or you could refer to those we provide under the `tests` folder. -->
## Screenshots of Test Results (if appropriate):
1. Pipeline test:
2. Your own tests:
## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Fix bugs
- [ ] Add new feature
- [ ] Update documentation
================================================
FILE: .github/brew_install.sh
================================================
#!/bin/bash
set -u
# First check if the OS is Linux.
if [[ "$(uname)" = "Linux" ]]; then
HOMEBREW_ON_LINUX=1
fi
# On macOS, this script installs to /usr/local only.
# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access
# and ~/.linuxbrew otherwise.
# To install elsewhere (which is unsupported)
# you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
HOMEBREW_PREFIX="/usr/local"
HOMEBREW_REPOSITORY="/usr/local/Homebrew"
HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"
STAT="stat -f"
CHOWN="/usr/sbin/chown"
CHGRP="/usr/bin/chgrp"
GROUP="admin"
TOUCH="/usr/bin/touch"
else
HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"
HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
STAT="stat --printf"
CHOWN="/bin/chown"
CHGRP="/bin/chgrp"
GROUP="$(id -gn)"
TOUCH="/bin/touch"
fi
BREW_REPO="https://github.com/Homebrew/brew"
# TODO: bump version when new macOS is released
MACOS_LATEST_SUPPORTED="10.15"
# TODO: bump version when new macOS is released
MACOS_OLDEST_SUPPORTED="10.13"
# For Homebrew on Linux
REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556
REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements
# no analytics during installation
export HOMEBREW_NO_ANALYTICS_THIS_RUN=1
export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1
# string formatters
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_underline="$(tty_escape "4;39")"
tty_blue="$(tty_mkbold 34)"
tty_red="$(tty_mkbold 31)"
tty_bold="$(tty_mkbold 39)"
tty_reset="$(tty_escape 0)"
have_sudo_access() {
local -a args
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A")
fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
if [[ -n "${args[*]-}" ]]; then
/usr/bin/sudo "${args[@]}" -l mkdir &>/dev/null
else
/usr/bin/sudo -l mkdir &>/dev/null
fi
HAVE_SUDO_ACCESS="$?"
fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then
abort "Need sudo access on macOS (e.g. the user $USER to be an Administrator)!"
fi
return "$HAVE_SUDO_ACCESS"
}
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
}
warn() {
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
}
abort() {
printf "%s\n" "$1"
exit 1
}
execute() {
if ! "$@"; then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi
}
execute_sudo() {
local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
if have_sudo_access; then
ohai "/usr/bin/sudo" "${args[@]}"
execute "/usr/bin/sudo" "${args[@]}"
else
ohai "${args[@]}"
execute "${args[@]}"
fi
}
getc() {
local save_state
save_state=$(/bin/stty -g)
/bin/stty raw -echo
IFS= read -r -n 1 -d '' "$@"
/bin/stty "$save_state"
}
wait_for_user() {
local c
echo
echo "Press RETURN to continue or any other key to abort"
getc c
# we test for \r and \n because some stuff does \r instead
if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then
exit 1
fi
}
major_minor() {
echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")"
}
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"
fi
version_gt() {
[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]
}
version_ge() {
[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]]
}
version_lt() {
[[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
}
should_install_command_line_tools() {
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then
return 1
fi
if version_gt "$macos_version" "10.13"; then
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
else
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] ||
! [[ -e "/usr/include/iconv.h" ]]
fi
}
get_permission() {
$STAT "%A" "$1"
}
user_only_chmod() {
[[ -d "$1" ]] && [[ "$(get_permission "$1")" != "755" ]]
}
exists_but_not_writable() {
[[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]]
}
get_owner() {
$STAT "%u" "$1"
}
file_not_owned() {
[[ "$(get_owner "$1")" != "$(id -u)" ]]
}
get_group() {
$STAT "%g" "$1"
}
file_not_grpowned() {
[[ " $(id -G "$USER") " != *" $(get_group "$1") "* ]]
}
# Please sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository.
test_ruby () {
if [[ ! -x $1 ]]
then
return 1
fi
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
"abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \
Gem::Version.new('$REQUIRED_RUBY_VERSION').to_s.split('.').first(2)" 2>/dev/null
}
no_usable_ruby() {
local ruby_exec
IFS=$'\n' # Do word splitting on new lines only
for ruby_exec in $(which -a ruby); do
if test_ruby "$ruby_exec"; then
return 1
fi
done
IFS=$' \t\n' # Restore IFS to its default value
return 0
}
outdated_glibc() {
local glibc_version
glibc_version=$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+')
version_lt "$glibc_version" "$REQUIRED_GLIBC_VERSION"
}
if [[ -n "${HOMEBREW_ON_LINUX-}" ]] && no_usable_ruby && outdated_glibc
then
abort "$(cat <<-EOFABORT
Homebrew requires Ruby $REQUIRED_RUBY_VERSION which was not found on your system.
Homebrew portable Ruby requires Glibc version $REQUIRED_GLIBC_VERSION or newer,
and your Glibc version is too old.
See ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#requirements${tty_reset}
Install Ruby $REQUIRED_RUBY_VERSION and add its location to your PATH.
EOFABORT
)"
fi
# USER isn't always set so provide a fall back for the installer and subprocesses.
if [[ -z "${USER-}" ]]; then
USER="$(chomp "$(id -un)")"
export USER
fi
# Invalidate sudo timestamp before exiting (if it wasn't active before).
if ! /usr/bin/sudo -n -v 2>/dev/null; then
trap '/usr/bin/sudo -k' EXIT
fi
# Things can fail later if `pwd` doesn't exist.
# Also sudo prints a warning message for no good reason
cd "/usr" || exit 1
####################################################################### script
if ! command -v git >/dev/null; then
abort "$(cat <<EOABORT
You must install Git before installing Homebrew. See:
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
EOABORT
)"
fi
if ! command -v curl >/dev/null; then
abort "$(cat <<EOABORT
You must install cURL before installing Homebrew. See:
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
EOABORT
)"
fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
have_sudo_access
else
if [[ -n "${CI-}" ]] || [[ -w "$HOMEBREW_PREFIX_DEFAULT" ]] || [[ -w "/home/linuxbrew" ]] || [[ -w "/home" ]]; then
HOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT"
else
trap exit SIGINT
if [[ $(/usr/bin/sudo -n -l mkdir 2>&1) != *"mkdir"* ]]; then
ohai "Select the Homebrew installation directory"
echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})"
echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}$HOME/.linuxbrew${tty_reset}"
echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation"
fi
if have_sudo_access; then
HOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT"
else
HOMEBREW_PREFIX="$HOME/.linuxbrew"
fi
trap - SIGINT
fi
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
fi
if [[ "$UID" == "0" ]]; then
abort "Don't run this as root!"
elif [[ -d "$HOMEBREW_PREFIX" && ! -x "$HOMEBREW_PREFIX" ]]; then
abort "$(cat <<EOABORT
The Homebrew prefix, ${HOMEBREW_PREFIX}, exists but is not searchable. If this is
not intentional, please restore the default permissions and try running the
installer again:
sudo chmod 775 ${HOMEBREW_PREFIX}
EOABORT
)"
fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
if version_lt "$macos_version" "10.7"; then
abort "$(cat <<EOABORT
Your Mac OS X version is too old. See:
${tty_underline}https://github.com/mistydemeo/tigerbrew${tty_reset}
EOABORT
)"
elif version_lt "$macos_version" "10.10"; then
abort "Your OS X version is too old"
elif version_gt "$macos_version" "$MACOS_LATEST_SUPPORTED" || \
version_lt "$macos_version" "$MACOS_OLDEST_SUPPORTED"; then
who="We"
what=""
if version_gt "$macos_version" "$MACOS_LATEST_SUPPORTED"; then
what="pre-release version"
else
who+=" (and Apple)"
what="old version"
fi
ohai "You are using macOS ${macos_version}."
ohai "${who} do not provide support for this ${what}."
echo "$(cat <<EOS
This installation may not succeed.
After installation, you will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew\'s GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this ${what}.
EOS
)
"
fi
fi
ohai "This script will install:"
echo "${HOMEBREW_PREFIX}/bin/brew"
echo "${HOMEBREW_PREFIX}/share/doc/homebrew"
echo "${HOMEBREW_PREFIX}/share/man/man1/brew.1"
echo "${HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
echo "${HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
echo "${HOMEBREW_REPOSITORY}"
# Keep relatively in sync with
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
directories=(bin etc include lib sbin share opt var
Frameworks
etc/bash_completion.d lib/pkgconfig
share/aclocal share/doc share/info share/locale share/man
share/man/man1 share/man/man2 share/man/man3 share/man/man4
share/man/man5 share/man/man6 share/man/man7 share/man/man8
var/log var/homebrew var/homebrew/linked
bin/brew)
group_chmods=()
for dir in "${directories[@]}"; do
if exists_but_not_writable "${HOMEBREW_PREFIX}/${dir}"; then
group_chmods+=("${HOMEBREW_PREFIX}/${dir}")
fi
done
# zsh refuses to read from these directories if group writable
directories=(share/zsh share/zsh/site-functions)
zsh_dirs=()
for dir in "${directories[@]}"; do
zsh_dirs+=("${HOMEBREW_PREFIX}/${dir}")
done
directories=(bin etc include lib sbin share var opt
share/zsh share/zsh/site-functions
var/homebrew var/homebrew/linked
Cellar Caskroom Homebrew Frameworks)
mkdirs=()
for dir in "${directories[@]}"; do
if ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]; then
mkdirs+=("${HOMEBREW_PREFIX}/${dir}")
fi
done
user_chmods=()
if [[ "${#zsh_dirs[@]}" -gt 0 ]]; then
for dir in "${zsh_dirs[@]}"; do
if user_only_chmod "${dir}"; then
user_chmods+=("${dir}")
fi
done
fi
chmods=()
if [[ "${#group_chmods[@]}" -gt 0 ]]; then
chmods+=("${group_chmods[@]}")
fi
if [[ "${#user_chmods[@]}" -gt 0 ]]; then
chmods+=("${user_chmods[@]}")
fi
chowns=()
chgrps=()
if [[ "${#chmods[@]}" -gt 0 ]]; then
for dir in "${chmods[@]}"; do
if file_not_owned "${dir}"; then
chowns+=("${dir}")
fi
if file_not_grpowned "${dir}"; then
chgrps+=("${dir}")
fi
done
fi
if [[ "${#group_chmods[@]}" -gt 0 ]]; then
ohai "The following existing directories will be made group writable:"
printf "%s\n" "${group_chmods[@]}"
fi
if [[ "${#user_chmods[@]}" -gt 0 ]]; then
ohai "The following existing directories will be made writable by user only:"
printf "%s\n" "${user_chmods[@]}"
fi
if [[ "${#chowns[@]}" -gt 0 ]]; then
ohai "The following existing directories will have their owner set to ${tty_underline}${USER}${tty_reset}:"
printf "%s\n" "${chowns[@]}"
fi
if [[ "${#chgrps[@]}" -gt 0 ]]; then
ohai "The following existing directories will have their group set to ${tty_underline}${GROUP}${tty_reset}:"
printf "%s\n" "${chgrps[@]}"
fi
if [[ "${#mkdirs[@]}" -gt 0 ]]; then
ohai "The following new directories will be created:"
printf "%s\n" "${mkdirs[@]}"
fi
if should_install_command_line_tools; then
ohai "The Xcode Command Line Tools will be installed."
fi
if [[ -t 0 && -z "${CI-}" ]]; then
wait_for_user
fi
if [[ -d "${HOMEBREW_PREFIX}" ]]; then
if [[ "${#chmods[@]}" -gt 0 ]]; then
execute_sudo "/bin/chmod" "u+rwx" "${chmods[@]}"
fi
if [[ "${#group_chmods[@]}" -gt 0 ]]; then
execute_sudo "/bin/chmod" "g+rwx" "${group_chmods[@]}"
fi
if [[ "${#user_chmods[@]}" -gt 0 ]]; then
execute_sudo "/bin/chmod" "755" "${user_chmods[@]}"
fi
if [[ "${#chowns[@]}" -gt 0 ]]; then
execute_sudo "$CHOWN" "$USER" "${chowns[@]}"
fi
if [[ "${#chgrps[@]}" -gt 0 ]]; then
execute_sudo "$CHGRP" "$GROUP" "${chgrps[@]}"
fi
else
execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_PREFIX}"
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
execute_sudo "$CHOWN" "root:wheel" "${HOMEBREW_PREFIX}"
else
execute_sudo "$CHOWN" "$USER:$GROUP" "${HOMEBREW_PREFIX}"
fi
fi
if [[ "${#mkdirs[@]}" -gt 0 ]]; then
execute_sudo "/bin/mkdir" "-p" "${mkdirs[@]}"
execute_sudo "/bin/chmod" "g+rwx" "${mkdirs[@]}"
execute_sudo "$CHOWN" "$USER" "${mkdirs[@]}"
execute_sudo "$CHGRP" "$GROUP" "${mkdirs[@]}"
fi
if ! [[ -d "${HOMEBREW_CACHE}" ]]; then
if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; then
execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"
else
execute "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"
fi
fi
if exists_but_not_writable "${HOMEBREW_CACHE}"; then
execute_sudo "/bin/chmod" "g+rwx" "${HOMEBREW_CACHE}"
fi
if file_not_owned "${HOMEBREW_CACHE}"; then
execute_sudo "$CHOWN" "$USER" "${HOMEBREW_CACHE}"
fi
if file_not_grpowned "${HOMEBREW_CACHE}"; then
execute_sudo "$CHGRP" "$GROUP" "${HOMEBREW_CACHE}"
fi
if [[ -d "${HOMEBREW_CACHE}" ]]; then
execute "$TOUCH" "${HOMEBREW_CACHE}/.cleaned"
fi
if should_install_command_line_tools && version_ge "$macos_version" "10.13"; then
ohai "Searching online for the Command Line Tools"
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
execute_sudo "$TOUCH" "$clt_placeholder"
clt_label_command="/usr/sbin/softwareupdate -l |
grep -B 1 -E 'Command Line Tools' |
awk -F'*' '/^ *\\*/ {print \$2}' |
sed -e 's/^ *Label: //' -e 's/^ *//' |
sort -V |
tail -n1"
clt_label="$(chomp "$(/bin/bash -c "$clt_label_command")")"
if [[ -n "$clt_label" ]]; then
ohai "Installing $clt_label"
execute_sudo "/usr/sbin/softwareupdate" "-i" "$clt_label"
execute_sudo "/bin/rm" "-f" "$clt_placeholder"
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
fi
# Headless install may have failed, so fallback to original 'xcode-select' method
if should_install_command_line_tools && test -t 0; then
ohai "Installing the Command Line Tools (expect a GUI popup):"
execute_sudo "/usr/bin/xcode-select" "--install"
echo "Press any key when the installation has completed."
getc
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "$output" == *"license"* ]]; then
abort "$(cat <<EOABORT
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
sudo xcodebuild -license
EOABORT
)"
fi
ohai "Downloading and installing Homebrew..."
(
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
# we do it in four steps to avoid merge errors when reinstalling
execute "git" "init" "-q"
# "git remote add" will fail if the remote is defined in the global config
execute "git" "config" "remote.origin.url" "${BREW_REPO}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
# ensure we don't munge line endings on checkout
execute "git" "config" "core.autocrlf" "false"
execute "git" "fetch" "origin" "--force"
execute "git" "fetch" "origin" "--tags" "--force"
execute "git" "reset" "--hard" "origin/master"
execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"
) || exit 1
if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; then
warn "${HOMEBREW_PREFIX}/bin is not in your PATH."
fi
ohai "Installation successful!"
echo
# Use the shell's audible bell.
if [[ -t 1 ]]; then
printf "\a"
fi
# Use an extra newline and bold to avoid this being missed.
ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."
echo "$(cat <<EOS
${tty_bold}Read the analytics documentation (and how to opt-out) here:
${tty_underline}https://docs.brew.sh/Analytics${tty_reset}
No analytics data has been sent yet (or will be during this \`install\` run).
EOS
)
"
ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
echo "$(cat <<EOS
${tty_underline}https://github.com/Homebrew/brew#donations${tty_reset}
EOS
)
"
(
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true"
execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true"
) || exit 1
ohai "Next steps:"
echo "- Run \`brew help\` to get started"
echo "- Further documentation: "
echo " ${tty_underline}https://docs.brew.sh${tty_reset}"
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then
case "$SHELL" in
*/bash*)
if [[ -r "$HOME/.bash_profile" ]]; then
shell_profile="$HOME/.bash_profile"
else
shell_profile="$HOME/.profile"
fi
;;
*/zsh*)
shell_profile="$HOME/.zprofile"
;;
*)
shell_profile="$HOME/.profile"
;;
esac
echo "- Install the Homebrew dependencies if you have sudo access:"
if [[ $(command -v apt-get) ]]; then
echo " sudo apt-get install build-essential"
elif [[ $(command -v yum) ]]; then
echo " sudo yum groupinstall 'Development Tools'"
elif [[ $(command -v pacman) ]]; then
echo " sudo pacman -S base-devel"
elif [[ $(command -v apk) ]]; then
echo " sudo apk add build-base"
fi
cat <<EOS
See ${tty_underline}https://docs.brew.sh/linux${tty_reset} for more information
- Add Homebrew to your ${tty_bold}PATH${tty_reset} in ${tty_underline}${shell_profile}${tty_reset}:
echo 'eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv)' >> ${shell_profile}
eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv)
- We recommend that you install GCC:
brew install gcc
EOS
fi
================================================
FILE: .github/release-drafter.yml
================================================
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🌟 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '📚 Documentation'
label:
- 'doc'
- 'documentation'
- title: '🧹 Maintenance'
label:
- 'maintenance'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
================================================
FILE: .github/workflows/lint_title.yml
================================================
name: Lint pull request title
on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
lint-title:
runs-on: ubuntu-latest
steps:
# This step is necessary because the lint title uses the .commitlintrc.js file in the project root directory.
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
- name: Install commitlint
run: npm install --save-dev @commitlint/{config-conventional,cli}
- name: Validate PR Title with commitlint
env:
BODY: ${{ github.event.pull_request.title }}
run: |
echo "$BODY" | npx commitlint --config .commitlintrc.js
================================================
FILE: .github/workflows/release.yml
================================================
name: Release
on:
push:
branches:
- main
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release_please.outputs.release_created }}
steps:
- name: Release please
id: release_please
uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.PAT }}
release-type: simple
deploy_with_manylinux:
needs: release
permissions:
contents: write
pull-requests: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: needs.release.outputs.release_created == 'true'
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
if: needs.release.outputs.release_created == 'true'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Build wheel on Linux
if: needs.release.outputs.release_created == 'true'
uses: RalfG/python-wheels-manylinux-build@v0.7.1-manylinux2014_x86_64
with:
python-versions: 'cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312'
build-requirements: 'numpy cython'
- name: Install dependencies
if: needs.release.outputs.release_created == 'true'
run: |
python -m pip install twine
- name: Upload to PyPi
if: needs.release.outputs.release_created == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TESTPYPI }}
run: |
twine check dist/pyqlib-*-manylinux*.whl
twine upload --repository-url https://test.pypi.org/legacy/ dist/pyqlib-*-manylinux*.whl --verbose
deploy_with_bdist_wheel:
needs: release
runs-on: ${{ matrix.os }}
strategy:
matrix:
# After testing, the whl files of pyqlib built by macos-14 and macos-15 in python environments of 3.8, 3.9, 3.10, 3.11, 3.12,
# the filenames are exactly duplicated, which will result in the duplicated whl files not being able to be uploaded to pypi,
# so we chose to just keep the latest macos-latest. macos-latest currently points to macos-15.
# Also, macos-13 will stop being supported on 2025-11-14.
# Refs: https://github.blog/changelog/2025-07-11-upcoming-changes-to-macos-hosted-runners-macos-latest-migration-and-xcode-support-policy-updates/
os: [windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
if: needs.release.outputs.release_created == 'true'
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
if: needs.release.outputs.release_created == 'true'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
if: needs.release.outputs.release_created == 'true'
run: |
make dev
- name: Build wheel on ${{ matrix.os }}
if: needs.release.outputs.release_created == 'true'
run: |
make build
- name: Upload to PyPi
if: needs.release.outputs.release_created == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TESTPYPI }}
run: |
twine check dist/*.whl
twine upload --repository-url https://test.pypi.org/legacy/ dist/*.whl --verbose
================================================
FILE: .github/workflows/stale.yml
================================================
name: Mark stale issues and pull requests
on:
schedule:
- cron: "0 0/3 * * *"
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been open for three months with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days'
stale-pr-message: 'This PR is stale because it has been open for a year with no activity. Remove the stale label or comment on the PR otherwise this will be closed in 5 days'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
days-before-stale: 90
days-before-pr-stale: 365
days-before-close: 5
operations-per-run: 100
exempt-issue-labels: 'bug,enhancement'
remove-stale-when-updated: true
================================================
FILE: .github/workflows/test_qlib_from_pip.yml
================================================
name: Test qlib from pip
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
timeout-minutes: 120
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-24.04, ubuntu-22.04, macos-14, macos-15]
# In github action, using python 3.7, pip install will not match the latest version of the package.
# Also, python 3.7 is no longer supported from macos-14, and will be phased out from macos-13 in the near future.
# All things considered, we have removed python 3.7.
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Test qlib from pip
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Update pip to the latest version
run: |
python -m pip install --upgrade pip
- name: Qlib installation test
run: |
python -m pip install pyqlib
- name: Install Lightgbm for MacOS
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
run: |
brew update
brew install libomp || brew reinstall libomp
python -m pip install --no-binary=:all: lightgbm
- name: Downloads dependencies data
run: |
cd ..
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
cd qlib
- name: Test workflow by config
run: |
qrun examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
================================================
FILE: .github/workflows/test_qlib_from_source.yml
================================================
name: Test qlib from source
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
timeout-minutes: 180
# we may retry for 3 times for `Unit tests with Pytest`
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-24.04, ubuntu-22.04, macos-14, macos-15]
# In github action, using python 3.7, pip install will not match the latest version of the package.
# Also, python 3.7 is no longer supported from macos-14, and will be phased out from macos-13 in the near future.
# All things considered, we have removed python 3.7.
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Test qlib from source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Update pip to the latest version
run: |
python -m pip install --upgrade pip
- name: Installing pytorch for macos
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
run: |
python -m pip install torch torchvision torchaudio
- name: Installing pytorch for ubuntu
if: ${{ matrix.os == 'ubuntu-24.04' || matrix.os == 'ubuntu-22.04' }}
run: |
python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
- name: Installing pytorch for windows
if: ${{ matrix.os == 'windows-latest' }}
run: |
python -m pip install torch torchvision torchaudio
- name: Set up Python tools
run: |
make dev
- name: Lint with Black
run: |
make black
- name: Make html with sphinx
# Since read the docs builds on ubuntu 22.04, we only need to test that the build passes on ubuntu 22.04.
if: ${{ matrix.os == 'ubuntu-22.04' }}
run: |
make docs-gen
- name: Check Qlib with pylint
run: |
make pylint
- name: Check Qlib with flake8
run: |
make flake8
- name: Check Qlib with mypy
run: |
make mypy
# Due to issues that cannot be automatically fixed when running `nbqa black . -l 120 --check --diff` on Jupyter notebooks,
# we reverted to a version of `black` earlier than 26.1.0 before performing the checks.
- name: Check Qlib ipynb with nbqa
run: |
python -m pip install "black<26.1"
make nbqa
- name: Test data downloads
run: |
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
python scripts/get_data.py download_data --file_name rl_data.zip --target_dir tests/.data/rl
- name: Install Lightgbm for MacOS
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
run: |
brew update
brew install libomp || brew reinstall libomp
python -m pip install --no-binary=:all: lightgbm
- name: Check Qlib ipynb with nbconvert
run: |
make nbconvert
- name: Test workflow by config (install from source)
run: |
python -m pip install numba
python qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
- name: Unit tests with Pytest (MacOS)
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
uses: nick-fields/retry@v2
with:
timeout_minutes: 60
max_attempts: 3
command: |
# Limit the number of threads in various libraries to prevent Segmentation faults caused by OpenMP multithreading conflicts under macOS.
export OMP_NUM_THREADS=1 # Limit the number of OpenMP threads
export MKL_NUM_THREADS=1 # Limit the number of Intel MKL threads
export NUMEXPR_NUM_THREADS=1 # Limit the number of NumExpr threads
export OPENBLAS_NUM_THREADS=1 # Limit the number of OpenBLAS threads
export VECLIB_MAXIMUM_THREADS=1 # Limit the number of macOS Accelerate/vecLib threads
cd tests
python -m pytest . -m "not slow" --durations=0
- name: Unit tests with Pytest (Ubuntu and Windows)
if: ${{ matrix.os != 'macos-13' && matrix.os != 'macos-14' && matrix.os != 'macos-15' }}
uses: nick-fields/retry@v2
with:
timeout_minutes: 60
max_attempts: 3
command: |
cd tests
python -m pytest . -m "not slow" --durations=0
================================================
FILE: .github/workflows/test_qlib_from_source_slow.yml
================================================
name: Test qlib from source slow
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
timeout-minutes: 720
# we may retry for 3 times for `Unit tests with Pytest`
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-24.04, ubuntu-22.04, macos-14, macos-15]
# In github action, using python 3.7, pip install will not match the latest version of the package.
# Also, python 3.7 is no longer supported from macos-14, and will be phased out from macos-13 in the near future.
# All things considered, we have removed python 3.7.
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Test qlib from source slow
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python tools
run: |
make dev
- name: Downloads dependencies data
run: |
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
- name: Install Lightgbm for MacOS
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
run: |
brew update
brew install libomp || brew reinstall libomp
python -m pip install --no-binary=:all: lightgbm
- name: Unit tests with Pytest
uses: nick-fields/retry@v2
with:
timeout_minutes: 240
max_attempts: 3
command: |
cd tests
python -m pytest . -m "slow" --durations=0
================================================
FILE: .gitignore
================================================
# https://github.com/github/gitignore/blob/master/Python.gitignore
__pycache__/
*.pyc
*.pyd
*.so
*.ipynb
.ipynb_checkpoints
_build
build/
dist/
*.pkl
*.hd5
*.csv
.env
.vim
.nvimrc
.vscode
qlib/VERSION.txt
qlib/data/_libs/expanding.cpp
qlib/data/_libs/rolling.cpp
qlib/_version.py
examples/estimator/estimator_example/
examples/rl/data/
examples/rl/checkpoints/
examples/rl/outputs/
examples/rl_order_execution/data/
examples/rl_order_execution/outputs/
*.egg-info/
# test related
test-output.xml
.output
.data
# special software
mlruns/
tags
.pytest_cache/
.mypy_cache/
.vscode/
*.swp
./pretrain
.idea/
.aider*
================================================
FILE: .mypy.ini
================================================
[mypy]
exclude = (?x)(
^qlib/backtest/high_performance_ds\.py$
| ^qlib/contrib
| ^qlib/data
| ^qlib/model
| ^qlib/strategy
| ^qlib/tests
| ^qlib/utils
| ^qlib/workflow
| ^qlib/config\.py$
| ^qlib/log\.py$
| ^qlib/__init__\.py$
)
ignore_missing_imports = true
disallow_incomplete_defs = true
follow_imports = skip
================================================
FILE: .pre-commit-config.yaml
================================================
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: ["qlib", "-l 120"]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: ["--ignore=E501,F541,E266,E402,W503,E731,E203"]
================================================
FILE: .pylintrc
================================================
[TYPECHECK]
# https://stackoverflow.com/a/53572939
# List of members which are set dynamically and missed by Pylint inference
# system, and so shouldn't trigger E1101 when accessed.
generated-members=numpy.*, torch.*
================================================
FILE: .readthedocs.yaml
================================================
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
# Required
version: 2
# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.8"
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
# Build all formats
formats: all
# Optionally set the version of Python and requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
================================================
FILE: CHANGELOG.md
================================================
================================================
FILE: CHANGES.rst
================================================
Changelog
=========
Here you can see the full list of changes between each QLib release.
Version 0.1.0
-------------
This is the initial release of QLib library.
Version 0.1.1
-------------
Performance optimize. Add more features and operators.
Version 0.1.2
-------------
- Support operator syntax. Now ``High() - Low()`` is equivalent to ``Sub(High(), Low())``.
- Add more technical indicators.
Version 0.1.3
-------------
Bug fix and add instruments filtering mechanism.
Version 0.2.0
-------------
- Redesign ``LocalProvider`` database format for performance improvement.
- Support load features as string fields.
- Add scripts for database construction.
- More operators and technical indicators.
Version 0.2.1
-------------
- Support registering user-defined ``Provider``.
- Support use operators in string format, e.g. ``['Ref($close, 1)']`` is valid field format.
- Support dynamic fields in ``$some_field`` format. And existing fields like ``Close()`` may be deprecated in the future.
Version 0.2.2
-------------
- Add ``disk_cache`` for reusing features (enabled by default).
- Add ``qlib.contrib`` for experimental model construction and evaluation.
Version 0.2.3
-------------
- Add ``backtest`` module
- Decoupling the Strategy, Account, Position, Exchange from the backtest module
Version 0.2.4
-------------
- Add ``profit attribution`` module
- Add ``rick_control`` and ``cost_control`` strategies
Version 0.3.0
-------------
- Add ``estimator`` module
Version 0.3.1
-------------
- Add ``filter`` module
Version 0.3.2
-------------
- Add real price trading, if the ``factor`` field in the data set is incomplete, use ``adj_price`` trading
- Refactor ``handler`` ``launcher`` ``trainer`` code
- Support ``backtest`` configuration parameters in the configuration file
- Fix bug in position ``amount`` is 0
- Fix bug of ``filter`` module
Version 0.3.3
-------------
- Fix bug of ``filter`` module
Version 0.3.4
-------------
- Support for ``finetune model``
- Refactor ``fetcher`` code
Version 0.3.5
-------------
- Support multi-label training, you can provide multiple label in ``handler``. (But LightGBM doesn't support due to the algorithm itself)
- Refactor ``handler`` code, dataset.py is no longer used, and you can deploy your own labels and features in ``feature_label_config``
- Handler only offer DataFrame. Also, ``trainer`` and model.py only receive DataFrame
- Change ``split_rolling_data``, we roll the data on market calendar now, not on normal date
- Move some date config from ``handler`` to ``trainer``
Version 0.4.0
-------------
- Add `data` package that holds all data-related codes
- Reform the data provider structure
- Create a server for data centralized management `qlib-server <https://amc-msra.visualstudio.com/trading-algo/_git/qlib-server>`_
- Add a `ClientProvider` to work with server
- Add a pluggable cache mechanism
- Add a recursive backtracking algorithm to inspect the furthest reference date for an expression
.. note::
The ``D.instruments`` function does not support ``start_time``, ``end_time``, and ``as_list`` parameters, if you want to get the results of previous versions of ``D.instruments``, you can do this:
>>> from qlib.data import D
>>> instruments = D.instruments(market='csi500')
>>> D.list_instruments(instruments=instruments, start_time='2015-01-01', end_time='2016-02-15', as_list=True)
Version 0.4.1
-------------
- Add support Windows
- Fix ``instruments`` type bug
- Fix ``features`` is empty bug(It will cause failure in updating)
- Fix ``cache`` lock and update bug
- Fix use the same cache for the same field (the original space will add a new cache)
- Change "logger handler" from config
- Change model load support 0.4.0 later
- The default value of the ``method`` parameter of ``risk_analysis`` function is changed from **ci** to **si**
Version 0.4.2
-------------
- Refactor DataHandler
- Add ``Alpha360`` DataHandler
Version 0.4.3
-------------
- Implementing Online Inference and Trading Framework
- Refactoring The interfaces of backtest and strategy module.
Version 0.4.4
-------------
- Optimize cache generation performance
- Add report module
- Fix bug when using ``ServerDatasetCache`` offline.
- In the previous version of ``long_short_backtest``, there is a case of ``np.nan`` in long_short. The current version ``0.4.4`` has been fixed, so ``long_short_backtest`` will be different from the previous version.
- In the ``0.4.2`` version of ``risk_analysis`` function, ``N`` is ``250``, and ``N`` is ``252`` from ``0.4.3``, so ``0.4.2`` is ``0.002122`` smaller than the ``0.4.3`` the backtest result is slightly different between ``0.4.2`` and ``0.4.3``.
- refactor the argument of backtest function.
- **NOTE**:
- The default arguments of topk margin strategy is changed. Please pass the arguments explicitly if you want to get the same backtest result as previous version.
- The TopkWeightStrategy is changed slightly. It will try to sell the stocks more than ``topk``. (The backtest result of TopkAmountStrategy remains the same)
- The margin ratio mechanism is supported in the Topk Margin strategies.
Version 0.4.5
-------------
- Add multi-kernel implementation for both client and server.
- Support a new way to load data from client which skips dataset cache.
- Change the default dataset method from single kernel implementation to multi kernel implementation.
- Accelerate the high frequency data reading by optimizing the relative modules.
- Support a new method to write config file by using dict.
Version 0.4.6
-------------
- Some bugs are fixed
- The default config in `Version 0.4.5` is not friendly to daily frequency data.
- Backtest error in TopkWeightStrategy when `WithInteract=True`.
Version 0.5.0
-------------
- First opensource version
- Refine the docs, code
- Add baselines
- public data crawler
Version 0.8.0
-------------
- The backtest is greatly refactored.
- Nested decision execution framework is supported
- There are lots of changes for daily trading, it is hard to list all of them. But a few important changes could be noticed
- The trading limitation is more accurate;
- In `previous version <https://github.com/microsoft/qlib/blob/v0.7.2/qlib/contrib/backtest/exchange.py#L160>`__, longing and shorting actions share the same action.
- In `current version <https://github.com/microsoft/qlib/blob/7c31012b507a3823117bddcc693fc64899460b2a/qlib/backtest/exchange.py#L304>`__, the trading limitation is different between logging and shorting action.
- The constant is different when calculating annualized metrics.
- `Current version <https://github.com/microsoft/qlib/blob/7c31012b507a3823117bddcc693fc64899460b2a/qlib/contrib/evaluate.py#L42>`_ uses more accurate constant than `previous version <https://github.com/microsoft/qlib/blob/v0.7.2/qlib/contrib/evaluate.py#L22>`__
- `A new version <https://github.com/microsoft/qlib/blob/7c31012b507a3823117bddcc693fc64899460b2a/qlib/tests/data.py#L17>`__ of data is released. Due to the unstability of Yahoo data source, the data may be different after downloading data again.
- Users could check out the backtesting results between `Current version <https://github.com/microsoft/qlib/tree/7c31012b507a3823117bddcc693fc64899460b2a/examples/benchmarks>`__ and `previous version <https://github.com/microsoft/qlib/tree/v0.7.2/examples/benchmarks>`__
Other Versions
--------------
Please refer to `Github release Notes <https://github.com/microsoft/qlib/releases>`_
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Microsoft Open Source Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
Resources:
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
================================================
FILE: Dockerfile
================================================
FROM continuumio/miniconda3:latest
WORKDIR /qlib
COPY . .
RUN apt-get update && \
apt-get install -y build-essential
RUN conda create --name qlib_env python=3.8 -y
RUN echo "conda activate qlib_env" >> ~/.bashrc
ENV PATH /opt/conda/envs/qlib_env/bin:$PATH
RUN python -m pip install --upgrade pip
RUN python -m pip install numpy==1.23.5
RUN python -m pip install pandas==1.5.3
RUN python -m pip install importlib-metadata==5.2.0
RUN python -m pip install "cloudpickle<3"
RUN python -m pip install scikit-learn==1.3.2
RUN python -m pip install cython packaging tables matplotlib statsmodels
RUN python -m pip install pybind11 cvxpy
ARG IS_STABLE="yes"
RUN if [ "$IS_STABLE" = "yes" ]; then \
python -m pip install pyqlib; \
else \
python setup.py install; \
fi
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
================================================
FILE: MANIFEST.in
================================================
exclude tests/*
include qlib/*
include qlib/*/*
include qlib/*/*/*
include qlib/*/*/*/*
include qlib/*/*/*/*/*
================================================
FILE: Makefile
================================================
.PHONY: clean deepclean prerequisite dependencies lightgbm rl develop lint docs package test analysis all install dev black pylint flake8 mypy nbqa nbconvert lint build upload docs-gen
#You can modify it according to your terminal
SHELL := /bin/bash
########################################################################################
# Variables
########################################################################################
# Documentation target directory, will be adapted to specific folder for readthedocs.
PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$$READTHEDOCS_OUTPUT/html" || echo "public")
SO_DIR := qlib/data/_libs
SO_FILES := $(wildcard $(SO_DIR)/*.so)
ifeq ($(OS),Windows_NT)
IS_WINDOWS = true
else
IS_WINDOWS = false
endif
########################################################################################
# Development Environment Management
########################################################################################
# Remove common intermediate files.
clean:
-rm -rf \
$(PUBLIC_DIR) \
qlib/data/_libs/*.cpp \
qlib/data/_libs/*.so \
mlruns \
public \
build \
.coverage \
.mypy_cache \
.pytest_cache \
.ruff_cache \
Pipfile* \
coverage.xml \
dist \
release-notes.md
find . -name '*.egg-info' -print0 | xargs -0 rm -rf
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -f
find . -name '__pycache__' -print0 | xargs -0 rm -rf
# Remove pre-commit hook, virtual environment alongside itermediate files.
deepclean: clean
if command -v pre-commit > /dev/null 2>&1; then pre-commit uninstall --hook-type pre-push; fi
if command -v pipenv >/dev/null 2>&1 && pipenv --venv >/dev/null 2>&1; then pipenv --rm; fi
# Prerequisite section
# What this code does is compile two Cython modules, rolling and expanding, using setuptools and Cython,
# and builds them as binary expansion modules that can be imported directly into Python.
# Since pyproject.toml can't do that, we compile it here.
# pywinpty as a dependency of jupyter on windows, if you use pip install pywinpty installation,
# will first download the tar.gz file, and then locally compiled and installed,
# this will lead to some unnecessary trouble, so we choose to install the compiled whl file, to avoid trouble.
prerequisite:
@if [ -n "$(SO_FILES)" ]; then \
echo "Shared library files exist, skipping build."; \
else \
echo "No shared library files found, building..."; \
pip install --upgrade setuptools wheel; \
python -m pip install cython numpy; \
python -c "from setuptools import setup, Extension; from Cython.Build import cythonize; import numpy; extensions = [Extension('qlib.data._libs.rolling', ['qlib/data/_libs/rolling.pyx'], language='c++', include_dirs=[numpy.get_include()]), Extension('qlib.data._libs.expanding', ['qlib/data/_libs/expanding.pyx'], language='c++', include_dirs=[numpy.get_include()])]; setup(ext_modules=cythonize(extensions, language_level='3'), script_args=['build_ext', '--inplace'])"; \
fi
@if [ "$(IS_WINDOWS)" = "true" ]; then \
python -m pip install pywinpty --only-binary=:all:; \
fi
# Install the package in editable mode.
dependencies:
python -m pip install --no-cache-dir -e .
lightgbm:
python -m pip install --no-cache-dir lightgbm --prefer-binary
rl:
python -m pip install --no-cache-dir -e .[rl]
develop:
python -m pip install --no-cache-dir -e .[dev]
lint:
python -m pip install --no-cache-dir -e .[lint]
docs:
python -m pip install --no-cache-dir -e .[docs]
package:
python -m pip install --no-cache-dir -e .[package]
test:
python -m pip install --no-cache-dir -e .[test]
analysis:
python -m pip install --no-cache-dir -e .[analysis]
client:
python -m pip install --no-cache-dir -e .[client]
all:
python -m pip install --no-cache-dir -e .[pywinpty,dev,lint,docs,package,test,analysis,rl]
install: prerequisite dependencies
dev: prerequisite all
########################################################################################
# Lint and pre-commit
########################################################################################
# Check lint with black.
black:
black . -l 120 --check --diff --exclude qlib/_version.py
# Check code folder with pylint.
# TODO: These problems we will solve in the future. Important among them are: W0221, W0223, W0237, E1102
# C0103: invalid-name
# C0209: consider-using-f-string
# R0402: consider-using-from-import
# R1705: no-else-return
# R1710: inconsistent-return-statements
# R1725: super-with-arguments
# R1735: use-dict-literal
# W0102: dangerous-default-value
# W0212: protected-access
# W0221: arguments-differ
# W0223: abstract-method
# W0231: super-init-not-called
# W0237: arguments-renamed
# W0612: unused-variable
# W0621: redefined-outer-name
# W0622: redefined-builtin
# FIXME: specify exception type
# W0703: broad-except
# W1309: f-string-without-interpolation
# E1102: not-callable
# E1136: unsubscriptable-object
# W4904: deprecated-class
# R0917: too-many-positional-arguments
# E1123: unexpected-keyword-arg
# References for disable error: https://pylint.pycqa.org/en/latest/user_guide/messages/messages_overview.html
# We use sys.setrecursionlimit(2000) to make the recursion depth larger to ensure that pylint works properly (the default recursion depth is 1000).
# References for parameters: https://github.com/PyCQA/pylint/issues/4577#issuecomment-1000245962
pylint:
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,W4904,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1730,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}' qlib --init-hook="import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,E1123,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0246,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}' scripts --init-hook="import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
# Check code with flake8.
# The following flake8 error codes were ignored:
# E501 line too long
# Description: We have used black to limit the length of each line to 120.
# F541 f-string is missing placeholders
# Description: The same thing is done when using pylint for detection.
# E266 too many leading '#' for block comment
# Description: To make the code more readable, a lot of "#" is used.
# This error code appears centrally in:
# qlib/backtest/executor.py
# qlib/data/ops.py
# qlib/utils/__init__.py
# E402 module level import not at top of file
# Description: There are times when module level import is not available at the top of the file.
# W503 line break before binary operator
# Description: Since black formats the length of each line of code, it has to perform a line break when a line of arithmetic is too long.
# E731 do not assign a lambda expression, use a def
# Description: Restricts the use of lambda expressions, but at some point lambda expressions are required.
# E203 whitespace before ':'
# Description: If there is whitespace before ":", it cannot pass the black check.
flake8:
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 --per-file-ignores="__init__.py:F401,F403" qlib
# Check code with mypy.
# https://github.com/python/mypy/issues/10600
mypy:
mypy qlib --install-types --non-interactive
mypy qlib --verbose
# Check ipynb with nbqa.
nbqa:
nbqa black . -l 120 --check --diff
nbqa pylint . --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136,W0719,W0104,W0404,C0412,W0611,C0410 --const-rgx='[a-z_][a-z0-9_]{2,30}'
# Check ipynb with nbconvert.(Run after data downloads)
# TODO: Add more ipynb files in future
nbconvert:
jupyter nbconvert --to notebook --execute examples/workflow_by_code.ipynb
lint: black pylint flake8 mypy nbqa
########################################################################################
# Package
########################################################################################
# Build the package.
build:
python -m build --wheel
# Upload the package.
upload:
python -m twine upload dist/*
########################################################################################
# Documentation
########################################################################################
docs-gen:
python -m sphinx.cmd.build -W docs $(PUBLIC_DIR)
================================================
FILE: README.md
================================================
[](https://pypi.org/project/pyqlib/#files)
[](https://pypi.org/project/pyqlib/#files)
[](https://pypi.org/project/pyqlib/#history)
[](https://pypi.org/project/pyqlib/)
[](https://github.com/microsoft/qlib/actions)
[](https://qlib.readthedocs.io/en/latest/?badge=latest)
[](LICENSE)
[](https://gitter.im/Microsoft/qlib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## :newspaper: **What's NEW!** :sparkling_heart:
Recent released features
### Introducing <a href="https://github.com/microsoft/RD-Agent"><img src="docs/_static/img/rdagent_logo.png" alt="RD_Agent" style="height: 2em"></a>: LLM-Based Autonomous Evolving Agents for Industrial Data-Driven R&D
We are excited to announce the release of **RD-Agent**📢, a powerful tool that supports automated factor mining and model optimization in quant investment R&D.
RD-Agent is now available on [GitHub](https://github.com/microsoft/RD-Agent), and we welcome your star🌟!
To learn more, please visit our [♾️Demo page](https://rdagent.azurewebsites.net/). Here, you will find demo videos in both English and Chinese to help you better understand the scenario and usage of RD-Agent.
We have prepared several demo videos for you:
| Scenario | Demo video (English) | Demo video (中文) |
| -- | ------ | ------ |
| Quant Factor Mining | [Link](https://rdagent.azurewebsites.net/factor_loop?lang=en) | [Link](https://rdagent.azurewebsites.net/factor_loop?lang=zh) |
| Quant Factor Mining from reports | [Link](https://rdagent.azurewebsites.net/report_factor?lang=en) | [Link](https://rdagent.azurewebsites.net/report_factor?lang=zh) |
| Quant Model Optimization | [Link](https://rdagent.azurewebsites.net/model_loop?lang=en) | [Link](https://rdagent.azurewebsites.net/model_loop?lang=zh) |
- 📃**Paper**: [R&D-Agent-Quant: A Multi-Agent Framework for Data-Centric Factors and Model Joint Optimization](https://arxiv.org/abs/2505.15155)
- 👾**Code**: https://github.com/microsoft/RD-Agent/
```BibTeX
@misc{li2025rdagentquant,
title={R\&D-Agent-Quant: A Multi-Agent Framework for Data-Centric Factors and Model Joint Optimization},
author={Yuante Li and Xu Yang and Xiao Yang and Minrui Xu and Xisen Wang and Weiqing Liu and Jiang Bian},
year={2025},
eprint={2505.15155},
archivePrefix={arXiv},
primaryClass={cs.AI}
}
```

***
| Feature | Status |
| -- | ------ |
| [R&D-Agent-Quant](https://arxiv.org/abs/2505.15155) Published | Apply R&D-Agent to Qlib for quant trading |
| BPQP for End-to-end learning | 📈Coming soon!([Under review](https://github.com/microsoft/qlib/pull/1863)) |
| 🔥LLM-driven Auto Quant Factory🔥 | 🚀 Released in [♾️RD-Agent](https://github.com/microsoft/RD-Agent) on Aug 8, 2024 |
| KRNN and Sandwich models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1414/) on May 26, 2023 |
| Release Qlib v0.9.0 | :octocat: [Released](https://github.com/microsoft/qlib/releases/tag/v0.9.0) on Dec 9, 2022 |
| RL Learning Framework | :hammer: :chart_with_upwards_trend: Released on Nov 10, 2022. [#1332](https://github.com/microsoft/qlib/pull/1332), [#1322](https://github.com/microsoft/qlib/pull/1322), [#1316](https://github.com/microsoft/qlib/pull/1316),[#1299](https://github.com/microsoft/qlib/pull/1299),[#1263](https://github.com/microsoft/qlib/pull/1263), [#1244](https://github.com/microsoft/qlib/pull/1244), [#1169](https://github.com/microsoft/qlib/pull/1169), [#1125](https://github.com/microsoft/qlib/pull/1125), [#1076](https://github.com/microsoft/qlib/pull/1076)|
| HIST and IGMTF models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1040) on Apr 10, 2022 |
| Qlib [notebook tutorial](https://github.com/microsoft/qlib/tree/main/examples/tutorial) | 📖 [Released](https://github.com/microsoft/qlib/pull/1037) on Apr 7, 2022 |
| Ibovespa index data | :rice: [Released](https://github.com/microsoft/qlib/pull/990) on Apr 6, 2022 |
| Point-in-Time database | :hammer: [Released](https://github.com/microsoft/qlib/pull/343) on Mar 10, 2022 |
| Arctic Provider Backend & Orderbook data example | :hammer: [Released](https://github.com/microsoft/qlib/pull/744) on Jan 17, 2022 |
| Meta-Learning-based framework & DDG-DA | :chart_with_upwards_trend: :hammer: [Released](https://github.com/microsoft/qlib/pull/743) on Jan 10, 2022 |
| Planning-based portfolio optimization | :hammer: [Released](https://github.com/microsoft/qlib/pull/754) on Dec 28, 2021 |
| Release Qlib v0.8.0 | :octocat: [Released](https://github.com/microsoft/qlib/releases/tag/v0.8.0) on Dec 8, 2021 |
| ADD model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/704) on Nov 22, 2021 |
| ADARNN model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/689) on Nov 14, 2021 |
| TCN model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/668) on Nov 4, 2021 |
| Nested Decision Framework | :hammer: [Released](https://github.com/microsoft/qlib/pull/438) on Oct 1, 2021. [Example](https://github.com/microsoft/qlib/blob/main/examples/nested_decision_execution/workflow.py) and [Doc](https://qlib.readthedocs.io/en/latest/component/highfreq.html) |
| Temporal Routing Adaptor (TRA) | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/531) on July 30, 2021 |
| Transformer & Localformer | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/508) on July 22, 2021 |
| Release Qlib v0.7.0 | :octocat: [Released](https://github.com/microsoft/qlib/releases/tag/v0.7.0) on July 12, 2021 |
| TCTS Model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/491) on July 1, 2021 |
| Online serving and automatic model rolling | :hammer: [Released](https://github.com/microsoft/qlib/pull/290) on May 17, 2021 |
| DoubleEnsemble Model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/286) on Mar 2, 2021 |
| High-frequency data processing example | :hammer: [Released](https://github.com/microsoft/qlib/pull/257) on Feb 5, 2021 |
| High-frequency trading example | :chart_with_upwards_trend: [Part of code released](https://github.com/microsoft/qlib/pull/227) on Jan 28, 2021 |
| High-frequency data(1min) | :rice: [Released](https://github.com/microsoft/qlib/pull/221) on Jan 27, 2021 |
| Tabnet Model | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/205) on Jan 22, 2021 |
Features released before 2021 are not listed here.
<p align="center">
<img src="docs/_static/img/logo/1.png" />
</p>
Qlib is an open-source, AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms, including supervised learning, market dynamics modeling, and reinforcement learning.
An increasing number of SOTA Quant research works/papers in diverse paradigms are being released in Qlib to collaboratively solve key challenges in quantitative investment. For example, 1) using supervised learning to mine the market's complex non-linear patterns from rich and heterogeneous financial data, 2) modeling the dynamic nature of the financial market using adaptive concept drift technology, and 3) using reinforcement learning to model continuous investment decisions and assist investors in optimizing their trading strategies.
It contains the full ML pipeline of data processing, model training, back-testing; and covers the entire chain of quantitative investment: alpha seeking, risk modeling, portfolio optimization, and order execution.
For more details, please refer to our paper ["Qlib: An AI-oriented Quantitative Investment Platform"](https://arxiv.org/abs/2009.11189).
<table>
<tbody>
<tr>
<th>Frameworks, Tutorial, Data & DevOps</th>
<th>Main Challenges & Solutions in Quant Research</th>
</tr>
<tr>
<td>
<li><a href="#plans"><strong>Plans</strong></a></li>
<li><a href="#framework-of-qlib">Framework of Qlib</a></li>
<li><a href="#quick-start">Quick Start</a></li>
<ul dir="auto">
<li type="circle"><a href="#installation">Installation</a> </li>
<li type="circle"><a href="#data-preparation">Data Preparation</a></li>
<li type="circle"><a href="#auto-quant-research-workflow">Auto Quant Research Workflow</a></li>
<li type="circle"><a href="#building-customized-quant-research-workflow-by-code">Building Customized Quant Research Workflow by Code</a></li></ul>
<li><a href="#quant-dataset-zoo"><strong>Quant Dataset Zoo</strong></a></li>
<li><a href="#learning-framework">Learning Framework</a></li>
<li><a href="#more-about-qlib">More About Qlib</a></li>
<li><a href="#offline-mode-and-online-mode">Offline Mode and Online Mode</a>
<ul>
<li type="circle"><a href="#performance-of-qlib-data-server">Performance of Qlib Data Server</a></li></ul>
<li><a href="#related-reports">Related Reports</a></li>
<li><a href="#contact-us">Contact Us</a></li>
<li><a href="#contributing">Contributing</a></li>
</td>
<td valign="baseline">
<li><a href="#main-challenges--solutions-in-quant-research">Main Challenges & Solutions in Quant Research</a>
<ul>
<li type="circle"><a href="#forecasting-finding-valuable-signalspatterns">Forecasting: Finding Valuable Signals/Patterns</a>
<ul>
<li type="disc"><a href="#quant-model-paper-zoo"><strong>Quant Model (Paper) Zoo</strong></a>
<ul>
<li type="circle"><a href="#run-a-single-model">Run a Single Model</a></li>
<li type="circle"><a href="#run-multiple-models">Run Multiple Models</a></li>
</ul>
</li>
</ul>
</li>
<li type="circle"><a href="#adapting-to-market-dynamics">Adapting to Market Dynamics</a></li>
<li type="circle"><a href="#reinforcement-learning-modeling-continuous-decisions">Reinforcement Learning: modeling continuous decisions</a></li>
</ul>
</li>
</td>
</tr>
</tbody>
</table>
# Plans
New features under development(order by estimated release time).
Your feedbacks about the features are very important.
<!-- | Feature | Status | -->
<!-- | -- | ------ | -->
# Framework of Qlib
<div style="align: center">
<img src="docs/_static/img/framework-abstract.jpg" />
</div>
The high-level framework of Qlib can be found above(users can find the [detailed framework](https://qlib.readthedocs.io/en/latest/introduction/introduction.html#framework) of Qlib's design when getting into nitty gritty).
The components are designed as loose-coupled modules, and each component could be used stand-alone.
Qlib provides a strong infrastructure to support Quant research. [Data](https://qlib.readthedocs.io/en/latest/component/data.html) is always an important part.
A strong learning framework is designed to support diverse learning paradigms (e.g. [reinforcement learning](https://qlib.readthedocs.io/en/latest/component/rl.html), [supervised learning](https://qlib.readthedocs.io/en/latest/component/workflow.html#model-section)) and patterns at different levels(e.g. [market dynamic modeling](https://qlib.readthedocs.io/en/latest/component/meta.html)).
By modeling the market, [trading strategies](https://qlib.readthedocs.io/en/latest/component/strategy.html) will generate trade decisions that will be executed. Multiple trading strategies and executors in different levels or granularities can be [nested to be optimized and run together](https://qlib.readthedocs.io/en/latest/component/highfreq.html).
At last, a comprehensive [analysis](https://qlib.readthedocs.io/en/latest/component/report.html) will be provided and the model can be [served online](https://qlib.readthedocs.io/en/latest/component/online.html) in a low cost.
# Quick Start
This quick start guide tries to demonstrate
1. It's very easy to build a complete Quant research workflow and try your ideas with _Qlib_.
2. Though with *public data* and *simple models*, machine learning technologies **work very well** in practical Quant investment.
Here is a quick **[demo](https://terminalizer.com/view/3f24561a4470)** shows how to install ``Qlib``, and run LightGBM with ``qrun``. **But**, please make sure you have already prepared the data following the [instruction](#data-preparation).
## Installation
This table demonstrates the supported Python version of `Qlib`:
| | install with pip | install from source | plot |
| ------------- |:---------------------:|:--------------------:|:------------------:|
| Python 3.8 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Python 3.9 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Python 3.10 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Python 3.11 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Python 3.12 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
**Note**:
1. **Conda** is suggested for managing your Python environment. In some cases, using Python outside of a `conda` environment may result in missing header files, causing the installation failure of certain packages.
2. Please pay attention that installing cython in Python 3.6 will raise some error when installing ``Qlib`` from source. If users use Python 3.6 on their machines, it is recommended to *upgrade* Python to version 3.8 or higher, or use `conda`'s Python to install ``Qlib`` from source.
### Install with pip
Users can easily install ``Qlib`` by pip according to the following command.
```bash
pip install pyqlib
```
**Note**: pip will install the latest stable qlib. However, the main branch of qlib is in active development. If you want to test the latest scripts or functions in the main branch. Please install qlib with the methods below.
### Install from source
Also, users can install the latest dev version ``Qlib`` by the source code according to the following steps:
* Before installing ``Qlib`` from source, users need to install some dependencies:
```bash
pip install numpy
pip install --upgrade cython
```
* Clone the repository and install ``Qlib`` as follows.
```bash
git clone https://github.com/microsoft/qlib.git && cd qlib
pip install . # `pip install -e .[dev]` is recommended for development. check details in docs/developer/code_standard_and_dev_guide.rst
```
**Tips**: If you fail to install `Qlib` or run the examples in your environment, comparing your steps and the [CI workflow](.github/workflows/test_qlib_from_source.yml) may help you find the problem.
**Tips for Mac**: If you are using Mac with M1, you might encounter issues in building the wheel for LightGBM, which is due to missing dependencies from OpenMP. To solve the problem, install openmp first with ``brew install libomp`` and then run ``pip install .`` to build it successfully.
## Data Preparation
❗ Due to more restrict data security policy. The official dataset is disabled temporarily. You can try [this data source](https://github.com/chenditc/investment_data/releases) contributed by the community.
Here is an example to download the latest data.
```bash
wget https://github.com/chenditc/investment_data/releases/latest/download/qlib_bin.tar.gz
mkdir -p ~/.qlib/qlib_data/cn_data
tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=1
rm -f qlib_bin.tar.gz
```
The official dataset below will resume in short future.
----
Load and prepare data by running the following code:
### Get with module
```bash
# get 1d data
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
# get 1min data
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data_1min --region cn --interval 1min
```
### Get from source
```bash
# get 1d data
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
# get 1min data
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data_1min --region cn --interval 1min
```
This dataset is created by public data collected by [crawler scripts](scripts/data_collector/), which have been released in
the same repository.
Users could create the same dataset with it. [Description of dataset](https://github.com/microsoft/qlib/tree/main/scripts/data_collector#description-of-dataset)
*Please pay **ATTENTION** that the data is collected from [Yahoo Finance](https://finance.yahoo.com/lookup), and the data might not be perfect.
We recommend users to prepare their own data if they have a high-quality dataset. For more information, users can refer to the [related document](https://qlib.readthedocs.io/en/latest/component/data.html#converting-csv-format-into-qlib-format)*.
### Automatic update of daily frequency data (from yahoo finance)
> This step is *Optional* if users only want to try their models and strategies on history data.
>
> It is recommended that users update the data manually once (--trading_date 2021-05-25) and then set it to update automatically.
>
> **NOTE**: Users can't incrementally update data based on the offline data provided by Qlib(some fields are removed to reduce the data size). Users should use [yahoo collector](https://github.com/microsoft/qlib/tree/main/scripts/data_collector/yahoo#automatic-update-of-daily-frequency-datafrom-yahoo-finance) to download Yahoo data from scratch and then incrementally update it.
>
> For more information, please refer to: [yahoo collector](https://github.com/microsoft/qlib/tree/main/scripts/data_collector/yahoo#automatic-update-of-daily-frequency-datafrom-yahoo-finance)
* Automatic update of data to the "qlib" directory each trading day(Linux)
* use *crontab*: `crontab -e`
* set up timed tasks:
```
* * * * 1-5 python <script path> update_data_to_bin --qlib_data_1d_dir <user data dir>
```
* **script path**: *scripts/data_collector/yahoo/collector.py*
* Manual update of data
```
python scripts/data_collector/yahoo/collector.py update_data_to_bin --qlib_data_1d_dir <user data dir> --trading_date <start date> --end_date <end date>
```
* *trading_date*: start of trading day
* *end_date*: end of trading day(not included)
### Checking the health of the data
* We provide a script to check the health of the data, you can run the following commands to check whether the data is healthy or not.
```
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data
```
* Of course, you can also add some parameters to adjust the test results, such as this.
```
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data --missing_data_num 30055 --large_step_threshold_volume 94485 --large_step_threshold_price 20
```
* If you want more information about `check_data_health`, please refer to the [documentation](https://qlib.readthedocs.io/en/latest/component/data.html#checking-the-health-of-the-data).
<!--
- Run the initialization code and get stock data:
```python
import qlib
from qlib.data import D
from qlib.constant import REG_CN
# Initialization
mount_path = "~/.qlib/qlib_data/cn_data" # target_dir
qlib.init(mount_path=mount_path, region=REG_CN)
# Get stock data by Qlib
# Load trading calendar with the given time range and frequency
print(D.calendar(start_time='2010-01-01', end_time='2017-12-31', freq='day')[:2])
# Parse a given market name into a stockpool config
instruments = D.instruments('csi500')
print(D.list_instruments(instruments=instruments, start_time='2010-01-01', end_time='2017-12-31', as_list=True)[:6])
# Load features of certain instruments in given time range
instruments = ['SH600000']
fields = ['$close', '$volume', 'Ref($close, 1)', 'Mean($close, 3)', '$high-$low']
print(D.features(instruments, fields, start_time='2010-01-01', end_time='2017-12-31', freq='day').head())
```
-->
## Docker images
1. Pulling a docker image from a docker hub repository
```bash
docker pull pyqlib/qlib_image_stable:stable
```
2. Start a new Docker container
```bash
docker run -it --name <container name> -v <Mounted local directory>:/app pyqlib/qlib_image_stable:stable
```
3. At this point you are in the docker environment and can run the qlib scripts. An example:
```bash
>>> python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
>>> python qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
```
4. Exit the container
```bash
>>> exit
```
5. Restart the container
```bash
docker start -i -a <container name>
```
6. Stop the container
```bash
docker stop <container name>
```
7. Delete the container
```bash
docker rm <container name>
```
8. If you want to know more information, please refer to the [documentation](https://qlib.readthedocs.io/en/latest/developer/how_to_build_image.html).
## Auto Quant Research Workflow
Qlib provides a tool named `qrun` to run the whole workflow automatically (including building dataset, training models, backtest and evaluation). You can start an auto quant research workflow and have a graphical reports analysis according to the following steps:
1. Quant Research Workflow: Run `qrun` with lightgbm workflow config ([workflow_config_lightgbm_Alpha158.yaml](examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml) as following.
```bash
cd examples # Avoid running program under the directory contains `qlib`
qrun benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
```
If users want to use `qrun` under debug mode, please use the following command:
```bash
python -m pdb qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
```
The result of `qrun` is as follows, please refer to [docs](https://qlib.readthedocs.io/en/latest/component/strategy.html#result) for more explanations about the result.
```bash
'The following are analysis results of the excess return without cost.'
risk
mean 0.000708
std 0.005626
annualized_return 0.178316
information_ratio 1.996555
max_drawdown -0.081806
'The following are analysis results of the excess return with cost.'
risk
mean 0.000512
std 0.005626
annualized_return 0.128982
information_ratio 1.444287
max_drawdown -0.091078
```
Here are detailed documents for `qrun` and [workflow](https://qlib.readthedocs.io/en/latest/component/workflow.html).
2. Graphical Reports Analysis: First, run `python -m pip install .[analysis]` to install the required dependencies. Then run `examples/workflow_by_code.ipynb` with `jupyter notebook` to get graphical reports.
- Forecasting signal (model prediction) analysis
- Cumulative Return of groups

- Return distribution

- Information Coefficient (IC)



- Auto Correlation of forecasting signal (model prediction)

- Portfolio analysis
- Backtest return

<!--
- Score IC

- Cumulative Return

- Risk Analysis

- Rank Label

-->
- [Explanation](https://qlib.readthedocs.io/en/latest/component/report.html) of above results
## Building Customized Quant Research Workflow by Code
The automatic workflow may not suit the research workflow of all Quant researchers. To support a flexible Quant research workflow, Qlib also provides a modularized interface to allow researchers to build their own workflow by code. [Here](examples/workflow_by_code.ipynb) is a demo for customized Quant research workflow by code.
# Main Challenges & Solutions in Quant Research
Quant investment is a very unique scenario with lots of key challenges to be solved.
Currently, Qlib provides some solutions for several of them.
## Forecasting: Finding Valuable Signals/Patterns
Accurate forecasting of the stock price trend is a very important part to construct profitable portfolios.
However, huge amount of data with various formats in the financial market which make it challenging to build forecasting models.
An increasing number of SOTA Quant research works/papers, which focus on building forecasting models to mine valuable signals/patterns in complex financial data, are released in `Qlib`
### [Quant Model (Paper) Zoo](examples/benchmarks)
Here is a list of models built on `Qlib`.
- [GBDT based on XGBoost (Tianqi Chen, et al. KDD 2016)](examples/benchmarks/XGBoost/)
- [GBDT based on LightGBM (Guolin Ke, et al. NIPS 2017)](examples/benchmarks/LightGBM/)
- [GBDT based on Catboost (Liudmila Prokhorenkova, et al. NIPS 2018)](examples/benchmarks/CatBoost/)
- [MLP based on pytorch](examples/benchmarks/MLP/)
- [LSTM based on pytorch (Sepp Hochreiter, et al. Neural computation 1997)](examples/benchmarks/LSTM/)
- [GRU based on pytorch (Kyunghyun Cho, et al. 2014)](examples/benchmarks/GRU/)
- [ALSTM based on pytorch (Yao Qin, et al. IJCAI 2017)](examples/benchmarks/ALSTM)
- [GATs based on pytorch (Petar Velickovic, et al. 2017)](examples/benchmarks/GATs/)
- [SFM based on pytorch (Liheng Zhang, et al. KDD 2017)](examples/benchmarks/SFM/)
- [TFT based on tensorflow (Bryan Lim, et al. International Journal of Forecasting 2019)](examples/benchmarks/TFT/)
- [TabNet based on pytorch (Sercan O. Arik, et al. AAAI 2019)](examples/benchmarks/TabNet/)
- [DoubleEnsemble based on LightGBM (Chuheng Zhang, et al. ICDM 2020)](examples/benchmarks/DoubleEnsemble/)
- [TCTS based on pytorch (Xueqing Wu, et al. ICML 2021)](examples/benchmarks/TCTS/)
- [Transformer based on pytorch (Ashish Vaswani, et al. NeurIPS 2017)](examples/benchmarks/Transformer/)
- [Localformer based on pytorch (Juyong Jiang, et al.)](examples/benchmarks/Localformer/)
- [TRA based on pytorch (Hengxu, Dong, et al. KDD 2021)](examples/benchmarks/TRA/)
- [TCN based on pytorch (Shaojie Bai, et al. 2018)](examples/benchmarks/TCN/)
- [ADARNN based on pytorch (YunTao Du, et al. 2021)](examples/benchmarks/ADARNN/)
- [ADD based on pytorch (Hongshun Tang, et al.2020)](examples/benchmarks/ADD/)
- [IGMTF based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/IGMTF/)
- [HIST based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/HIST/)
- [KRNN based on pytorch](examples/benchmarks/KRNN/)
- [Sandwich based on pytorch](examples/benchmarks/Sandwich/)
Your PR of new Quant models is highly welcomed.
The performance of each model on the `Alpha158` and `Alpha360` datasets can be found [here](examples/benchmarks/README.md).
### Run a single model
All the models listed above are runnable with ``Qlib``. Users can find the config files we provide and some details about the model through the [benchmarks](examples/benchmarks) folder. More information can be retrieved at the model files listed above.
`Qlib` provides three different ways to run a single model, users can pick the one that fits their cases best:
- Users can use the tool `qrun` mentioned above to run a model's workflow based from a config file.
- Users can create a `workflow_by_code` python script based on the [one](examples/workflow_by_code.py) listed in the `examples` folder.
- Users can use the script [`run_all_model.py`](examples/run_all_model.py) listed in the `examples` folder to run a model. Here is an example of the specific shell command to be used: `python run_all_model.py run --models=lightgbm`, where the `--models` arguments can take any number of models listed above(the available models can be found in [benchmarks](examples/benchmarks/)). For more use cases, please refer to the file's [docstrings](examples/run_all_model.py).
- **NOTE**: Each baseline has different environment dependencies, please make sure that your python version aligns with the requirements(e.g. TFT only supports Python 3.6~3.7 due to the limitation of `tensorflow==1.15.0`)
### Run multiple models
`Qlib` also provides a script [`run_all_model.py`](examples/run_all_model.py) which can run multiple models for several iterations. (**Note**: the script only support *Linux* for now. Other OS will be supported in the future. Besides, it doesn't support parallel running the same model for multiple times as well, and this will be fixed in the future development too.)
The script will create a unique virtual environment for each model, and delete the environments after training. Thus, only experiment results such as `IC` and `backtest` results will be generated and stored.
Here is an example of running all the models for 10 iterations:
```python
python run_all_model.py run 10
```
It also provides the API to run specific models at once. For more use cases, please refer to the file's [docstrings](examples/run_all_model.py).
### Break change
In `pandas`, `group_key` is one of the parameters of the `groupby` method. From version 1.5 to 2.0 of `pandas`, the default value of `group_key` has been changed from `no default` to `True`, which will cause qlib to report an error during operation. So we set `group_key=False`, but it doesn't guarantee that some programmes will run correctly, including:
* qlib\examples\rl_order_execution\scripts\gen_training_orders.py
* qlib\examples\benchmarks\TRA\src\dataset.MTSDatasetH.py
* qlib\examples\benchmarks\TFT\tft.py
## [Adapting to Market Dynamics](examples/benchmarks_dynamic)
Due to the non-stationary nature of the environment of the financial market, the data distribution may change in different periods, which makes the performance of models build on training data decays in the future test data.
So adapting the forecasting models/strategies to market dynamics is very important to the model/strategies' performance.
Here is a list of solutions built on `Qlib`.
- [Rolling Retraining](examples/benchmarks_dynamic/baseline/)
- [DDG-DA on pytorch (Wendi, et al. AAAI 2022)](examples/benchmarks_dynamic/DDG-DA/)
## Reinforcement Learning: modeling continuous decisions
Qlib now supports reinforcement learning, a feature designed to model continuous investment decisions. This functionality assists investors in optimizing their trading strategies by learning from interactions with the environment to maximize some notion of cumulative reward.
Here is a list of solutions built on `Qlib` categorized by scenarios.
### [RL for order execution](examples/rl_order_execution)
[Here](https://qlib.readthedocs.io/en/latest/component/rl/overall.html#order-execution) is the introduction of this scenario. All the methods below are compared [here](examples/rl_order_execution).
- [TWAP](examples/rl_order_execution/exp_configs/backtest_twap.yml)
- [PPO: "An End-to-End Optimal Trade Execution Framework based on Proximal Policy Optimization", IJCAL 2020](examples/rl_order_execution/exp_configs/backtest_ppo.yml)
- [OPDS: "Universal Trading for Order Execution with Oracle Policy Distillation", AAAI 2021](examples/rl_order_execution/exp_configs/backtest_opds.yml)
# Quant Dataset Zoo
Dataset plays a very important role in Quant. Here is a list of the datasets built on `Qlib`:
| Dataset | US Market | China Market |
| -- | -- | -- |
| [Alpha360](./qlib/contrib/data/handler.py) | √ | √ |
| [Alpha158](./qlib/contrib/data/handler.py) | √ | √ |
[Here](https://qlib.readthedocs.io/en/latest/advanced/alpha.html) is a tutorial to build dataset with `Qlib`.
Your PR to build new Quant dataset is highly welcomed.
# Learning Framework
Qlib is high customizable and a lot of its components are learnable.
The learnable components are instances of `Forecast Model` and `Trading Agent`. They are learned based on the `Learning Framework` layer and then applied to multiple scenarios in `Workflow` layer.
The learning framework leverages the `Workflow` layer as well(e.g. sharing `Information Extractor`, creating environments based on `Execution Env`).
Based on learning paradigms, they can be categorized into reinforcement learning and supervised learning.
- For supervised learning, the detailed docs can be found [here](https://qlib.readthedocs.io/en/latest/component/model.html).
- For reinforcement learning, the detailed docs can be found [here](https://qlib.readthedocs.io/en/latest/component/rl.html). Qlib's RL learning framework leverages `Execution Env` in `Workflow` layer to create environments. It's worth noting that `NestedExecutor` is supported as well. This empowers users to optimize different level of strategies/models/agents together (e.g. optimizing an order execution strategy for a specific portfolio management strategy).
# More About Qlib
If you want to have a quick glance at the most frequently used components of qlib, you can try notebooks [here](examples/tutorial/).
The detailed documents are organized in [docs](docs/).
[Sphinx](http://www.sphinx-doc.org) and the readthedocs theme is required to build the documentation in html formats.
```bash
cd docs/
conda install sphinx sphinx_rtd_theme -y
# Otherwise, you can install them with pip
# pip install sphinx sphinx_rtd_theme
make html
```
You can also view the [latest document](http://qlib.readthedocs.io/) online directly.
Qlib is in active and continuing development. Our plan is in the roadmap, which is managed as a [github project](https://github.com/microsoft/qlib/projects/1).
# Offline Mode and Online Mode
The data server of Qlib can either deployed as `Offline` mode or `Online` mode. The default mode is offline mode.
Under `Offline` mode, the data will be deployed locally.
Under `Online` mode, the data will be deployed as a shared data service. The data and their cache will be shared by all the clients. The data retrieval performance is expected to be improved due to a higher rate of cache hits. It will consume less disk space, too. The documents of the online mode can be found in [Qlib-Server](https://qlib-server.readthedocs.io/). The online mode can be deployed automatically with [Azure CLI based scripts](https://qlib-server.readthedocs.io/en/latest/build.html#one-click-deployment-in-azure). The source code of online data server can be found in [Qlib-Server repository](https://github.com/microsoft/qlib-server).
## Performance of Qlib Data Server
The performance of data processing is important to data-driven methods like AI technologies. As an AI-oriented platform, Qlib provides a solution for data storage and data processing. To demonstrate the performance of Qlib data server, we
compare it with several other data storage solutions.
We evaluate the performance of several storage solutions by finishing the same task,
which creates a dataset (14 features/factors) from the basic OHLCV daily data of a stock market (800 stocks each day from 2007 to 2020). The task involves data queries and processing.
| | HDF5 | MySQL | MongoDB | InfluxDB | Qlib -E -D | Qlib +E -D | Qlib +E +D |
| -- | ------ | ------ | -------- | --------- | ----------- | ------------ | ----------- |
| Total (1CPU) (seconds) | 184.4±3.7 | 365.3±7.5 | 253.6±6.7 | 368.2±3.6 | 147.0±8.8 | 47.6±1.0 | **7.4±0.3** |
| Total (64CPU) (seconds) | | | | | 8.8±0.6 | **4.2±0.2** | |
* `+(-)E` indicates with (out) `ExpressionCache`
* `+(-)D` indicates with (out) `DatasetCache`
Most general-purpose databases take too much time to load data. After looking into the underlying implementation, we find that data go through too many layers of interfaces and unnecessary format transformations in general-purpose database solutions.
Such overheads greatly slow down the data loading process.
Qlib data are stored in a compact format, which is efficient to be combined into arrays for scientific computation.
# Related Reports
- [Guide To Qlib: Microsoft’s AI Investment Platform](https://analyticsindiamag.com/qlib/)
- [微软也搞AI量化平台?还是开源的!](https://mp.weixin.qq.com/s/47bP5YwxfTp2uTHjUBzJQQ)
- [微矿Qlib:业内首个AI量化投资开源平台](https://mp.weixin.qq.com/s/vsJv7lsgjEi-ALYUz4CvtQ)
# Contact Us
- If you have any issues, please create issue [here](https://github.com/microsoft/qlib/issues/new/choose) or send messages in [gitter](https://gitter.im/Microsoft/qlib).
- If you want to make contributions to `Qlib`, please [create pull requests](https://github.com/microsoft/qlib/compare).
- For other reasons, you are welcome to contact us by email([qlib@microsoft.com](mailto:qlib@microsoft.com)).
- We are recruiting new members(both FTEs and interns), your resumes are welcome!
Join IM discussion groups:
|[Gitter](https://gitter.im/Microsoft/qlib)|
|----|
||
# Contributing
We appreciate all contributions and thank all the contributors!
<a href="https://github.com/microsoft/qlib/graphs/contributors"><img src="https://contrib.rocks/image?repo=microsoft/qlib" /></a>
Before we released Qlib as an open-source project on Github in Sep 2020, Qlib is an internal project in our group. Unfortunately, the internal commit history is not kept. A lot of members in our group have also contributed a lot to Qlib, which includes Ruihua Wang, Yinda Zhang, Haisu Yu, Shuyu Wang, Bochen Pang, and [Dong Zhou](https://github.com/evanzd/evanzd). Especially thanks to [Dong Zhou](https://github.com/evanzd/evanzd) due to his initial version of Qlib.
## Guidance
This project welcomes contributions and suggestions.
**Here are some
[code standards and development guidance](docs/developer/code_standard_and_dev_guide.rst) for submiting a pull request.**
Making contributions is not a hard thing. Solving an issue(maybe just answering a question raised in [issues list](https://github.com/microsoft/qlib/issues) or [gitter](https://gitter.im/Microsoft/qlib)), fixing/issuing a bug, improving the documents and even fixing a typo are important contributions to Qlib.
For example, if you want to contribute to Qlib's document/code, you can follow the steps in the figure below.
<p align="center">
<img src="https://github.com/demon143/qlib/blob/main/docs/_static/img/change%20doc.gif" />
</p>
If you don't know how to start to contribute, you can refer to the following examples.
| Type | Examples |
| -- | -- |
| Solving issues | [Answer a question](https://github.com/microsoft/qlib/issues/749); [issuing](https://github.com/microsoft/qlib/issues/765) or [fixing](https://github.com/microsoft/qlib/pull/792) a bug |
| Docs | [Improve docs quality](https://github.com/microsoft/qlib/pull/797/files) ; [Fix a typo](https://github.com/microsoft/qlib/pull/774) |
| Feature | Implement a [requested feature](https://github.com/microsoft/qlib/projects) like [this](https://github.com/microsoft/qlib/pull/754); [Refactor interfaces](https://github.com/microsoft/qlib/pull/539/files) |
| Dataset | [Add a dataset](https://github.com/microsoft/qlib/pull/733) |
| Models | [Implement a new model](https://github.com/microsoft/qlib/pull/689), [some instructions to contribute models](https://github.com/microsoft/qlib/tree/main/examples/benchmarks#contributing) |
[Good first issues](https://github.com/microsoft/qlib/labels/good%20first%20issue) are labelled to indicate that they are easy to start your contributions.
You can find some impefect implementation in Qlib by `rg 'TODO|FIXME' qlib`
If you would like to become one of Qlib's maintainers to contribute more (e.g. help merge PR, triage issues), please contact us by email([qlib@microsoft.com](mailto:qlib@microsoft.com)). We are glad to help to upgrade your permission.
## License
Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the right to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
================================================
FILE: SECURITY.md
================================================
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->
================================================
FILE: build_docker_image.sh
================================================
#!/bin/bash
docker_user="your_dockerhub_username"
read -p "Do you want to build the nightly version of the qlib image? (default is stable) (yes/no): " answer;
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
if [ "$answer" = "yes" ]; then
# Build the nightly version of the qlib image
docker build --build-arg IS_STABLE=no -t qlib_image -f ./Dockerfile .
image_tag="nightly"
else
# Build the stable version of the qlib image
docker build -t qlib_image -f ./Dockerfile .
image_tag="stable"
fi
read -p "Is it uploaded to docker hub? (default is no) (yes/no): " answer;
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
if [ "$answer" = "yes" ]; then
# Log in to Docker Hub
# If you are a new docker hub user, please verify your email address before proceeding with this step.
docker login
# Tag the Docker image
docker tag qlib_image "$docker_user/qlib_image:$image_tag"
# Push the Docker image to Docker Hub
docker push "$docker_user/qlib_image:$image_tag"
else
echo "Not uploaded to docker hub."
fi
================================================
FILE: docs/FAQ/FAQ.rst
================================================
Qlib FAQ
############
Qlib Frequently Asked Questions
===============================
.. contents::
:depth: 1
:local:
:backlinks: none
------
1. RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase...
-----------------------------------------------------------------------------------------------------------------------------------
.. code-block:: console
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
This is caused by the limitation of multiprocessing under windows OS. Please refer to `here <https://stackoverflow.com/a/24374798>`_ for more info.
**Solution**: To select a start method you use the ``D.features`` in the if __name__ == '__main__' clause of the main module. For example:
.. code-block:: python
import qlib
from qlib.data import D
if __name__ == "__main__":
qlib.init()
instruments = ["SH600000"]
fields = ["$close", "$change"]
df = D.features(instruments, fields, start_time='2010-01-01', end_time='2012-12-31')
print(df.head())
2. qlib.data.cache.QlibCacheException: It sees the key(...) of the redis lock has existed in your redis db now.
---------------------------------------------------------------------------------------------------------------
It sees the key of the redis lock has existed in your redis db now. You can use the following command to clear your redis keys and rerun your commands
.. code-block:: console
$ redis-cli
> select 1
> flushdb
If the issue is not resolved, use ``keys *`` to find if multiple keys exist. If so, try using ``flushall`` to clear all the keys.
.. note::
``qlib.config.redis_task_db`` defaults is ``1``, users can use ``qlib.init(redis_task_db=<other_db>)`` settings.
Also, feel free to post a new issue in our GitHub repository. We always check each issue carefully and try our best to solve them.
3. ModuleNotFoundError: No module named 'qlib.data._libs.rolling'
-----------------------------------------------------------------
.. code-block:: python
#### Do not import qlib package in the repository directory in case of importing qlib from . without compiling #####
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "qlib/qlib/__init__.py", line 19, in init
from .data.cache import H
File "qlib/qlib/data/__init__.py", line 8, in <module>
from .data import (
File "qlib/qlib/data/data.py", line 20, in <module>
from .cache import H
File "qlib/qlib/data/cache.py", line 36, in <module>
from .ops import Operators
File "qlib/qlib/data/ops.py", line 19, in <module>
from ._libs.rolling import rolling_slope, rolling_rsquare, rolling_resi
ModuleNotFoundError: No module named 'qlib.data._libs.rolling'
- If the error occurs when importing ``qlib`` package with ``PyCharm`` IDE, users can execute the following command in the project root folder to compile Cython files and generate executable files:
.. code-block:: bash
python setup.py build_ext --inplace
- If the error occurs when importing ``qlib`` package with command ``python`` , users need to change the running directory to ensure that the script does not run in the project directory.
4. BadNamespaceError: / is not a connected namespace
----------------------------------------------------
.. code-block:: python
File "qlib_online.py", line 35, in <module>
cal = D.calendar()
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 973, in calendar
return Cal.calendar(start_time, end_time, freq, future=future)
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 798, in calendar
self.conn.send_request(
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\client.py", line 101, in send_request
self.sio.emit(request_type + "_request", request_content)
File "G:\apps\miniconda\envs\qlib\lib\site-packages\python_socketio-5.3.0-py3.8.egg\socketio\client.py", line 369, in emit
raise exceptions.BadNamespaceError(
BadNamespaceError: / is not a connected namespace.
- The version of ``python-socketio`` in qlib needs to be the same as the version of ``python-socketio`` in qlib-server:
.. code-block:: bash
pip install -U python-socketio==<qlib-server python-socketio version>
5. TypeError: send() got an unexpected keyword argument 'binary'
----------------------------------------------------------------
.. code-block:: python
File "qlib_online.py", line 35, in <module>
cal = D.calendar()
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 973, in calendar
return Cal.calendar(start_time, end_time, freq, future=future)
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 798, in calendar
self.conn.send_request(
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\client.py", line 101, in send_request
self.sio.emit(request_type + "_request", request_content)
File "G:\apps\miniconda\envs\qlib\lib\site-packages\socketio\client.py", line 263, in emit
self._send_packet(packet.Packet(packet.EVENT, namespace=namespace,
File "G:\apps\miniconda\envs\qlib\lib\site-packages\socketio\client.py", line 339, in _send_packet
self.eio.send(ep, binary=binary)
TypeError: send() got an unexpected keyword argument 'binary'
- The ``python-engineio`` version needs to be compatible with the ``python-socketio`` version, reference: https://github.com/miguelgrinberg/python-socketio#version-compatibility
.. code-block:: bash
pip install -U python-engineio==<compatible python-socketio version>
# or
pip install -U python-socketio==3.1.2 python-engineio==3.13.2
================================================
FILE: docs/Makefile
================================================
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python3 -msphinx
SPHINXPROJ = Quantlab
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
pip install -r requirements.txt
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
================================================
FILE: docs/_static/demo.sh
================================================
#!/bin/sh
git clone https://github.com/microsoft/qlib.git
cd qlib
ls
pip install pyqlib
# or
# pip install numpy
# pip install --upgrade cython
# python setup.py install
cd examples
ls
qrun benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
================================================
FILE: docs/advanced/PIT.rst
================================================
.. _pit:
============================
(P)oint-(I)n-(T)ime Database
============================
.. currentmodule:: qlib
Introduction
------------
Point-in-time data is a very important consideration when performing any sort of historical market analysis.
For example, let’s say we are backtesting a trading strategy and we are using the past five years of historical data as our input.
Our model is assumed to trade once a day, at the market close, and we’ll say we are calculating the trading signal for 1 January 2020 in our backtest. At that point, we should only have data for 1 January 2020, 31 December 2019, 30 December 2019 etc.
In financial data (especially financial reports), the same piece of data may be amended for multiple times overtime. If we only use the latest version for historical backtesting, data leakage will happen.
Point-in-time database is designed for solving this problem to make sure user get the right version of data at any historical timestamp. It will keep the performance of online trading and historical backtesting the same.
Data Preparation
----------------
Qlib provides a crawler to help users to download financial data and then a converter to dump the data in Qlib format.
Please follow `scripts/data_collector/pit/README.md <https://github.com/microsoft/qlib/tree/main/scripts/data_collector/pit/>`_ to download and convert data.
Besides, you can find some additional usage examples there.
File-based design for PIT data
------------------------------
Qlib provides a file-based storage for PIT data.
For each feature, it contains 4 columns, i.e. date, period, value, _next.
Each row corresponds to a statement.
The meaning of each feature with filename like `XXX_a.data`:
- `date`: the statement's date of publication.
- `period`: the period of the statement. (e.g. it will be quarterly frequency in most of the markets)
- If it is an annual period, it will be an integer corresponding to the year
- If it is an quarterly periods, it will be an integer like `<year><index of quarter>`. The last two decimal digits represents the index of quarter. Others represent the year.
- `value`: the described value
- `_next`: the byte index of the next occurance of the field.
Besides the feature data, an index `XXX_a.index` is included to speed up the querying performance
The statements are soted by the `date` in ascending order from the beginning of the file.
.. code-block:: python
# the data format from XXXX.data
array([(20070428, 200701, 0.090219 , 4294967295),
(20070817, 200702, 0.13933 , 4294967295),
(20071023, 200703, 0.24586301, 4294967295),
(20080301, 200704, 0.3479 , 80),
(20080313, 200704, 0.395989 , 4294967295),
(20080422, 200801, 0.100724 , 4294967295),
(20080828, 200802, 0.24996801, 4294967295),
(20081027, 200803, 0.33412001, 4294967295),
(20090325, 200804, 0.39011699, 4294967295),
(20090421, 200901, 0.102675 , 4294967295),
(20090807, 200902, 0.230712 , 4294967295),
(20091024, 200903, 0.30072999, 4294967295),
(20100402, 200904, 0.33546099, 4294967295),
(20100426, 201001, 0.083825 , 4294967295),
(20100812, 201002, 0.200545 , 4294967295),
(20101029, 201003, 0.260986 , 4294967295),
(20110321, 201004, 0.30739301, 4294967295),
(20110423, 201101, 0.097411 , 4294967295),
(20110831, 201102, 0.24825101, 4294967295),
(20111018, 201103, 0.318919 , 4294967295),
(20120323, 201104, 0.4039 , 420),
(20120411, 201104, 0.403925 , 4294967295),
(20120426, 201201, 0.112148 , 4294967295),
(20120810, 201202, 0.26484701, 4294967295),
(20121026, 201203, 0.370487 , 4294967295),
(20130329, 201204, 0.45004699, 4294967295),
(20130418, 201301, 0.099958 , 4294967295),
(20130831, 201302, 0.21044201, 4294967295),
(20131016, 201303, 0.30454299, 4294967295),
(20140325, 201304, 0.394328 , 4294967295),
(20140425, 201401, 0.083217 , 4294967295),
(20140829, 201402, 0.16450299, 4294967295),
(20141030, 201403, 0.23408499, 4294967295),
(20150421, 201404, 0.319612 , 4294967295),
(20150421, 201501, 0.078494 , 4294967295),
(20150828, 201502, 0.137504 , 4294967295),
(20151023, 201503, 0.201709 , 4294967295),
(20160324, 201504, 0.26420501, 4294967295),
(20160421, 201601, 0.073664 , 4294967295),
(20160827, 201602, 0.136576 , 4294967295),
(20161029, 201603, 0.188062 , 4294967295),
(20170415, 201604, 0.244385 , 4294967295),
(20170425, 201701, 0.080614 , 4294967295),
(20170728, 201702, 0.15151 , 4294967295),
(20171026, 201703, 0.25416601, 4294967295),
(20180328, 201704, 0.32954201, 4294967295),
(20180428, 201801, 0.088887 , 4294967295),
(20180802, 201802, 0.170563 , 4294967295),
(20181029, 201803, 0.25522 , 4294967295),
(20190329, 201804, 0.34464401, 4294967295),
(20190425, 201901, 0.094737 , 4294967295),
(20190713, 201902, 0. , 1040),
(20190718, 201902, 0.175322 , 4294967295),
(20191016, 201903, 0.25581899, 4294967295)],
dtype=[('date', '<u4'), ('period', '<u4'), ('value', '<f8'), ('_next', '<u4')])
# - each row contains 20 byte
# The data format from XXXX.index. It consists of two parts
# 1) the start index of the data. So the first part of the info will be like
2007
# 2) the remain index data will be like information below
# - The data indicate the **byte index** of first data update of a period.
# - e.g. Because the info at both byte 80 and 100 corresponds to 200704. The byte index of first occurance (i.e. 100) is recorded in the data.
array([ 0, 20, 40, 60, 100,
120, 140, 160, 180, 200,
220, 240, 260, 280, 300,
320, 340, 360, 380, 400,
440, 460, 480, 500, 520,
540, 560, 580, 600, 620,
640, 660, 680, 700, 720,
740, 760, 780, 800, 820,
840, 860, 880, 900, 920,
940, 960, 980, 1000, 1020,
1060, 4294967295], dtype=uint32)
Known limitations:
- Currently, the PIT database is designed for quarterly or annually factors, which can handle fundamental data of financial reports in most markets.
- Qlib leverage the file name to identify the type of the data. File with name like `XXX_q.data` corresponds to quarterly data. File with name like `XXX_a.data` corresponds to annual data.
- The caclulation of PIT is not performed in the optimal way. There is great potential to boost the performance of PIT data calcuation.
================================================
FILE: docs/advanced/alpha.rst
================================================
.. _alpha:
=========================
Building Formulaic Alphas
=========================
.. currentmodule:: qlib
Introduction
============
In quantitative trading practice, designing novel factors that can explain and predict future asset returns are of vital importance to the profitability of a strategy. Such factors are usually called alpha factors, or alphas in short.
A formulaic alpha, as the name suggests, is a kind of alpha that can be presented as a formula or a mathematical expression.
Building Formulaic Alphas in ``Qlib``
=====================================
In ``Qlib``, users can easily build formulaic alphas.
Example
-------
`MACD`, short for moving average convergence/divergence, is a formulaic alpha used in technical analysis of stock prices. It is designed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock's price.
`MACD` can be presented as the following formula:
.. math::
MACD = 2\times (DIF-DEA)
.. note::
`DIF` means Differential value, which is 12-period EMA minus 26-period EMA.
.. math::
DIF = \frac{EMA(CLOSE, 12) - EMA(CLOSE, 26)}{CLOSE}
`DEA` means a 9-period EMA of the DIF.
.. math::
DEA = EMA(DIF, 9)
Users can use ``Data Handler`` to build formulaic alphas `MACD` in qlib:
.. note:: Users need to initialize ``Qlib`` with `qlib.init` first. Please refer to `initialization <../start/initialization.html>`_.
.. code-block:: python
>> from qlib.data.dataset.loader import QlibDataLoader
>> MACD_EXP = '2 * ((EMA($close, 12) - EMA($close, 26))/$close - EMA((EMA($close, 12) - EMA($close, 26))/$close, 9))'
>> fields = [MACD_EXP] # MACD
>> names = ['MACD']
>> labels = ['Ref($close, -2)/Ref($close, -1) - 1'] # label
>> label_names = ['LABEL']
>> data_loader_config = {
.. "feature": (fields, names),
.. "label": (labels, label_names)
.. }
>> data_loader = QlibDataLoader(config=data_loader_config)
>> df = data_loader.load(instruments='csi300', start_time='2010-01-01', end_time='2017-12-31')
>> print(df)
feature label
MACD LABEL
datetime instrument
2010-01-04 SH600000 0.008781 -0.019672
SH600004 0.006699 -0.014721
SH600006 0.005714 0.002911
SH600008 0.000798 0.009818
SH600009 0.017015 -0.017758
... ... ...
2017-12-29 SZ300124 0.015071 -0.005074
SZ300136 -0.015466 0.056352
SZ300144 0.013082 0.011853
SZ300251 -0.001026 0.021739
SZ300315 -0.007559 0.012455
Reference
=========
To learn more about ``Data Loader``, please refer to `Data Loader <../component/data.html#data-loader>`_
To learn more about ``Data API``, please refer to `Data API <../component/data.html>`_
================================================
FILE: docs/advanced/serial.rst
================================================
.. _serial:
=============
Serialization
=============
.. currentmodule:: qlib
Introduction
============
``Qlib`` supports dumping the state of ``DataHandler``, ``DataSet``, ``Processor`` and ``Model``, etc. into a disk and reloading them.
Serializable Class
==================
``Qlib`` provides a base class ``qlib.utils.serial.Serializable``, whose state can be dumped into or loaded from disk in `pickle` format.
When users dump the state of a ``Serializable`` instance, the attributes of the instance whose name **does not** start with `_` will be saved on the disk.
However, users can use ``config`` method or override ``default_dump_all`` attribute to prevent this feature.
Users can also override ``pickle_backend`` attribute to choose a pickle backend. The supported value is "pickle" (default and common) and "dill" (dump more things such as function, more information in `here <https://pypi.org/project/dill/>`_).
Example
=======
``Qlib``'s serializable class includes ``DataHandler``, ``DataSet``, ``Processor`` and ``Model``, etc., which are subclass of ``qlib.utils.serial.Serializable``.
Specifically, ``qlib.data.dataset.DatasetH`` is one of them. Users can serialize ``DatasetH`` as follows.
.. code-block:: Python
##=============dump dataset=============
dataset.to_pickle(path="dataset.pkl") # dataset is an instance of qlib.data.dataset.DatasetH
##=============reload dataset=============
with open("dataset.pkl", "rb") as file_dataset:
dataset = pickle.load(file_dataset)
.. note::
Only state of ``DatasetH`` should be saved on the disk, such as some `mean` and `variance` used for data normalization, etc.
After reloading the ``DatasetH``, users need to reinitialize it. It means that users can reset some states of ``DatasetH`` or ``QlibDataHandler`` such as `instruments`, `start_time`, `end_time` and `segments`, etc., and generate new data according to the states (data is not state and should not be saved on the disk).
A more detailed example is in this `link <https://github.com/microsoft/qlib/tree/main/examples/highfreq>`_.
API
===
Please refer to `Serializable API <../reference/api.html#module-qlib.utils.serial.Serializable>`_.
================================================
FILE: docs/advanced/server.rst
================================================
.. _server:
=============================
``Online`` & ``Offline`` mode
=============================
.. currentmodule:: qlib
Introduction
============
``Qlib`` supports ``Online`` mode and ``Offline`` mode. Only the ``Offline`` mode is introduced in this document.
The ``Online`` mode is designed to solve the following problems:
- Manage the data in a centralized way. Users don't have to manage data of different versions.
- Reduce the amount of cache to be generated.
- Make the data can be accessed in a remote way.
Qlib-Server
===========
``Qlib-Server`` is the assorted server system for ``Qlib``, which utilizes ``Qlib`` for basic calculations and provides extensive server system and cache mechanism. With QLibServer, the data provided for ``Qlib`` can be managed in a centralized manner. With ``Qlib-Server``, users can use ``Qlib`` in ``Online`` mode.
Reference
=========
If users are interested in ``Qlib-Server`` and ``Online`` mode, please refer to `Qlib-Server Project <https://github.com/microsoft/qlib-server>`_ and `Qlib-Server Document <https://qlib-server.readthedocs.io/en/latest/>`_.
================================================
FILE: docs/advanced/task_management.rst
================================================
.. _task_management:
===============
Task Management
===============
.. currentmodule:: qlib
Introduction
============
The `Workflow <../component/introduction.html>`_ part introduces how to run research workflow in a loosely-coupled way. But it can only execute one ``task`` when you use ``qrun``.
To automatically generate and execute different tasks, ``Task Management`` provides a whole process including `Task Generating`_, `Task Storing`_, `Task Training`_ and `Task Collecting`_.
With this module, users can run their ``task`` automatically at different periods, in different losses, or even by different models.The processes of task generation, model training and combine and collect data are shown in the following figure.
.. image:: ../_static/img/Task-Gen-Recorder-Collector.svg
:align: center
This whole process can be used in `Online Serving <../component/online.html>`_.
An example of the entire process is shown `here <https://github.com/microsoft/qlib/tree/main/examples/model_rolling/task_manager_rolling.py>`__.
Task Generating
===============
A ``task`` consists of `Model`, `Dataset`, `Record`, or anything added by users.
The specific task template can be viewed in
`Task Section <../component/workflow.html#task-section>`_.
Even though the task template is fixed, users can customize their ``TaskGen`` to generate different ``task`` by task template.
Here is the base class of ``TaskGen``:
.. autoclass:: qlib.workflow.task.gen.TaskGen
:members:
:noindex:
``Qlib`` provides a class `RollingGen <https://github.com/microsoft/qlib/tree/main/qlib/workflow/task/gen.py>`_ to generate a list of ``task`` of the dataset in different date segments.
This class allows users to verify the effect of data from different periods on the model in one experiment. More information is `here <../reference/api.html#TaskGen>`__.
Task Storing
============
To achieve higher efficiency and the possibility of cluster operation, ``Task Manager`` will store all tasks in `MongoDB <https://www.mongodb.com/>`_.
``TaskManager`` can fetch undone tasks automatically and manage the lifecycle of a set of tasks with error handling.
Users **MUST** finish the configuration of `MongoDB <https://www.mongodb.com/>`_ when using this module.
Users need to provide the MongoDB URL and database name for using ``TaskManager`` in `initialization <../start/initialization.html#Parameters>`_ or make a statement like this.
.. code-block:: python
from qlib.config import C
C["mongo"] = {
"task_url" : "mongodb://localhost:27017/", # your MongoDB url
"task_db_name" : "rolling_db" # database name
}
.. autoclass:: qlib.workflow.task.manage.TaskManager
:members:
:noindex:
More information of ``Task Manager`` can be found in `here <../reference/api.html#TaskManager>`__.
Task Training
=============
After generating and storing those ``task``, it's time to run the ``task`` which is in the *WAITING* status.
``Qlib`` provides a method called ``run_task`` to run those ``task`` in task pool, however, users can also customize how tasks are executed.
An easy way to get the ``task_func`` is using ``qlib.model.trainer.task_train`` directly.
It will run the whole workflow defined by ``task``, which includes *Model*, *Dataset*, *Record*.
.. autofunction:: qlib.workflow.task.manage.run_task
:noindex:
Meanwhile, ``Qlib`` provides a module called ``Trainer``.
.. autoclass:: qlib.model.trainer.Trainer
:members:
:noindex:
``Trainer`` will train a list of tasks and return a list of model recorders.
``Qlib`` offer two kinds of Trainer, TrainerR is the simplest way and TrainerRM is based on TaskManager to help manager tasks lifecycle automatically.
If you do not want to use ``Task Manager`` to manage tasks, then use TrainerR to train a list of tasks generated by ``TaskGen`` is enough.
`Here <../reference/api.html#Trainer>`_ are the details about different ``Trainer``.
Task Collecting
===============
Before collecting model training results, you need to use the ``qlib.init`` to specify the path of mlruns.
To collect the results of ``task`` after training, ``Qlib`` provides `Collector <../reference/api.html#Collector>`_, `Group <../reference/api.html#Group>`_ and `Ensemble <../reference/api.html#Ensemble>`_ to collect the results in a readable, expandable and loosely-coupled way.
`Collector <../reference/api.html#Collector>`_ can collect objects from everywhere and process them such as merging, grouping, averaging and so on. It has 2 step action including ``collect`` (collect anything in a dict) and ``process_collect`` (process collected dict).
`Group <../reference/api.html#Group>`_ also has 2 steps including ``group`` (can group a set of object based on `group_func` and change them to a dict) and ``reduce`` (can make a dict become an ensemble based on some rule).
For example: {(A,B,C1): object, (A,B,C2): object} ---``group``---> {(A,B): {C1: object, C2: object}} ---``reduce``---> {(A,B): object}
`Ensemble <../reference/api.html#Ensemble>`_ can merge the objects in an ensemble.
For example: {C1: object, C2: object} ---``Ensemble``---> object.
You can set the ensembles you want in the ``Collector``'s process_list.
Common ensembles include ``AverageEnsemble`` and ``RollingEnsemble``. Average ensemble is used to ensemble the results of different models in the same time period. Rollingensemble is used to ensemble the results of different models in the same time period
So the hierarchy is ``Collector``'s second step corresponds to ``Group``. And ``Group``'s second step correspond to ``Ensemble``.
For more information, please see `Collector <../reference/api.html#Collector>`_, `Group <../reference/api.html#Group>`_ and `Ensemble <../reference/api.html#Ensemble>`_, or the `example <https://github.com/microsoft/qlib/tree/main/examples/model_rolling/task_manager_rolling.py>`_.
================================================
FILE: docs/changelog/changelog.rst
================================================
.. include:: ../../CHANGES.rst
================================================
FILE: docs/component/data.rst
================================================
.. _data:
==================================
Data Layer: Data Framework & Usage
==================================
Introduction
============
``Data Layer`` provides user-friendly APIs to manage and retrieve data. It provides high-performance data infrastructure.
It is designed for quantitative investment. For example, users could build formulaic alphas with ``Data Layer`` easily. Please refer to `Building Formulaic Alphas <../advanced/alpha.html>`_ for more details.
The introduction of ``Data Layer`` includes the following parts.
- Data Preparation
- Data API
- Data Loader
- Data Handler
- Dataset
- Cache
- Data and Cache File Structure
Here is a typical example of Qlib data workflow
- Users download data and converting data into Qlib format(with filename suffix `.bin`). In this step, typically only some basic data are stored on disk(such as OHLCV).
- Creating some basic features based on Qlib's expression Engine(e.g. "Ref($close, 60) / $close", the return of last 60 trading days). Supported operators in the expression engine can be found `here <https://github.com/microsoft/qlib/blob/main/qlib/data/ops.py>`__. This step is typically implemented in Qlib's `Data Loader <https://qlib.readthedocs.io/en/latest/component/data.html#data-loader>`_ which is a component of `Data Handler <https://qlib.readthedocs.io/en/latest/component/data.html#data-handler>`_ .
- If users require more complicated data processing (e.g. data normalization), `Data Handler <https://qlib.readthedocs.io/en/latest/component/data.html#data-handler>`_ support user-customized processors to process data(some predefined processors can be found `here <https://github.com/microsoft/qlib/blob/main/qlib/data/dataset/processor.py>`__). The processors are different from operators in expression engine. It is designed for some complicated data processing methods which is hard to supported in operators in expression engine.
- At last, `Dataset <https://qlib.readthedocs.io/en/latest/component/data.html#dataset>`_ is responsible to prepare model-specific dataset from the processed data of Data Handler
Data Preparation
================
Qlib Format Data
----------------
We've specially designed a data structure to manage financial data, please refer to the `File storage design section in Qlib paper <https://arxiv.org/abs/2009.11189>`_ for detailed information.
Such data will be stored with filename suffix `.bin` (We'll call them `.bin` file, `.bin` format, or qlib format). `.bin` file is designed for scientific computing on finance data.
``Qlib`` provides two different off-the-shelf datasets, which can be accessed through this `link <https://github.com/microsoft/qlib/blob/main/qlib/contrib/data/handler.py>`__:
======================== ================= ================
Dataset US Market China Market
======================== ================= ================
Alpha360 √ √
Alpha158 √ √
======================== ================= ================
Also, ``Qlib`` provides a high-frequency dataset. Users can run a high-frequency dataset example through this `link <https://github.com/microsoft/qlib/tree/main/examples/highfreq>`__.
Qlib Format Dataset
-------------------
``Qlib`` has provided an off-the-shelf dataset in `.bin` format, users could use the script ``scripts/get_data.py`` to download the China-Stock dataset as follows. User can also use numpy to load `.bin` file to validate data.
The price volume data look different from the actual dealing price because of they are **adjusted** (`adjusted price <https://www.investopedia.com/terms/a/adjusted_closing_price.asp>`_). And then you may find that the adjusted price may be different from different data sources. This is because different data sources may vary in the way of adjusting prices. Qlib normalize the price on first trading day of each stock to 1 when adjusting them.
Users can leverage `$factor` to get the original trading price (e.g. `$close / $factor` to get the original close price).
Here are some discussions about the price adjusting of Qlib.
- https://github.com/microsoft/qlib/issues/991#issuecomment-1075252402
.. code-block:: bash
# download 1d
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
# download 1min
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/qlib_cn_1min --region cn --interval 1min
In addition to China-Stock data, ``Qlib`` also includes a US-Stock dataset, which can be downloaded with the following command:
.. code-block:: bash
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/us_data --region us
After running the above command, users can find china-stock and us-stock data in ``Qlib`` format in the ``~/.qlib/qlib_data/cn_data`` directory and ``~/.qlib/qlib_data/us_data`` directory respectively.
``Qlib`` also provides the scripts in ``scripts/data_collector`` to help users crawl the latest data on the Internet and convert it to qlib format.
When ``Qlib`` is initialized with this dataset, users could build and evaluate their own models with it. Please refer to `Initialization <../start/initialization.html>`_ for more details.
Automatic update of daily frequency data
----------------------------------------
**It is recommended that users update the data manually once (\-\-trading_date 2021-05-25) and then set it to update automatically.**
For more information refer to: `yahoo collector <https://github.com/microsoft/qlib/tree/main/scripts/data_collector/yahoo#Automatic-update-of-daily-frequency-data>`_
- Automatic update of data to the "qlib" directory each trading day(Linux)
- use *crontab*: `crontab -e`
- set up timed tasks:
.. code-block:: bash
* * * * 1-5 python <script path> update_data_to_bin --qlib_data_1d_dir <user data dir>
- **script path**: *scripts/data_collector/yahoo/collector.py*
- Manual update of data
.. code-block:: bash
python scripts/data_collector/yahoo/collector.py update_data_to_bin --qlib_data_1d_dir <user data dir> --trading_date <start date> --end_date <end date>
- *trading_date*: start of trading day
- *end_date*: end of trading day(not included)
Converting CSV and Parquet Format into Qlib Format
--------------------------------------------------
``Qlib`` has provided the script ``scripts/dump_bin.py`` to convert **any** data in CSV or Parquet format into `.bin` files (``Qlib`` format) as long as they are in the correct format.
Besides downloading the prepared demo data, users could download demo data directly from the Collector as follows for reference to the CSV format.
Here are some example:
for daily data:
.. code-block:: bash
python scripts/get_data.py download_data --file_name csv_data_cn.zip --target_dir ~/.qlib/csv_data/cn_data
for 1min data:
.. code-block:: bash
python scripts/data_collector/yahoo/collector.py download_data --source_dir ~/.qlib/stock_data/source/cn_1min --region CN --start 2021-05-20 --end 2021-05-23 --delay 0.1 --interval 1min --limit_nums 10
Users can also provide their own data in CSV or Parquet format. However, the data **must satisfies** following criterions:
- CSV or Parquet file is named after a specific stock *or* the CSV or Parquet file includes a column of the stock name
- Name the CSV or Parquet file after a stock: `SH600000.csv`, `AAPL.csv` or `SH600000.parquet`, `AAPL.parquet` (not case sensitive).
- CSV or Parquet file includes a column of the stock name. User **must** specify the column name when dumping the data. Here is an example:
.. code-block:: bash
python scripts/dump_bin.py dump_all ... --symbol_field_name symbol --file_suffix <.csv or .parquet>
where the data are in the following format:
+-----------+-------+
| symbol | close |
+===========+=======+
| SH600000 | 120 |
+-----------+-------+
- CSV or Parquet file **must** include a column for the date, and when dumping the data, user must specify the date column name. Here is an example:
.. code-block:: bash
python scripts/dump_bin.py dump_all ... --date_field_name date --file_suffix <.csv or .parquet>
where the data are in the following format:
+---------+------------+-------+------+----------+
| symbol | date | close | open | volume |
+=========+============+=======+======+==========+
| SH600000| 2020-11-01 | 120 | 121 | 12300000 |
+---------+------------+-------+------+----------+
| SH600000| 2020-11-02 | 123 | 120 | 12300000 |
+---------+------------+-------+------+----------+
Supposed that users prepare their CSV or Parquet format data in the directory ``~/.qlib/my_data``, they can run the following command to start the conversion.
.. code-block:: bash
python scripts/dump_bin.py dump_all --data_path ~/.qlib/my_data --qlib_dir ~/.qlib/qlib_data/ --include_fields open,close,high,low,volume,factor --file_suffix <.csv or .parquet>
For other supported parameters when dumping the data into `.bin` file, users can refer to the information by running the following commands:
.. code-block:: bash
python scripts/dump_bin.py dump_all --help
After conversion, users can find their Qlib format data in the directory `~/.qlib/qlib_data/`.
.. note::
The arguments of `--include_fields` should correspond with the column names of CSV or Parquet files. The columns names of dataset provided by ``Qlib`` should include open, close, high, low, volume and factor at least.
- `open`
The adjusted opening price
- `close`
The adjusted closing price
- `high`
The adjusted highest price
- `low`
The adjusted lowest price
- `volume`
The adjusted trading volume
- `factor`
The Restoration factor. Normally, ``factor = adjusted_price / original_price``, `adjusted price` reference: `split adjusted <https://www.investopedia.com/terms/s/splitadjusted.asp>`_
In the convention of `Qlib` data processing, `open, close, high, low, volume, money and factor` will be set to NaN if the stock is suspended.
If you want to use your own alpha-factor which can't be calculate by OCHLV, like PE, EPS and so on, you could add it to the CSV or Parquet files with OHCLV together and then dump it to the Qlib format data.
Checking the health of the data
-------------------------------
``Qlib`` provides a script to check the health of the data.
- The main points to check are as follows
- Check if any data is missing in the DataFrame.
- Check if there are any large step changes above the threshold in the OHLCV columns.
- Check if any of the required columns (OLHCV) are missing in the DataFrame.
- Check if the 'factor' column is missing in the DataFrame.
- You can run the following commands to check whether the data is healthy or not.
for daily data:
.. code-block:: bash
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data
for 1min data:
.. code-block:: bash
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data_1min --freq 1min
- Of course, you can also add some parameters to adjust the test results.
- The available parameters are these.
- freq: Frequency of data.
- large_step_threshold_price: Maximum permitted price change
- large_step_threshold_volume: Maximum permitted volume change.
- missing_data_num: Maximum value for which data is allowed to be null.
- You can run the following commands to check whether the data is healthy or not.
for daily data:
.. code-block:: bash
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data --missing_data_num 30055 --large_step_threshold_volume 94485 --large_step_threshold_price 20
for 1min data:
.. code-block:: bash
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data --freq 1min --missing_data_num 35806 --large_step_threshold_volume 3205452000000 --large_step_threshold_price 0.91
Stock Pool (Market)
-------------------
``Qlib`` defines `stock pool <https://github.com/microsoft/qlib/blob/main/examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml#L4>`_ as stock list and their date ranges. Predefined stock pools (e.g. csi300) may be imported as follows.
.. code-block:: bash
python collector.py --index_name CSI300 --qlib_dir <user qlib data dir> --method parse_instruments
Multiple Stock Modes
--------------------
``Qlib`` now provides two different stock modes for users: China-Stock Mode & US-Stock Mode. Here are some different settings of these two modes:
============== ================= ================
Region Trade Unit Limit Threshold
============== ================= ================
China 100 0.099
US 1 None
============== ================= ================
The `trade unit` defines the unit number of stocks can be used in a trade, and the `limit threshold` defines the bound set to the percentage of ups and downs of a stock.
- If users use ``Qlib`` in china-stock mode, china-stock data is required. Users can use ``Qlib`` in china-stock mode according to the following steps:
- Download china-stock in qlib format, please refer to section `Qlib Format Dataset <#qlib-format-dataset>`_.
- Initialize ``Qlib`` in china-stock mode
Supposed that users download their Qlib format data in the directory ``~/.qlib/qlib_data/cn_data``. Users only need to initialize ``Qlib`` as follows.
.. code-block:: python
from qlib.constant import REG_CN
qlib.init(provider_uri='~/.qlib/qlib_data/cn_data', region=REG_CN)
- If users use ``Qlib`` in US-stock mode, US-stock data is required. ``Qlib`` also provides a script to download US-stock data. Users can use ``Qlib`` in US-stock mode according to the following steps:
- Download us-stock in qlib format, please refer to section `Qlib Format Dataset <#qlib-format-dataset>`_.
- Initialize ``Qlib`` in US-stock mode
Supposed that users prepare their Qlib format data in the directory ``~/.qlib/qlib_data/us_data``. Users only need to initialize ``Qlib`` as follows.
.. code-block:: python
from qlib.config import REG_US
qlib.init(provider_uri='~/.qlib/qlib_data/us_data', region=REG_US)
.. note::
PRs for new data source are highly welcome! Users could commit the code to crawl data as a PR like `the examples here <https://github.com/microsoft/qlib/tree/main/scripts>`_. And then we will use the code to create data cache on our server which other users could use directly.
Data API
========
Data Retrieval
--------------
Users can use APIs in ``qlib.data`` to retrieve data, please refer to `Data Retrieval <../start/getdata.html>`_.
Feature
-------
``Qlib`` provides `Feature` and `ExpressionOps` to fetch the features according to users' needs.
- `Feature`
Load data from the data provider. User can get the features like `$high`, `$low`, `$open`, `$close`, .etc, which should correspond with the arguments of `--include_fields`, please refer to section `Converting CSV Format into Qlib Format <#converting-csv-format-into-qlib-format>`_.
- `ExpressionOps`
`ExpressionOps` will use operator for feature construction.
To know more about ``Operator``, please refer to `Operator API <../reference/api.html#module-qlib.data.ops>`_.
Also, ``Qlib`` supports users to define their own custom ``Operator``, an example has been given in ``tests/test_register_ops.py``.
To know more about ``Feature``, please refer to `Feature API <../reference/api.html#module-qlib.data.base>`_.
Filter
------
``Qlib`` provides `NameDFilter` and `ExpressionDFilter` to filter the instruments according to users' needs.
- `NameDFilter`
Name dynamic instrument filter. Filter the instruments based on a regulated name format. A name rule regular expression is required.
- `ExpressionDFilter`
Expression dynamic instrument filter. Filter the instruments based on a certain expression. An expression rule indicating a certain feature field is required.
- `basic features filter`: rule_expression = '$close/$open>5'
- `cross-sectional features filter` \: rule_expression = '$rank($close)<10'
- `time-sequence features filter`: rule_expression = '$Ref($close, 3)>100'
Here is a simple example showing how to use filter in a basic ``Qlib`` workflow configuration file:
.. code-block:: yaml
filter: &filter
filter_type: ExpressionDFilter
rule_expression: "Ref($close, -2) / Ref($close, -1) > 1"
filter_start_time: 2010-01-01
filter_end_time: 2010-01-07
keep: False
data_handler_config: &data_handler_config
start_time: 2010-01-01
end_time: 2021-01-22
fit_start_time: 2010-01-01
fit_end_time: 2015-12-31
instruments: *market
filter_pipe: [*filter]
To know more about ``Filter``, please refer to `Filter API <../reference/api.html#module-qlib.data.filter>`_.
Reference
---------
To know more about ``Data API``, please refer to `Data API <../reference/api.html#data>`_.
Data Loader
===========
``Data Loader`` in ``Qlib`` is designed to load raw data from the original data source. It will be loaded and used in the ``Data Handler`` module.
QlibDataLoader
--------------
The ``QlibDataLoader`` class in ``Qlib`` is such an interface that allows users to load raw data from the ``Qlib`` data source.
StaticDataLoader
----------------
The ``StaticDataLoader`` class in ``Qlib`` is such an interface that allows users to load raw data from file or as provided.
Interface
---------
Here are some interfaces of the ``QlibDataLoader`` class:
.. autoclass:: qlib.data.dataset.loader.DataLoader
:members:
:noindex:
API
---
To know more about ``Data Loader``, please refer to `Data Loader API <../reference/api.html#module-qlib.data.dataset.loader>`_.
Data Handler
============
The ``Data Handler`` module in ``Qlib`` is designed to handler those common data processing methods which will be used by most of the models.
Users can use ``Data Handler`` in an automatic workflow by ``qrun``, refer to `Workflow: Workflow Management <workflow.html>`_ for more details.
DataHandlerLP
-------------
In addition to use ``Data Handler`` in an automatic workflow with ``qrun``, ``Data Handler`` can be used as an independent module, by which users can easily preprocess data (standardization, remove NaN, etc.) and build datasets.
In order to achieve so, ``Qlib`` provides a base class `qlib.data.dataset.DataHandlerLP <../reference/api.html#qlib.data.dataset.handler.DataHandlerLP>`_. The core idea of this class is that: we will have some learnable ``Processors`` which can learn the parameters of data processing(e.g., parameters for zscore normalization). When new data comes in, these `trained` ``Processors`` can then process the new data and thus processing real-time data in an efficient way becomes possible. More information about ``Processors`` will be listed in the next subsection.
Interface
---------
Here are some important interfaces that ``DataHandlerLP`` provides:
.. autoclass:: qlib.data.dataset.handler.DataHandlerLP
:members: __init__, fetch, get_cols
:noindex:
If users want to load features and labels by config, users can define a new handler and call the static method `parse_config_to_fields` of ``qlib.contrib.data.handler.Alpha158``.
Also, users can pass ``qlib.contrib.data.processor.ConfigSectionProcessor`` that provides some preprocess methods for features defined by config into the new handler.
Processor
---------
The ``Processor`` module in ``Qlib`` is designed to be learnable and it is responsible for handling data processing such as `normalization` and `drop none/nan features/labels`.
``Qlib`` provides the following ``Processors``:
- ``DropnaProcessor``: `processor` that drops N/A features.
- ``DropnaLabel``: `processor` that drops N/A labels.
- ``TanhProcess``: `processor` that uses `tanh` to process noise data.
- ``ProcessInf``: `processor` that handles infinity values, it will be replaces by the mean of the column.
- ``Fillna``: `processor` that handles N/A values, which will fill the N/A value by 0 or other given number.
- ``MinMaxNorm``: `processor` that applies min-max normalization.
- ``ZscoreNorm``: `processor` that applies z-score normalization.
- ``RobustZScoreNorm``: `processor` that applies robust z-score normalization.
- ``CSZScoreNorm``: `processor` that applies cross sectional z-score normalization.
- ``CSRankNorm``: `processor` that applies cross sectional rank normalization.
- ``CSZFillna``: `processor` that fills N/A values in a cross sectional way by the mean of the column.
Users can also create their own `processor` by inheriting the base class of ``Processor``. Please refer to the implementation of all the processors for more information (`Processor Link <https://github.com/microsoft/qlib/blob/main/qlib/data/dataset/processor.py>`_).
To know more about ``Processor``, please refer to `Processor API <../reference/api.html#module-qlib.data.dataset.processor>`_.
Example
-------
``Data Handler`` can be run with ``qrun`` by modifying the configuration file, and can also be used as a single module.
Know more about how to run ``Data Handler`` with ``qrun``, please refer to `Workflow: Workflow Management <workflow.html>`_
Qlib provides implemented data handler `Alpha158`. The following example shows how to run `Alpha158` as a single module.
.. note:: Users need to initialize ``Qlib`` with `qlib.init` first, please refer to `initialization <../start/initialization.html>`_.
.. code-block:: Python
import qlib
from qlib.contrib.data.handler import Alpha158
data_handler_config = {
"start_time": "2008-01-01",
"end_time": "2020-08-01",
"fit_start_time": "2008-01-01",
"fit_end_time": "2014-12-31",
"instruments": "csi300",
}
if __name__ == "__main__":
qlib.init()
h = Alpha158(**data_handler_config)
# get all the columns of the data
print(h.get_cols())
# fetch all the labels
print(h.fetch(col_set="label"))
# fetch all the features
print(h.fetch(col_set="feature"))
.. note:: In the ``Alpha158``, ``Qlib`` uses the label `Ref($close, -2)/Ref($close, -1) - 1` that means the change from T+1 to T+2, rather than `Ref($close, -1)/$close - 1`, of which the reason is that when getting the T day close price of a china stock, the stock can be bought on T+1 day and sold on T+2 day.
API
---
To know more about ``Data Handler``, please refer to `Data Handler API <../reference/api.html#module-qlib.data.dataset.handler>`_.
Dataset
=======
The ``Dataset`` module in ``Qlib`` aims to prepare data for model training and inferencing.
The motivation of this module is that we want to maximize the flexibility of different models to handle data that are suitable for themselves. This module gives the model the flexibility to process their data in an unique way. For instance, models such as ``GBDT`` may work well on data that contains `nan` or `None` value, while neural networks such as ``MLP`` will break down on such data.
If user's model need process its data in a different way, user could implement his own ``Dataset`` class. If the model's
data processing is not special, ``DatasetH`` can be used directly.
The ``DatasetH`` class is the `dataset` with `Data Handler`. Here is the most important interface of the class:
.. autoclass:: qlib.data.dataset.__init__.DatasetH
:members:
:noindex:
API
---
To know more about ``Dataset``, please refer to `Dataset API <../reference/api.html#dataset>`_.
Cache
=====
``Cache`` is an optional module that helps accelerate providing data by saving some frequently-used data as cache file. ``Qlib`` provides a `Memcache` class to cache the most-frequently-used data in memory, an inheritable `ExpressionCache` class, and an inheritable `DatasetCache` class.
Global Memory Cache
-------------------
`Memcache` is a global memory cache mechanism that composes of three `MemCacheUnit` instances to cache **Calendar**, **Instruments**, and **Features**. The `MemCache` is defined globally in `cache.py` as `H`. Users can use `H['c'], H['i'], H['f']` to get/set `memcache`.
.. autoclass:: qlib.data.cache.MemCacheUnit
:members:
:noindex:
.. autoclass:: qlib.data.cache.MemCache
:members:
:noindex:
ExpressionCache
---------------
`ExpressionCache` is a cache mechanism that saves expressions such as **Mean($close, 5)**. Users can inherit this base class to define their own cache mechanism that saves expressions according to the following steps.
- Override `self._uri` method to define how the cache file path is generated
- Override `self._expression` method to define what data will be cached and how to cache it.
The following shows the details about the interfaces:
.. autoclass:: qlib.data.cache.ExpressionCache
:members:
:noindex:
``Qlib`` has currently provided implemented disk cache `DiskExpressionCache` which inherits from `ExpressionCache` . The expressions data will be stored in the disk.
DatasetCache
------------
`DatasetCache` is a cache mechanism that saves datasets. A certain dataset is regulated by a stock pool configuration (or a series of instruments, though not recommended), a list of expressions or static feature fields, the start time, and end time for the collected features and the frequency. Users can inherit this base class to define their own cache mechanism that saves datasets according to the following steps.
- Override `self._uri` method to define how their cache file path is generated
- Override `self._expression` method to define what data will be cached and how to cache it.
The following shows the details about the interfaces:
.. autoclass:: qlib.data.cache.DatasetCache
:members:
:noindex:
``Qlib`` has currently provided implemented disk cache `DiskDatasetCache` which inherits from `DatasetCache` . The datasets' data will be stored in the disk.
Data and Cache File Structure
=============================
We've specially designed a file structure to manage data and cache, please refer to the `File storage design section in Qlib paper <https://arxiv.org/abs/2009.11189>`_ for detailed information. The file structure of data and cache is listed as follows.
.. code-block::
- data/
[raw data] updated by data providers
- calendars/
- day.txt
- instruments/
- all.txt
- csi500.txt
- ...
- features/
- sh600000/
- open.day.bin
- close.day.bin
- ...
- ...
[cached data] updated when raw data is updated
- calculated features/
- sh600000/
- [hash(instrtument, field_expression, freq)]
- all-time expression -cache data file
- .meta : an assorted meta file recording the instrument name, field name, freq, and visit times
- ...
- cache/
- [hash(stockpool_config, field_expression_list, freq)]
- all-time Dataset-cache data file
- .meta : an assorted meta file recording the stockpool config, field names and visit times
- .index : an assorted index file recording the line index of all calendars
- ...
================================================
FILE: docs/component/highfreq.rst
================================================
.. _highfreq:
========================================================================
Design of Nested Decision Execution Framework for High-Frequency Trading
========================================================================
.. currentmodule:: qlib
Introduction
============
Daily trading (e.g. portfolio management) and intraday trading (e.g. orders execution) are two hot topics in Quant investment and are usually studied separately.
To get the join trading performance of daily and intraday trading, they must interact with each other and run backtest jointly.
In order to support the joint backtest strategies at multiple levels, a corresponding framework is required. None of the publicly available high-frequency trading frameworks considers multi-level joint trading, which makes the backtesting aforementioned inaccurate.
Besides backtesting, the optimization of strategies from different levels is not standalone and can be affected by each other.
For example, the best portfolio management strategy may change with the performance of order executions(e.g. a portfolio with higher turnover may become a better choice when we improve the order execution strategies).
To achieve overall good performance, it is necessary to consider the interaction of strategies at a different levels.
Therefore, building a new framework for trading on multiple levels becomes necessary to solve the various problems mentioned above, for which we designed a nested decision execution framework that considers the interaction of strategies.
.. image:: ../_static/img/framework.svg
The design of the framework is shown in the yellow part in the middle of the figure above. Each level consists of ``Trading Agent`` and ``Execution Env``. ``Trading Agent`` has its own data processing module (``Information Extractor``), forecasting module (``Forecast Model``) and decision generator (``Decision Generator``). The trading algorithm generates the decisions by the ``Decision Generator`` based on the forecast signals output by the ``Forecast Module``, and the decisions generated by the trading algorithm are passed to the ``Execution Env``, which returns the execution results.
The frequency of the trading algorithm, decision content and execution environment can be customized by users (e.g. intraday trading, daily-frequency trading, weekly-frequency trading), and the execution environment can be nested with finer-grained trading algorithm and execution environment inside (i.e. sub-workflow in the figure, e.g. daily-frequency orders can be turned into finer-grained decisions by splitting orders within the day). The flexibility of the nested decision execution framework makes it easy for users to explore the effects of combining different levels of trading strategies and break down the optimization barriers between different levels of the trading algorithm.
The optimization for the nested decision execution framework can be implemented with the support of `QlibRL <./rl/overall.html>`_. To know more about how to use the QlibRL, go to API Reference: `RL API <../reference/api.html#rl>`_.
Example
=======
An example of a nested decision execution framework for high-frequency can be found `here <https://github.com/microsoft/qlib/blob/main/examples/nested_decision_execution/workflow.py>`_.
Besides, the above examples, here are some other related works about high-frequency trading in Qlib.
- `Prediction with high-frequency data <https://github.com/microsoft/qlib/tree/main/examples/highfreq#benchmarks-performance-predicting-the-price-trend-in-high-frequency-data>`_
- `Examples <https://github.com/microsoft/qlib/blob/main/examples/orderbook_data/>`_ to extract features from high-frequency data without fixed frequency.
- `A paper <https://github.com/microsoft/qlib/tree/high-freq-execution#high-frequency-execution>`_ for high-frequency trading.
================================================
FILE: docs/component/meta.rst
================================================
.. _meta:
======================================================
Meta Controller: Meta-Task & Meta-Dataset & Meta-Model
======================================================
.. currentmodule:: qlib
Introduction
============
``Meta Controller`` provides guidance to ``Forecast Model``, which aims to learn regular patterns among a series of forecasting tasks and use learned patterns to guide forthcoming forecasting tasks. Users can implement their own meta-model instance based on ``Meta Controller`` module.
Meta Task
=========
A `Meta Task` instance is the basic element in the meta-learning framework. It saves the data that can be used for the `Meta Model`. Multiple `Meta Task` instances may share the same `Data Handler`, controlled by `Meta Dataset`. Users should use `prepare_task_data()` to obtain the data that can be directly fed into the `Meta Model`.
.. autoclass:: qlib.model.meta.task.MetaTask
:members:
Meta Dataset
============
`Meta Dataset` controls the meta-information generating process. It is on the duty of providing data for training the `Meta Model`. Users should use `prepare_tasks` to retrieve a list of `Meta Task` instances.
.. autoclass:: qlib.model.meta.dataset.MetaTaskDataset
:members:
Meta Model
==========
General Meta Model
------------------
`Meta Model` instance is the part that controls the workflow. The usage of the `Meta Model` includes:
1. Users train their `Meta Model` with the `fit` function.
2. The `Meta Model` instance guides the workflow by giving useful information via the `inference` function.
.. autoclass:: qlib.model.meta.model.MetaModel
:members:
Meta Task Model
---------------
This type of meta-model may interact with task definitions directly. Then, the `Meta Task Model` is the class for them to inherit from. They guide the base tasks by modifying the base task definitions. The function `prepare_tasks` can be used to obtain the modified base task definitions.
.. autoclass:: qlib.model.meta.model.MetaTaskModel
:members:
Meta Guide Model
----------------
This type of meta-model participates in the training process of the base forecasting model. The meta-model may guide the base forecasting models during their training to improve their performances.
.. autoclass:: qlib.model.meta.model.MetaGuideModel
:members:
Example
=======
``Qlib`` provides an implementation of ``Meta Model`` module, ``DDG-DA``,
which adapts to the market dynamics.
``DDG-DA`` includes four steps:
1. Calculate meta-information and encapsulate it into ``Meta Task`` instances. All the meta-tasks form a ``Meta Dataset`` instance.
2. Train ``DDG-DA`` based on the training data of the meta-dataset.
3. Do the inference of the ``DDG-DA`` to get guide information.
4. Apply guide information to the forecasting models to improve their performances.
The `above example <https://github.com/microsoft/qlib/tree/main/examples/benchmarks_dynamic/DDG-DA>`_ can be found in ``examples/benchmarks_dynamic/DDG-DA/workflow.py``.
================================================
FILE: docs/component/model.rst
================================================
.. _model:
===========================================
Forecast Model: Model Training & Prediction
===========================================
Introduction
============
``Forecast Model`` is designed to make the `prediction score` about stocks. Users can use the ``Forecast Model`` in an automatic workflow by ``qrun``, please refer to `Workflow: Workflow Management <workflow.html>`_.
Because the components in ``Qlib`` are designed in a loosely-coupled way, ``Forecast Model`` can be used as an independent module also.
Base Class & Interface
======================
``Qlib`` provides a base class `qlib.model.base.Model <../reference/api.html#module-qlib.model.base>`_ from which all models should inherit.
The base class provides the following interfaces:
.. autoclass:: qlib.model.base.Model
:members:
:noindex:
``Qlib`` also provides a base class `qlib.model.base.ModelFT <../reference/api.html#qlib.model.base.ModelFT>`_, which includes the method for finetuning the model.
For other interfaces such as `finetune`, please refer to `Model API <../reference/api.html#module-qlib.model.base>`_.
Example
=======
``Qlib``'s `Model Zoo` includes models such as ``LightGBM``, ``MLP``, ``LSTM``, etc.. These models are treated as the baselines of ``Forecast Model``. The following steps show how to run`` LightGBM`` as an independent module.
- Initialize ``Qlib`` with `qlib.init` first, please refer to `Initialization <../start/initialization.html>`_.
- Run the following code to get the `prediction score` `pred_score`
.. code-block:: Python
from qlib.contrib.model.gbdt import LGBModel
from qlib.contrib.data.handler import Alpha158
from qlib.utils import init_instance_by_config, flatten_dict
from qlib.workflow import R
from qlib.workflow.record_temp import SignalRecord, PortAnaRecord
market = "csi300"
benchmark = "SH000300"
data_handler_config = {
"start_time": "2008-01-01",
"end_time": "2020-08-01",
"fit_start_time": "2008-01-01",
"fit_end_time": "2014-12-31",
"instruments": market,
}
task = {
"model": {
"class": "LGBModel",
"module_path": "qlib.contrib.model.gbdt",
"kwargs": {
"loss": "mse",
"colsample_bytree": 0.8879,
"learning_rate": 0.0421,
"subsample": 0.8789,
"lambda_l1": 205.6999,
"lambda_l2": 580.9768,
"max_depth": 8,
"num_leaves": 210,
"num_threads": 20,
},
},
"dataset": {
"class": "DatasetH",
"module_path": "qlib.data.dataset",
"kwargs": {
"handler": {
"class": "Alpha158",
"module_path": "qlib.contrib.data.handler",
"kwargs": data_handler_config,
},
"segments": {
"train": ("2008-01-01", "2014-12-31"),
"valid": ("2015-01-01", "2016-12-31"),
"test": ("2017-01-01", "2020-08-01"),
},
},
},
}
# model initialization
model = init_instance_by_config(task["model"])
dataset = init_instance_by_config(task["dataset"])
# start exp
with R.start(experiment_name="workflow"):
# train
R.log_params(**flatten_dict(task))
model.fit(dataset)
# prediction
recorder = R.get_recorder()
sr = SignalRecord(model, dataset, recorder)
sr.generate()
.. note::
`Alpha158` is the data handler provided by ``Qlib``, please refer to `Data Handler <data.html#data-handler>`_.
`SignalRecord` is the `Record Template` in ``Qlib``, please refer to `Workflow <recorder.html#record-template>`_.
Also, the above example has been given in ``examples/train_backtest_analyze.ipynb``.
Technically, the meaning of the model prediction depends on the label setting designed by user.
By default, the meaning of the score is normally the rating of the instruments by the forecasting model. The higher the score, the more profit the instruments.
Custom Model
============
Qlib supports custom models. If users are interested in customizing their own models and integrating the models into ``Qlib``, please refer to `Custom Model Integration <../start/integration.html>`_.
API
===
Please refer to `Model API <../reference/api.html#module-qlib.model.base>`_.
================================================
FILE: docs/component/online.rst
================================================
.. _online_serving:
==============
Online Serving
==============
.. currentmodule:: qlib
Introduction
============
.. image:: ../_static/img/online_serving.png
:align: center
In addition to backtesting, one way to test a model is effective is to make predictions in real market conditions or even do real trading based on those predictions.
``Online Serving`` is a set of modules for online models using the latest data,
which including `Online Manager <#Online Manager>`_, `Online Strategy <#Online Strategy>`_, `Online Tool <#Online Tool>`_, `Updater <#Updater>`_.
`Here <https://github.com/microsoft/qlib/tree/main/examples/online_srv>`_ are several examples for reference, which demonstrate different features of ``Online Serving``.
If you have many models or `task` needs to be managed, please consider `Task Management <../advanced/task_management.html>`_.
The `examples <https://github.com/microsoft/qlib/tree/main/examples/online_srv>`_ are based on some components in `Task Management <../advanced/task_management.html>`_ such as ``TrainerRM`` or ``Collector``.
**NOTE**: User should keep his data source updated to support online serving. For example, Qlib provides `a batch of scripts <https://github.com/microsoft/qlib/blob/main/scripts/data_collector/yahoo/README.md#automatic-update-of-daily-frequency-datafrom-yahoo-finance>`_ to help users update Yahoo daily data.
Known limitations currently
- Currently, the daily updating prediction for the next trading day is supported. But generating orders for the next trading day is not supported due to the `limitations of public data <https://github.com/microsoft/qlib/issues/215#issuecomment-766293563>_`
Online Manager
==============
.. automodule:: qlib.workflow.online.manager
:members:
:noindex:
Online Strategy
===============
.. automodule:: qlib.workflow.online.strategy
:members:
:noindex:
Online Tool
===========
.. automodule:: qlib.workflow.online.utils
:members:
:noindex:
Updater
=======
.. automodule:: qlib.workflow.online.update
:members:
:noindex:
================================================
FILE: docs/component/recorder.rst
================================================
.. _recorder:
====================================
Qlib Recorder: Experiment Management
====================================
.. currentmodule:: qlib
Introduction
============
``Qlib`` contains an experiment management system named ``QlibRecorder``, which is designed to help users handle experiment and analyse results in an efficient way.
There are three components of the system:
- `ExperimentManager`
a class that manages experiments.
- `Experiment`
a class of experiment, and each instance of it is responsible for a single experiment.
- `Recorder`
a class of recorder, and each instance of it is responsible for a single run.
Here is a general view of the structure of the system:
.. code-block::
ExperimentManager
- Experiment 1
- Recorder 1
- Recorder 2
- ...
- Experiment 2
- Recorder 1
- Recorder 2
- ...
- ...
This experiment management system defines a set of interface and provided a concrete implementation ``MLflowExpManager``, which is based on the machine learning platform: ``MLFlow`` (`link <https://mlflow.org/>`_).
If users set the implementation of ``ExpManager`` to be ``MLflowExpManager``, they can use the command `mlflow ui` to visualize and check the experiment results. For more information, please refer to the related documents `here <https://www.mlflow.org/docs/latest/cli.html#mlflow-ui>`_.
Qlib Recorder
=============
``QlibRecorder`` provides a high level API for users to use the experiment management system. The interfaces are wrapped in the variable ``R`` in ``Qlib``, and users can directly use ``R`` to interact with the system. The following command shows how to import ``R`` in Python:
.. code-block:: Python
from qlib.workflow import R
``QlibRecorder`` includes several common API for managing `experiments` and `recorders` within a workflow. For more available APIs, please refer to the following section about `Experiment Manager`, `Experiment` and `Recorder`.
Here are the available interfaces of ``QlibRecorder``:
.. autoclass:: qlib.workflow.__init__.QlibRecorder
:members:
Experiment Manager
==================
The ``ExpManager`` module in ``Qlib`` is responsible for managing different experiments. Most of the APIs of ``ExpManager`` are similar to ``QlibRecorder``, and the most important API will be the ``get_exp`` method. User can directly refer to the documents above for some detailed information about how to use the ``get_exp`` method.
.. autoclass:: qlib.workflow.expm.ExpManager
:members: get_exp, list_experiments
:noindex:
For other interfaces such as `create_exp`, `delete_exp`, please refer to `Experiment Manager API <../reference/api.html#experiment-manager>`_.
Experiment
==========
The ``Experiment`` class is solely responsible for a single experiment, and it will handle any operations that are related to an experiment. Basic methods such as `start`, `end` an experiment are included. Besides, methods related to `recorders` are also available: such methods include `get_recorder` and `list_recorders`.
.. autoclass:: qlib.workflow.exp.Experiment
:members: get_recorder, list_recorders
:noindex:
For other interfaces such as `search_records`, `delete_recorder`, please refer to `Experiment API <../reference/api.html#experiment>`_.
``Qlib`` also provides a default ``Experiment``, which will be created and used under certain situations when users use the APIs such as `log_metrics` or `get_exp`. If the default ``Experiment`` is used, there will be related logged information when running ``Qlib``. Users are able to change the name of the default ``Experiment`` in the config file of ``Qlib`` or during ``Qlib``'s `initialization <../start/initialization.html#parameters>`_, which is set to be '`Experiment`'.
Recorder
========
The ``Recorder`` class is responsible for a single recorder. It will handle some detailed operations such as ``log_metrics``, ``log_params`` of a single run. It is designed to help user to easily track results and things being generated during a run.
Here are some important APIs that are not included in the ``QlibRecorder``:
.. autoclass:: qlib.workflow.recorder.Recorder
:members: list_artifacts, list_metrics, list_params, list_tags
:noindex:
For other interfaces such as `save_objects`, `load_object`, please refer to `Recorder API <../reference/api.html#recorder>`_.
Record Template
===============
The ``RecordTemp`` class is a class that enables generate experiment results such as IC and backtest in a certain format. We have provided three different `Record Template` class:
- ``SignalRecord``: This class generates the `prediction` results of the model.
- ``SigAnaRecord``: This class generates the `IC`, `ICIR`, `Rank IC` and `Rank ICIR` of the model.
Here is a simple example of what is done in ``SigAnaRecord``, which users can refer to if they want to calculate IC, Rank IC, Long-Short Return with their own prediction and label.
.. code-block:: Python
from qlib.contrib.eva.alpha import calc_ic, calc_long_short_return
ic, ric = calc_ic(pred.iloc[:, 0], label.iloc[:, 0])
long_short_r, long_avg_r = calc_long_short_return(pred.iloc[:, 0], label.iloc[:, 0])
- ``PortAnaRecord``: This class generates the results of `backtest`. The detailed information about `backtest` as well as the available `strategy`, users can refer to `Strategy <../component/strategy.html>`_ and `Backtest <../component/backtest.html>`_.
Here is a simple example of what is done in ``PortAnaRecord``, which users can refer to if they want to do backtest based on their own prediction and label.
.. code-block:: Python
from qlib.contrib.strategy.strategy import TopkDropoutStrategy
from qlib.contrib.evaluate import (
backtest as normal_backtest,
risk_analysis,
)
# backtest
STRATEGY_CONFIG = {
"topk": 50,
"n_drop": 5,
}
BACKTEST_CONFIG = {
"limit_threshold": 0.095,
"account": 100000000,
"benchmark": BENCHMARK,
"deal_price": "close",
"open_cost": 0.0005,
"close_cost": 0.0015,
"min_cost": 5,
}
strategy = TopkDropoutStrategy(**STRATEGY_CONFIG)
report_normal, positions_normal = normal_backtest(pred_score, strategy=strategy, **BACKTEST_CONFIG)
# analysis
analysis = dict()
analysis["excess_return_without_cost"] = risk_analysis(report_normal["return"] - report_normal["bench"])
analysis["excess_return_with_cost"] = risk_analysis(report_normal["return"] - report_normal["bench"] - report_normal["cost"])
analysis_df = pd.concat(analysis) # type: pd.DataFrame
print(analysis_df)
For more information about the APIs, please refer to `Record Template API <../reference/api.html#module-qlib.workflow.record_temp>`_.
Known Limitations
=================
- The Python objects are saved based on pickle, which may results in issues when the environment dumping objects and loading objects are different.
================================================
FILE: docs/component/report.rst
================================================
.. _report:
=======================================
Analysis: Evaluation & Results Analysis
=======================================
Introduction
============
``Analysis`` is designed to show the graphical reports of ``Intraday Trading`` , which helps users to evaluate and analyse investment portfolios visually. The following are some graphics to view:
- analysis_position
- report_graph
- score_ic_graph
- cumulative_return_graph
- risk_analysis_graph
- rank_label_graph
- analysis_model
- model_performance_graph
All of the accumulated profit metrics(e.g. return, max drawdown) in Qlib are calculated by summation.
This avoids the metrics or the plots being skewed exponentially over time.
Graphical Reports
=================
Users can run the following code to get all supported reports.
.. code-block:: python
>> import qlib.contrib.report as qcr
>> print(qcr.GRAPH_NAME_LIST)
['analysis_position.report_graph', 'analysis_position.score_ic_graph', 'analysis_position.cumulative_return_graph', 'analysis_position.risk_analysis_graph', 'analysis_position.rank_label_graph', 'analysis_model.model_performance_graph']
.. note::
For more details, please refer to the function document: similar to ``help(qcr.analysis_position.report_graph)``
Usage & Example
===============
Usage of `analysis_position.report`
-----------------------------------
API
~~~
.. automodule:: qlib.contrib.report.analysis_position.report
:members:
:noindex:
Graphical Result
~~~~~~~~~~~~~~~~
.. note::
- Axis X: Trading day
- Axis Y:
- `cum bench`
Cumulative returns series of benchmark
- `cum return wo cost`
Cumulative returns series of portfolio without cost
- `cum return w cost`
Cumulative returns series of portfolio with cost
- `return wo mdd`
Maximum drawdown series of cumulative return without cost
- `return w cost mdd`:
Maximum drawdown series of cumulative return with cost
- `cum ex return wo cost`
The `CAR` (cumulative abnormal return) series of the portfolio compared to the benchmark without cost.
- `cum ex return w cost`
The `CAR` (cumulative abnormal return) series of the portfolio compared to the benchmark with cost.
- `turnover`
Turnover rate series
- `cum ex return wo cost mdd`
Drawdown series of `CAR` (cumulative abnormal return) without cost
- `cum ex return w cost mdd`
Drawdown series of `CAR` (cumulative abnormal return) with cost
- The shaded part above: Maximum drawdown corresponding to `cum return wo cost`
- The shaded part below: Maximum drawdown corresponding to `cum ex return wo cost`
.. image:: ../_static/img/analysis/report.png
Usage of `analysis_position.score_ic`
-------------------------------------
API
~~~
.. automodule:: qlib.contrib.report.analysis_position.score_ic
:members:
:noindex:
Graphical Result
~~~~~~~~~~~~~~~~
.. note::
- Axis X: Trading day
- Axis Y:
- `ic`
The `Pearson correlation coefficient` series between `label` and `prediction score`.
In the above example, the `label` is formulated as `Ref($close, -2)/Ref($close, -1)-1`. Please refer to `Data Feature <data.html#feature>`_ for more details.
- `rank_ic`
The `Spearman's rank correlation coefficient` series between `label` and `prediction score`.
.. image:: ../_static/img/analysis/score_ic.png
.. Usage of `analysis_position.cumulative_return`
.. ----------------------------------------------
..
.. API
.. ~~~~~~~~~~~~~~~~
..
.. .. automodule:: qlib.contrib.report.analysis_position.cumulative_return
.. :members:
..
.. Graphical Result
.. ~~~~~~~~~~~~~~~~~
..
.. .. note::
..
.. - Axis X: Trading day
.. - Axis Y:
.. - Above axis Y: `(((Ref($close, -1)/$close - 1) * weight).sum() / weight.sum()).cumsum()`
.. - Below axis Y: Daily weight sum
.. - In the **sell** graph, `y < 0` stands for profit; in other cases, `y > 0` stands for profit.
.. - In the **buy_minus_sell** graph, the **y** value of the **weight** graph at the bottom is `buy_weight + sell_weight`.
.. - In each graph, the **red line** in the histogram on the right represents the average.
..
.. .. image:: ../_static/img/analysis/cumulative_return_buy.png
..
.. .. image:: ../_static/img/analysis/cumulative_return_sell.png
..
.. .. image:: ../_static/img/analysis/cumulative_return_buy_minus_sell.png
..
.. .. image:: ../_static/img/analysis/cumulative_return_hold.png
Usage of `analysis_position.risk_analysis`
------------------------------------------
API
~~~
.. automodule:: qlib.contrib.report.analysis_position.risk_analysis
:members:
:noindex:
Graphical Result
~~~~~~~~~~~~~~~~
.. note::
- general graphics
- `std`
- `excess_return_without_cost`
The `Standard Deviation` of `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost`
The `Standard Deviation` of `CAR` (cumulative abnormal return) with cost.
- `annualized_return`
- `excess_return_without_cost`
The `Annualized Rate` of `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost`
The `Annualized Rate` of `CAR` (cumulative abnormal return) with cost.
- `information_ratio`
- `excess_return_without_cost`
The `Information Ratio` without cost.
- `excess_return_with_cost`
The `Information Ratio` with cost.
To know more about `Information Ratio`, please refer to `Information Ratio – IR <https://www.investopedia.com/terms/i/informationratio.asp>`_.
- `max_drawdown`
- `excess_return_without_cost`
The `Maximum Drawdown` of `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost`
The `Maximum Drawdown` of `CAR` (cumulative abnormal return) with cost.
.. image:: ../_static/img/analysis/risk_analysis_bar.png
:align: center
.. note::
- annualized_return/max_drawdown/information_ratio/std graphics
- Axis X: Trading days grouped by month
- Axis Y:
- annualized_return graphics
- `excess_return_without_cost_annualized_return`
The `Annualized Rate` series of monthly `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost_annualized_return`
The `Annualized Rate` series of monthly `CAR` (cumulative abnormal return) with cost.
- max_drawdown graphics
- `excess_return_without_cost_max_drawdown`
The `Maximum Drawdown` series of monthly `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost_max_drawdown`
The `Maximum Drawdown` series of monthly `CAR` (cumulative abnormal return) with cost.
- information_ratio graphics
- `excess_return_without_cost_information_ratio`
The `Information Ratio` series of monthly `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost_information_ratio`
The `Information Ratio` series of monthly `CAR` (cumulative abnormal return) with cost.
- std graphics
- `excess_return_without_cost_max_drawdown`
The `Standard Deviation` series of monthly `CAR` (cumulative abnormal return) without cost.
- `excess_return_with_cost_max_drawdown`
The `Standard Deviation` series of monthly `CAR` (cumulative abnormal return) with cost.
.. image:: ../_static/img/analysis/risk_analysis_annualized_return.png
:align: center
.. image:: ../_static/img/analysis/risk_analysis_max_drawdown.png
:align: center
.. image:: ../_static/img/analysis/risk_analysis_information_ratio.png
:align: center
.. image:: ../_static/img/analysis/risk_analysis_std.png
:align: center
..
.. Usage of `analysis_position.rank_label`
.. ---------------------------------------
..
.. API
.. ~~~
..
.. .. automodule:: qlib.contrib.report.analysis_position.rank_label
.. :members:
..
..
.. Graphical Result
.. ~~~~~~~~~~~~~~~~
..
.. .. note::
..
.. - hold/sell/buy graphics:
.. - Axis X: Trading day
.. - Axis Y:
.. Average `ranking ratio`of `label` for stocks that is held/sold/bought on the trading day.
..
.. In the above example, the `label` is formulated as `Ref($close, -1)/$close - 1`. The `ranking ratio` can be formulated as follows.
.. .. math::
..
.. ranking\ ratio = \frac{Ascending\ Ranking\ of\ label}{Number\ of\ Stocks\ in\ the\ Portfolio}
..
.. .. image:: ../_static/img/analysis/rank_label_hold.png
.. :align: center
..
.. .. image:: ../_static/img/analysis/rank_label_buy.png
.. :align: center
..
.. .. image:: ../_static/img/analysis/rank_label_sell.png
.. :align: center
..
..
Usage of `analysis_model.analysis_model_performance`
----------------------------------------------------
API
~~~
.. automodule:: qlib.contrib.report.analysis_model.analysis_model_performance
:members:
:noindex:
Graphical Results
~~~~~~~~~~~~~~~~~
.. note::
- cumulative return graphics
- `Group1`:
The `Cumulative Return` series of stocks group with (`ranking ratio` of label <= 20%)
- `Group2`:
The `Cumulative Return` series of stocks group with (20% < `ranking ratio` of label <= 40%)
- `Group3`:
The `Cumulative Return` series of stocks group with (40% < `ranking ratio` of label <= 60%)
- `Group4`:
The `Cumulative Return` series of stocks group with (60% < `ranking ratio` of label <= 80%)
- `Group5`:
The `Cumulative Return` series of stocks group with (80% < `ranking ratio` of label)
- `long-short`:
The Difference series between `Cumulative Return` of `Group1` and of `Group5`
- `long-average`
The Difference series between `Cumulative Return` of `Group1` and average `Cumulative Return` for all stocks.
The `ranking ratio` can be formulated as follows.
.. math::
ranking\ ratio = \frac{Ascending\ Ranking\ of\ label}{Number\ of\ Stocks\ in\ the\ Portfolio}
.. image:: ../_static/img/analysis/analysis_model_cumulative_return.png
:align: center
.. note::
- long-short/long-average
The distribution of long-short/long-average returns on each trading day
.. image:: ../_static/img/analysis/analysis_model_long_short.png
:align: center
.. TODO: ask xiao yang for detial
.. note::
- Information Coefficient
- The `Pearson correlation coefficient` series between `labels` and `prediction scores` of stocks in portfolio.
- The graphics reports can be used to evaluate the `prediction scores`.
.. image:: ../_static/img/analysis/analysis_model_IC.png
:align: center
.. note::
- Monthly IC
Monthly average of the `Information Coefficient`
.. image:: ../_static/img/analysis/analysis_model_monthly_IC.png
:align: center
.. note::
- IC
The distribution of the `Information Coefficient` on each trading day.
- IC Normal Dist. Q-Q
The `Quantile-Quantile Plot` is used for the normal distribution of `Information Coefficient` on each trading day.
.. image:: ../_static/img/analysis/analysis_model_NDQ.png
:align: center
.. note::
- Auto Correlation
- The `Pearson correlation coefficient` series between the latest `prediction scores` and the `prediction scores` `lag` days ago of stocks in portfolio on each trading day.
- The graphics reports can be used to estimate
gitextract_o4krgpl4/
├── .commitlintrc.js
├── .deepsource.toml
├── .dockerignore
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug-report.md
│ │ ├── documentation.md
│ │ ├── feature-request.md
│ │ └── question.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── brew_install.sh
│ ├── release-drafter.yml
│ └── workflows/
│ ├── lint_title.yml
│ ├── release.yml
│ ├── stale.yml
│ ├── test_qlib_from_pip.yml
│ ├── test_qlib_from_source.yml
│ └── test_qlib_from_source_slow.yml
├── .gitignore
├── .mypy.ini
├── .pre-commit-config.yaml
├── .pylintrc
├── .readthedocs.yaml
├── CHANGELOG.md
├── CHANGES.rst
├── CODE_OF_CONDUCT.md
├── Dockerfile
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── SECURITY.md
├── build_docker_image.sh
├── docs/
│ ├── FAQ/
│ │ └── FAQ.rst
│ ├── Makefile
│ ├── _static/
│ │ └── demo.sh
│ ├── advanced/
│ │ ├── PIT.rst
│ │ ├── alpha.rst
│ │ ├── serial.rst
│ │ ├── server.rst
│ │ └── task_management.rst
│ ├── changelog/
│ │ └── changelog.rst
│ ├── component/
│ │ ├── data.rst
│ │ ├── highfreq.rst
│ │ ├── meta.rst
│ │ ├── model.rst
│ │ ├── online.rst
│ │ ├── recorder.rst
│ │ ├── report.rst
│ │ ├── rl/
│ │ │ ├── framework.rst
│ │ │ ├── guidance.rst
│ │ │ ├── overall.rst
│ │ │ ├── quickstart.rst
│ │ │ └── toctree.rst
│ │ ├── strategy.rst
│ │ └── workflow.rst
│ ├── conf.py
│ ├── developer/
│ │ ├── code_standard_and_dev_guide.rst
│ │ └── how_to_build_image.rst
│ ├── hidden/
│ │ ├── client.rst
│ │ ├── online.rst
│ │ └── tuner.rst
│ ├── index.rst
│ ├── introduction/
│ │ ├── introduction.rst
│ │ └── quick.rst
│ ├── make.bat
│ ├── reference/
│ │ └── api.rst
│ ├── requirements.txt
│ └── start/
│ ├── getdata.rst
│ ├── initialization.rst
│ ├── installation.rst
│ └── integration.rst
├── examples/
│ ├── README.md
│ ├── benchmarks/
│ │ ├── ADARNN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_adarnn_Alpha360.yaml
│ │ ├── ADD/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_add_Alpha360.yaml
│ │ ├── ALSTM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_alstm_Alpha158.yaml
│ │ │ └── workflow_config_alstm_Alpha360.yaml
│ │ ├── CatBoost/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_catboost_Alpha158.yaml
│ │ │ ├── workflow_config_catboost_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_catboost_Alpha360.yaml
│ │ │ └── workflow_config_catboost_Alpha360_csi500.yaml
│ │ ├── DoubleEnsemble/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_doubleensemble_Alpha158.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha360.yaml
│ │ │ ├── workflow_config_doubleensemble_Alpha360_csi500.yaml
│ │ │ └── workflow_config_doubleensemble_early_stop_Alpha158.yaml
│ │ ├── GATs/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_gats_Alpha158.yaml
│ │ │ └── workflow_config_gats_Alpha360.yaml
│ │ ├── GRU/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_gru_Alpha158.yaml
│ │ │ └── workflow_config_gru_Alpha360.yaml
│ │ ├── GeneralPtNN/
│ │ │ ├── README.md
│ │ │ ├── workflow_config_gru.yaml
│ │ │ ├── workflow_config_gru2mlp.yaml
│ │ │ └── workflow_config_mlp.yaml
│ │ ├── HIST/
│ │ │ ├── README.md
│ │ │ ├── qlib_csi300_stock_index.npy
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_hist_Alpha360.yaml
│ │ ├── IGMTF/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_igmtf_Alpha360.yaml
│ │ ├── KRNN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_krnn_Alpha360.yaml
│ │ ├── LSTM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_lstm_Alpha158.yaml
│ │ │ └── workflow_config_lstm_Alpha360.yaml
│ │ ├── LightGBM/
│ │ │ ├── README.md
│ │ │ ├── features_resample_N.py
│ │ │ ├── features_sample.py
│ │ │ ├── multi_freq_handler.py
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_lightgbm_Alpha158.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha158_multi_freq.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha360.yaml
│ │ │ ├── workflow_config_lightgbm_Alpha360_csi500.yaml
│ │ │ ├── workflow_config_lightgbm_configurable_dataset.yaml
│ │ │ └── workflow_config_lightgbm_multi_freq.yaml
│ │ ├── Linear/
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_linear_Alpha158.yaml
│ │ │ ├── workflow_config_linear_Alpha158_csi500.yaml
│ │ │ └── workflow_config_linear_Alpha158_multi_pass_bt.yaml
│ │ ├── Localformer/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_localformer_Alpha158.yaml
│ │ │ └── workflow_config_localformer_Alpha360.yaml
│ │ ├── MLP/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_mlp_Alpha158.yaml
│ │ │ ├── workflow_config_mlp_Alpha158_csi500.yaml
│ │ │ ├── workflow_config_mlp_Alpha360.yaml
│ │ │ └── workflow_config_mlp_Alpha360_csi500.yaml
│ │ ├── README.md
│ │ ├── SFM/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_sfm_Alpha360.yaml
│ │ ├── Sandwich/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_sandwich_Alpha360.yaml
│ │ ├── TCN/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_tcn_Alpha158.yaml
│ │ │ └── workflow_config_tcn_Alpha360.yaml
│ │ ├── TCTS/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ └── workflow_config_tcts_Alpha360.yaml
│ │ ├── TFT/
│ │ │ ├── README.md
│ │ │ ├── data_formatters/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── base.py
│ │ │ │ └── qlib_Alpha158.py
│ │ │ ├── expt_settings/
│ │ │ │ ├── __init__.py
│ │ │ │ └── configs.py
│ │ │ ├── libs/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── hyperparam_opt.py
│ │ │ │ ├── tft_model.py
│ │ │ │ └── utils.py
│ │ │ ├── requirements.txt
│ │ │ ├── tft.py
│ │ │ └── workflow_config_tft_Alpha158.yaml
│ │ ├── TRA/
│ │ │ ├── README.md
│ │ │ ├── configs/
│ │ │ │ ├── config_alstm.yaml
│ │ │ │ ├── config_alstm_tra.yaml
│ │ │ │ ├── config_alstm_tra_init.yaml
│ │ │ │ ├── config_transformer.yaml
│ │ │ │ ├── config_transformer_tra.yaml
│ │ │ │ └── config_transformer_tra_init.yaml
│ │ │ ├── data/
│ │ │ │ └── README.md
│ │ │ ├── example.py
│ │ │ ├── requirements.txt
│ │ │ ├── run.sh
│ │ │ ├── src/
│ │ │ │ ├── dataset.py
│ │ │ │ └── model.py
│ │ │ ├── workflow_config_tra_Alpha158.yaml
│ │ │ ├── workflow_config_tra_Alpha158_full.yaml
│ │ │ └── workflow_config_tra_Alpha360.yaml
│ │ ├── TabNet/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_TabNet_Alpha158.yaml
│ │ │ └── workflow_config_TabNet_Alpha360.yaml
│ │ ├── Transformer/
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── workflow_config_transformer_Alpha158.yaml
│ │ │ └── workflow_config_transformer_Alpha360.yaml
│ │ └── XGBoost/
│ │ ├── README.md
│ │ ├── requirements.txt
│ │ ├── workflow_config_xgboost_Alpha158.yaml
│ │ └── workflow_config_xgboost_Alpha360.yaml
│ ├── benchmarks_dynamic/
│ │ ├── DDG-DA/
│ │ │ ├── Makefile
│ │ │ ├── README.md
│ │ │ ├── requirements.txt
│ │ │ ├── vis_data.py
│ │ │ └── workflow.py
│ │ ├── README.md
│ │ └── baseline/
│ │ ├── README.md
│ │ ├── rolling_benchmark.py
│ │ ├── workflow_config_lightgbm_Alpha158.yaml
│ │ └── workflow_config_linear_Alpha158.yaml
│ ├── data_demo/
│ │ ├── README.md
│ │ ├── data_cache_demo.py
│ │ └── data_mem_resuse_demo.py
│ ├── highfreq/
│ │ ├── README.md
│ │ ├── highfreq_handler.py
│ │ ├── highfreq_ops.py
│ │ ├── highfreq_processor.py
│ │ ├── workflow.py
│ │ └── workflow_config_High_Freq_Tree_Alpha158.yaml
│ ├── hyperparameter/
│ │ └── LightGBM/
│ │ ├── Readme.md
│ │ ├── hyperparameter_158.py
│ │ ├── hyperparameter_360.py
│ │ └── requirements.txt
│ ├── model_interpreter/
│ │ └── feature.py
│ ├── model_rolling/
│ │ ├── requirements.txt
│ │ └── task_manager_rolling.py
│ ├── nested_decision_execution/
│ │ ├── README.md
│ │ └── workflow.py
│ ├── online_srv/
│ │ ├── online_management_simulate.py
│ │ ├── rolling_online_management.py
│ │ └── update_online_pred.py
│ ├── orderbook_data/
│ │ ├── README.md
│ │ ├── create_dataset.py
│ │ └── example.py
│ ├── portfolio/
│ │ ├── README.md
│ │ ├── config_enhanced_indexing.yaml
│ │ └── prepare_riskdata.py
│ ├── rl_order_execution/
│ │ ├── README.md
│ │ ├── exp_configs/
│ │ │ ├── backtest_opds.yml
│ │ │ ├── backtest_ppo.yml
│ │ │ ├── backtest_twap.yml
│ │ │ ├── train_opds.yml
│ │ │ └── train_ppo.yml
│ │ └── scripts/
│ │ ├── gen_pickle_data.py
│ │ ├── gen_training_orders.py
│ │ ├── merge_orders.py
│ │ └── pickle_data_config.yml
│ ├── rolling_process_data/
│ │ ├── README.md
│ │ ├── rolling_handler.py
│ │ └── workflow.py
│ ├── run_all_model.py
│ └── workflow_by_code.py
├── pyproject.toml
├── qlib/
│ ├── __init__.py
│ ├── backtest/
│ │ ├── __init__.py
│ │ ├── account.py
│ │ ├── backtest.py
│ │ ├── decision.py
│ │ ├── exchange.py
│ │ ├── executor.py
│ │ ├── high_performance_ds.py
│ │ ├── position.py
│ │ ├── profit_attribution.py
│ │ ├── report.py
│ │ ├── signal.py
│ │ └── utils.py
│ ├── cli/
│ │ ├── __init__.py
│ │ ├── data.py
│ │ └── run.py
│ ├── config.py
│ ├── constant.py
│ ├── contrib/
│ │ ├── __init__.py
│ │ ├── data/
│ │ │ ├── __init__.py
│ │ │ ├── data.py
│ │ │ ├── dataset.py
│ │ │ ├── handler.py
│ │ │ ├── highfreq_handler.py
│ │ │ ├── highfreq_processor.py
│ │ │ ├── highfreq_provider.py
│ │ │ ├── loader.py
│ │ │ ├── processor.py
│ │ │ └── utils/
│ │ │ ├── __init__.py
│ │ │ └── sepdf.py
│ │ ├── eva/
│ │ │ ├── __init__.py
│ │ │ └── alpha.py
│ │ ├── evaluate.py
│ │ ├── evaluate_portfolio.py
│ │ ├── meta/
│ │ │ ├── __init__.py
│ │ │ └── data_selection/
│ │ │ ├── __init__.py
│ │ │ ├── dataset.py
│ │ │ ├── model.py
│ │ │ ├── net.py
│ │ │ └── utils.py
│ │ ├── model/
│ │ │ ├── __init__.py
│ │ │ ├── catboost_model.py
│ │ │ ├── double_ensemble.py
│ │ │ ├── gbdt.py
│ │ │ ├── highfreq_gdbt_model.py
│ │ │ ├── linear.py
│ │ │ ├── pytorch_adarnn.py
│ │ │ ├── pytorch_add.py
│ │ │ ├── pytorch_alstm.py
│ │ │ ├── pytorch_alstm_ts.py
│ │ │ ├── pytorch_gats.py
│ │ │ ├── pytorch_gats_ts.py
│ │ │ ├── pytorch_general_nn.py
│ │ │ ├── pytorch_gru.py
│ │ │ ├── pytorch_gru_ts.py
│ │ │ ├── pytorch_hist.py
│ │ │ ├── pytorch_igmtf.py
│ │ │ ├── pytorch_krnn.py
│ │ │ ├── pytorch_localformer.py
│ │ │ ├── pytorch_localformer_ts.py
│ │ │ ├── pytorch_lstm.py
│ │ │ ├── pytorch_lstm_ts.py
│ │ │ ├── pytorch_nn.py
│ │ │ ├── pytorch_sandwich.py
│ │ │ ├── pytorch_sfm.py
│ │ │ ├── pytorch_tabnet.py
│ │ │ ├── pytorch_tcn.py
│ │ │ ├── pytorch_tcn_ts.py
│ │ │ ├── pytorch_tcts.py
│ │ │ ├── pytorch_tra.py
│ │ │ ├── pytorch_transformer.py
│ │ │ ├── pytorch_transformer_ts.py
│ │ │ ├── pytorch_utils.py
│ │ │ ├── tcn.py
│ │ │ └── xgboost.py
│ │ ├── online/
│ │ │ ├── __init__.py
│ │ │ ├── manager.py
│ │ │ ├── online_model.py
│ │ │ ├── operator.py
│ │ │ ├── user.py
│ │ │ └── utils.py
│ │ ├── ops/
│ │ │ ├── __init__.py
│ │ │ └── high_freq.py
│ │ ├── report/
│ │ │ ├── __init__.py
│ │ │ ├── analysis_model/
│ │ │ │ ├── __init__.py
│ │ │ │ └── analysis_model_performance.py
│ │ │ ├── analysis_position/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── cumulative_return.py
│ │ │ │ ├── parse_position.py
│ │ │ │ ├── rank_label.py
│ │ │ │ ├── report.py
│ │ │ │ ├── risk_analysis.py
│ │ │ │ └── score_ic.py
│ │ │ ├── data/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── ana.py
│ │ │ │ └── base.py
│ │ │ ├── graph.py
│ │ │ └── utils.py
│ │ ├── rolling/
│ │ │ ├── __init__.py
│ │ │ ├── __main__.py
│ │ │ ├── base.py
│ │ │ └── ddgda.py
│ │ ├── strategy/
│ │ │ ├── __init__.py
│ │ │ ├── cost_control.py
│ │ │ ├── optimizer/
│ │ │ │ ├── __init__.py
│ │ │ │ ├── base.py
│ │ │ │ ├── enhanced_indexing.py
│ │ │ │ └── optimizer.py
│ │ │ ├── order_generator.py
│ │ │ ├── rule_strategy.py
│ │ │ └── signal_strategy.py
│ │ ├── torch.py
│ │ ├── tuner/
│ │ │ ├── __init__.py
│ │ │ ├── config.py
│ │ │ ├── launcher.py
│ │ │ ├── pipeline.py
│ │ │ ├── space.py
│ │ │ └── tuner.py
│ │ └── workflow/
│ │ ├── __init__.py
│ │ └── record_temp.py
│ ├── data/
│ │ ├── __init__.py
│ │ ├── _libs/
│ │ │ ├── __init__.py
│ │ │ ├── expanding.pyx
│ │ │ └── rolling.pyx
│ │ ├── base.py
│ │ ├── cache.py
│ │ ├── client.py
│ │ ├── data.py
│ │ ├── dataset/
│ │ │ ├── __init__.py
│ │ │ ├── handler.py
│ │ │ ├── loader.py
│ │ │ ├── processor.py
│ │ │ ├── storage.py
│ │ │ ├── utils.py
│ │ │ └── weight.py
│ │ ├── filter.py
│ │ ├── inst_processor.py
│ │ ├── ops.py
│ │ ├── pit.py
│ │ └── storage/
│ │ ├── __init__.py
│ │ ├── file_storage.py
│ │ └── storage.py
│ ├── log.py
│ ├── model/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── ens/
│ │ │ ├── __init__.py
│ │ │ ├── ensemble.py
│ │ │ └── group.py
│ │ ├── interpret/
│ │ │ ├── __init__.py
│ │ │ └── base.py
│ │ ├── meta/
│ │ │ ├── __init__.py
│ │ │ ├── dataset.py
│ │ │ ├── model.py
│ │ │ └── task.py
│ │ ├── riskmodel/
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── poet.py
│ │ │ ├── shrink.py
│ │ │ └── structured.py
│ │ ├── trainer.py
│ │ └── utils.py
│ ├── rl/
│ │ ├── __init__.py
│ │ ├── aux_info.py
│ │ ├── contrib/
│ │ │ ├── __init__.py
│ │ │ ├── backtest.py
│ │ │ ├── naive_config_parser.py
│ │ │ ├── train_onpolicy.py
│ │ │ └── utils.py
│ │ ├── data/
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── integration.py
│ │ │ ├── native.py
│ │ │ └── pickle_styled.py
│ │ ├── interpreter.py
│ │ ├── order_execution/
│ │ │ ├── __init__.py
│ │ │ ├── interpreter.py
│ │ │ ├── network.py
│ │ │ ├── policy.py
│ │ │ ├── reward.py
│ │ │ ├── simulator_qlib.py
│ │ │ ├── simulator_simple.py
│ │ │ ├── state.py
│ │ │ ├── strategy.py
│ │ │ └── utils.py
│ │ ├── reward.py
│ │ ├── seed.py
│ │ ├── simulator.py
│ │ ├── strategy/
│ │ │ ├── __init__.py
│ │ │ └── single_order.py
│ │ ├── trainer/
│ │ │ ├── __init__.py
│ │ │ ├── api.py
│ │ │ ├── callbacks.py
│ │ │ ├── trainer.py
│ │ │ └── vessel.py
│ │ └── utils/
│ │ ├── __init__.py
│ │ ├── data_queue.py
│ │ ├── env_wrapper.py
│ │ ├── finite_env.py
│ │ └── log.py
│ ├── strategy/
│ │ ├── __init__.py
│ │ └── base.py
│ ├── tests/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ └── data.py
│ ├── typehint.py
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── data.py
│ │ ├── exceptions.py
│ │ ├── file.py
│ │ ├── index_data.py
│ │ ├── mod.py
│ │ ├── objm.py
│ │ ├── paral.py
│ │ ├── pickle_utils.py
│ │ ├── resam.py
│ │ ├── serial.py
│ │ └── time.py
│ └── workflow/
│ ├── __init__.py
│ ├── exp.py
│ ├── expm.py
│ ├── online/
│ │ ├── __init__.py
│ │ ├── manager.py
│ │ ├── strategy.py
│ │ ├── update.py
│ │ └── utils.py
│ ├── record_temp.py
│ ├── recorder.py
│ ├── task/
│ │ ├── __init__.py
│ │ ├── collect.py
│ │ ├── gen.py
│ │ ├── manage.py
│ │ └── utils.py
│ └── utils.py
├── scripts/
│ ├── README.md
│ ├── check_data_health.py
│ ├── check_dump_bin.py
│ ├── collect_info.py
│ ├── data_collector/
│ │ ├── README.md
│ │ ├── baostock_5min/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── base.py
│ │ ├── br_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── cn_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── contrib/
│ │ │ ├── fill_cn_1min_data/
│ │ │ │ ├── README.md
│ │ │ │ ├── fill_cn_1min_data.py
│ │ │ │ └── requirements.txt
│ │ │ └── future_trading_date_collector/
│ │ │ ├── README.md
│ │ │ ├── future_trading_date_collector.py
│ │ │ └── requirements.txt
│ │ ├── crowd_source/
│ │ │ └── README.md
│ │ ├── crypto/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirement.txt
│ │ ├── fund/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── future_calendar_collector.py
│ │ ├── index.py
│ │ ├── pit/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── us_index/
│ │ │ ├── README.md
│ │ │ ├── collector.py
│ │ │ └── requirements.txt
│ │ ├── utils.py
│ │ └── yahoo/
│ │ ├── README.md
│ │ ├── collector.py
│ │ └── requirements.txt
│ ├── dump_bin.py
│ ├── dump_pit.py
│ └── get_data.py
├── setup.py
└── tests/
├── backtest/
│ ├── test_file_strategy.py
│ ├── test_high_freq_trading.py
│ ├── test_soft_topk_strategy.py
│ └── test_soft_topk_strategy_cold_start.py
├── conftest.py
├── data_mid_layer_tests/
│ ├── README.md
│ ├── test_dataloader.py
│ ├── test_dataset.py
│ ├── test_handler.py
│ ├── test_handler_storage.py
│ └── test_processor.py
├── dataset_tests/
│ ├── README.md
│ └── test_datalayer.py
├── dependency_tests/
│ ├── README.md
│ └── test_mlflow.py
├── misc/
│ ├── test_get_multi_proc.py
│ ├── test_index_data.py
│ ├── test_sepdf.py
│ └── test_utils.py
├── model/
│ └── test_general_nn.py
├── ops/
│ ├── test_elem_operator.py
│ └── test_special_ops.py
├── pytest.ini
├── rl/
│ ├── test_data_queue.py
│ ├── test_finite_env.py
│ ├── test_logger.py
│ ├── test_qlib_simulator.py
│ ├── test_saoe_simple.py
│ └── test_trainer.py
├── rolling_tests/
│ └── test_update_pred.py
├── storage_tests/
│ └── test_storage.py
├── test_all_pipeline.py
├── test_contrib_model.py
├── test_contrib_workflow.py
├── test_dump_data.py
├── test_get_data.py
├── test_pit.py
├── test_register_ops.py
├── test_structured_cov_estimator.py
└── test_workflow.py
Showing preview only (317K chars total). Download the full file or copy to clipboard to get everything.
SYMBOL INDEX (4030 symbols across 277 files)
FILE: examples/benchmarks/LightGBM/features_resample_N.py
class ResampleNProcessor (line 10) | class ResampleNProcessor(InstProcessor):
method __init__ (line 11) | def __init__(self, target_frq: str, **kwargs):
method __call__ (line 14) | def __call__(self, df: pd.DataFrame, *args, **kwargs):
FILE: examples/benchmarks/LightGBM/features_sample.py
class Resample1minProcessor (line 7) | class Resample1minProcessor(InstProcessor):
method __init__ (line 10) | def __init__(self, hour: int, minute: int, **kwargs):
method __call__ (line 14) | def __call__(self, df: pd.DataFrame, *args, **kwargs):
FILE: examples/benchmarks/LightGBM/multi_freq_handler.py
class Avg15minLoader (line 10) | class Avg15minLoader(QlibDataLoader):
method load (line 11) | def load(self, instruments=None, start_time=None, end_time=None) -> pd...
class Avg15minHandler (line 19) | class Avg15minHandler(DataHandlerLP):
method __init__ (line 20) | def __init__(
method loader_config (line 50) | def loader_config(self):
FILE: examples/benchmarks/TFT/data_formatters/base.py
class DataTypes (line 36) | class DataTypes(enum.IntEnum):
class InputTypes (line 44) | class InputTypes(enum.IntEnum):
class GenericDataFormatter (line 55) | class GenericDataFormatter(abc.ABC):
method set_scalers (line 64) | def set_scalers(self, df):
method transform_inputs (line 69) | def transform_inputs(self, df):
method format_predictions (line 74) | def format_predictions(self, df):
method split_data (line 79) | def split_data(self, df):
method _column_definition (line 85) | def _column_definition(self):
method get_fixed_params (line 90) | def get_fixed_params(self):
method num_classes_per_cat_input (line 116) | def num_classes_per_cat_input(self):
method get_num_samples_for_calibration (line 123) | def get_num_samples_for_calibration(self):
method get_column_definition (line 134) | def get_column_definition(self):
method _get_input_columns (line 165) | def _get_input_columns(self):
method _get_tft_input_indices (line 169) | def _get_tft_input_indices(self):
method get_experiment_params (line 201) | def get_experiment_params(self):
FILE: examples/benchmarks/TFT/data_formatters/qlib_Alpha158.py
class Alpha158Formatter (line 31) | class Alpha158Formatter(GenericDataFormatter):
method __init__ (line 70) | def __init__(self):
method split_data (line 79) | def split_data(self, df, valid_boundary=2016, test_boundary=2018):
method set_scalers (line 104) | def set_scalers(self, df):
method transform_inputs (line 147) | def transform_inputs(self, df):
method format_predictions (line 183) | def format_predictions(self, predictions):
method get_fixed_params (line 204) | def get_fixed_params(self):
method get_default_model_params (line 217) | def get_default_model_params(self):
FILE: examples/benchmarks/TFT/expt_settings/configs.py
class ExperimentConfig (line 28) | class ExperimentConfig:
method __init__ (line 44) | def __init__(self, experiment="volatility", root_folder=None):
method data_csv_path (line 72) | def data_csv_path(self):
method hyperparam_iterations (line 80) | def hyperparam_iterations(self):
method make_data_formatter (line 83) | def make_data_formatter(self):
FILE: examples/benchmarks/TFT/libs/hyperparam_opt.py
class HyperparamOptManager (line 38) | class HyperparamOptManager:
method __init__ (line 51) | def __init__(self, param_ranges, fixed_params, model_folder, override_...
method load_results (line 79) | def load_results(self):
method _get_params_from_name (line 105) | def _get_params_from_name(self, name):
method get_best_params (line 117) | def get_best_params(self):
method clear (line 124) | def clear(self):
method _check_params (line 131) | def _check_params(self, params):
method _get_name (line 143) | def _get_name(self, params):
method get_next_parameters (line 153) | def get_next_parameters(self, ranges_to_skip=None):
method update_score (line 188) | def update_score(self, parameters, loss, model, info=""):
class DistributedHyperparamOptManager (line 229) | class DistributedHyperparamOptManager(HyperparamOptManager):
method __init__ (line 232) | def __init__(
method optimisation_completed (line 299) | def optimisation_completed(self):
method get_next_parameters (line 302) | def get_next_parameters(self):
method load_serialised_hyperparam_df (line 316) | def load_serialised_hyperparam_df(self):
method update_serialised_hyperparam_df (line 336) | def update_serialised_hyperparam_df(self):
method _generate_full_hyperparam_df (line 354) | def _generate_full_hyperparam_df(self):
method clear (line 377) | def clear(self): # reset when cleared
method load_results (line 382) | def load_results(self):
method _get_worker_search_queue (line 395) | def _get_worker_search_queue(self):
method assign_worker_numbers (line 408) | def assign_worker_numbers(self, df):
FILE: examples/benchmarks/TFT/libs/tft_model.py
function linear_layer (line 55) | def linear_layer(size, activation=None, use_time_distributed=False, use_...
function apply_mlp (line 70) | def apply_mlp(
function apply_gating_layer (line 96) | def apply_gating_layer(x, hidden_layer_size, dropout_rate=None, use_time...
function add_and_norm (line 126) | def add_and_norm(x_list):
function gated_residual_network (line 140) | def gated_residual_network(
function get_decoder_mask (line 194) | def get_decoder_mask(self_attn_inputs):
class ScaledDotProductAttention (line 206) | class ScaledDotProductAttention:
method __init__ (line 215) | def __init__(self, attn_dropout=0.0):
method __call__ (line 219) | def __call__(self, q, k, v, mask):
class InterpretableMultiHeadAttention (line 242) | class InterpretableMultiHeadAttention:
method __init__ (line 258) | def __init__(self, n_head, d_model, dropout):
method __call__ (line 286) | def __call__(self, q, k, v, mask=None):
class TFTDataCache (line 323) | class TFTDataCache:
method update (line 329) | def update(cls, data, key):
method get (line 339) | def get(cls, key):
method contains (line 344) | def contains(cls, key):
class TemporalFusionTransformer (line 351) | class TemporalFusionTransformer:
method __init__ (line 383) | def __init__(self, raw_params, use_cudnn=False):
method get_tft_embeddings (line 441) | def get_tft_embeddings(self, all_inputs):
method _get_single_col_by_type (line 554) | def _get_single_col_by_type(self, input_type):
method training_data_cached (line 559) | def training_data_cached(self):
method cache_batched_data (line 564) | def cache_batched_data(self, data, cache_key, num_samples=-1):
method _batch_sampled_data (line 580) | def _batch_sampled_data(self, data, max_samples):
method _batch_data (line 651) | def _batch_data(self, data):
method _get_active_locations (line 709) | def _get_active_locations(self, x):
method _build_base_graph (line 713) | def _build_base_graph(self):
method build_model (line 947) | def build_model(self):
method fit (line 1014) | def fit(self, train_df=None, valid_df=None):
method evaluate (line 1081) | def evaluate(self, data=None, eval_metric="loss"):
method predict (line 1114) | def predict(self, df, return_targets=False):
method get_attention (line 1164) | def get_attention(self, df):
method reset_temp_folder (line 1224) | def reset_temp_folder(self):
method get_keras_saved_path (line 1231) | def get_keras_saved_path(self, model_folder):
method save (line 1235) | def save(self, model_folder):
method load (line 1247) | def load(self, model_folder, use_keras_loadings=False):
method get_hyperparm_choices (line 1267) | def get_hyperparm_choices(cls):
FILE: examples/benchmarks/TFT/libs/utils.py
function get_single_col_by_input_type (line 28) | def get_single_col_by_input_type(input_type, column_definition):
function extract_cols_from_data_type (line 44) | def extract_cols_from_data_type(data_type, column_definition, excluded_i...
function tensorflow_quantile_loss (line 59) | def tensorflow_quantile_loss(y, y_pred, quantile):
function numpy_normalised_quantile_loss (line 86) | def numpy_normalised_quantile_loss(y, y_pred, quantile):
function create_folder_if_not_exist (line 112) | def create_folder_if_not_exist(directory):
function get_default_tensorflow_config (line 123) | def get_default_tensorflow_config(tf_device="gpu", gpu_id=0):
function save (line 153) | def save(tf_session, model_folder, cp_name, scope=None):
function load (line 175) | def load(tf_session, model_folder, cp_name, scope=None, verbose=False):
function print_weights_in_checkpoint (line 212) | def print_weights_in_checkpoint(model_folder, cp_name):
FILE: examples/benchmarks/TFT/tft.py
function get_shifted_label (line 79) | def get_shifted_label(data_df, shifts=5, col_shift="LABEL0"):
function fill_test_na (line 83) | def fill_test_na(test_df):
function process_qlib_data (line 93) | def process_qlib_data(df, dataset, fillna=False):
function process_predicted (line 122) | def process_predicted(df, col_name):
function format_score (line 140) | def format_score(forecast_df, col_name="pred", label_shift=5):
function transform_df (line 147) | def transform_df(df, col_name="LABEL0"):
class TFTModel (line 153) | class TFTModel(ModelFT):
method __init__ (line 156) | def __init__(self, **kwargs):
method _prepare_data (line 161) | def _prepare_data(self, dataset: DatasetH):
method fit (line 167) | def fit(self, dataset: DatasetH, MODEL_FOLDER="qlib_tft_model", USE_GP...
method predict (line 251) | def predict(self, dataset):
method finetune (line 285) | def finetune(self, dataset: DatasetH):
method to_pickle (line 295) | def to_pickle(self, path: Union[Path, str]):
FILE: examples/benchmarks/TRA/example.py
function main (line 8) | def main(seed, config_file="configs/config_alstm.yaml"):
FILE: examples/benchmarks/TRA/src/dataset.py
function _to_tensor (line 14) | def _to_tensor(x):
function _create_ts_slices (line 20) | def _create_ts_slices(index, seq_len):
function _get_date_parse_fn (line 50) | def _get_date_parse_fn(target):
class MTSDatasetH (line 70) | class MTSDatasetH(DatasetH):
method __init__ (line 85) | def __init__(
method setup_data (line 111) | def setup_data(self, handler_kwargs: dict = None, **kwargs):
method _prepare_seg (line 147) | def _prepare_seg(self, slc, **kwargs):
method restore_index (line 177) | def restore_index(self, index):
method assign_data (line 182) | def assign_data(self, index, vals):
method clear_memory (line 190) | def clear_memory(self):
method train (line 194) | def train(self):
method eval (line 198) | def eval(self):
method _get_slices (line 204) | def _get_slices(self):
method __len__ (line 213) | def __len__(self):
method __iter__ (line 219) | def __iter__(self):
FILE: examples/benchmarks/TRA/src/model.py
class TRAModel (line 26) | class TRAModel(Model):
method __init__ (line 27) | def __init__(
method train_epoch (line 94) | def train_epoch(self, data_set):
method test_epoch (line 146) | def test_epoch(self, data_set, return_pred=False):
method fit (line 203) | def fit(self, dataset, evals_result=dict()):
method predict (line 314) | def predict(self, dataset, segment="test"):
class LSTM (line 326) | class LSTM(nn.Module):
method __init__ (line 340) | def __init__(
method forward (line 377) | def forward(self, x):
class PositionalEncoding (line 396) | class PositionalEncoding(nn.Module):
method __init__ (line 398) | def __init__(self, d_model, dropout=0.1, max_len=5000):
method forward (line 410) | def forward(self, x):
class Transformer (line 415) | class Transformer(nn.Module):
method __init__ (line 428) | def __init__(
method forward (line 459) | def forward(self, x):
class TRA (line 475) | class TRA(nn.Module):
method __init__ (line 489) | def __init__(self, input_size, num_states=1, hidden_size=8, tau=1.0, s...
method forward (line 507) | def forward(self, hidden, hist_loss):
function evaluate (line 535) | def evaluate(pred):
function average_params (line 546) | def average_params(params_list):
function shoot_infs (line 566) | def shoot_infs(inp_tensor):
function sinkhorn (line 585) | def sinkhorn(Q, n_iters=3, epsilon=0.01):
FILE: examples/benchmarks_dynamic/DDG-DA/vis_data.py
function show_linear_weight (line 86) | def show_linear_weight(exp):
FILE: examples/benchmarks_dynamic/DDG-DA/workflow.py
class DDGDABench (line 17) | class DDGDABench(DDGDA):
method __init__ (line 26) | def __init__(self, conf_path: Union[str, Path] = DEFAULT_CONF, horizon...
FILE: examples/benchmarks_dynamic/baseline/rolling_benchmark.py
class RollingBenchmark (line 16) | class RollingBenchmark(Rolling):
method __init__ (line 22) | def __init__(self, conf_path: Union[str, Path] = DEFAULT_CONF, horizon...
FILE: examples/highfreq/highfreq_handler.py
class HighFreqHandler (line 5) | class HighFreqHandler(DataHandlerLP):
method __init__ (line 6) | def __init__(
method get_feature_config (line 38) | def get_feature_config(self):
class HighFreqBacktestHandler (line 104) | class HighFreqBacktestHandler(DataHandler):
method __init__ (line 105) | def __init__(
method get_feature_config (line 126) | def get_feature_config(self):
FILE: examples/highfreq/highfreq_ops.py
class DayLast (line 11) | class DayLast(ElemOperator):
method _load_internal (line 25) | def _load_internal(self, instrument, start_index, end_index, freq):
class FFillNan (line 31) | class FFillNan(ElemOperator):
method _load_internal (line 45) | def _load_internal(self, instrument, start_index, end_index, freq):
class BFillNan (line 50) | class BFillNan(ElemOperator):
method _load_internal (line 64) | def _load_internal(self, instrument, start_index, end_index, freq):
class Date (line 69) | class Date(ElemOperator):
method _load_internal (line 83) | def _load_internal(self, instrument, start_index, end_index, freq):
class Select (line 89) | class Select(PairOperator):
method _load_internal (line 106) | def _load_internal(self, instrument, start_index, end_index, freq):
class IsNull (line 112) | class IsNull(ElemOperator):
method _load_internal (line 126) | def _load_internal(self, instrument, start_index, end_index, freq):
class Cut (line 131) | class Cut(ElemOperator):
method __init__ (line 149) | def __init__(self, feature, l=None, r=None):
method _load_internal (line 157) | def _load_internal(self, instrument, start_index, end_index, freq):
method get_extended_window_size (line 161) | def get_extended_window_size(self):
FILE: examples/highfreq/highfreq_processor.py
class HighFreqNorm (line 8) | class HighFreqNorm(Processor):
method __init__ (line 9) | def __init__(self, fit_start_time, fit_end_time):
method fit (line 13) | def fit(self, df_features):
method __call__ (line 36) | def __call__(self, df_features):
FILE: examples/highfreq/workflow.py
class HighfreqWorkflow (line 20) | class HighfreqWorkflow:
method _init_qlib (line 83) | def _init_qlib(self):
method _prepare_calender_cache (line 91) | def _prepare_calender_cache(self):
method get_data (line 99) | def get_data(self):
method dump_and_load_dataset (line 114) | def dump_and_load_dataset(self):
FILE: examples/hyperparameter/LightGBM/hyperparameter_158.py
function objective (line 9) | def objective(trial):
FILE: examples/hyperparameter/LightGBM/hyperparameter_360.py
function objective (line 11) | def objective(trial):
FILE: examples/model_rolling/task_manager_rolling.py
class RollingTaskExample (line 24) | class RollingTaskExample:
method __init__ (line 25) | def __init__(
method reset (line 55) | def reset(self):
method task_generating (line 63) | def task_generating(self):
method task_training (line 72) | def task_training(self, tasks):
method worker (line 76) | def worker(self):
method task_collecting (line 82) | def task_collecting(self):
method main (line 106) | def main(self):
FILE: examples/nested_decision_execution/workflow.py
class NestedDecisionExecutionWorkflow (line 112) | class NestedDecisionExecutionWorkflow:
method _init_qlib (line 222) | def _init_qlib(self):
method _train_model (line 233) | def _train_model(self, model, dataset):
method backtest (line 244) | def backtest(self):
method collect_data (line 275) | def collect_data(self):
method check_diff_freq (line 305) | def check_diff_freq(self):
method backtest_only_daily (line 319) | def backtest_only_daily(self):
FILE: examples/online_srv/online_management_simulate.py
class OnlineSimulationExample (line 24) | class OnlineSimulationExample:
method __init__ (line 25) | def __init__(
method reset (line 83) | def reset(self):
method main (line 91) | def main(self):
method worker (line 124) | def worker(self):
FILE: examples/online_srv/rolling_online_management.py
class RollingOnlineExample (line 25) | class RollingOnlineExample:
method __init__ (line 26) | def __init__(
method worker (line 66) | def worker(self):
method reset (line 77) | def reset(self):
method first_run (line 88) | def first_run(self):
method routine (line 98) | def routine(self):
method add_strategy (line 110) | def add_strategy(self):
method main (line 128) | def main(self):
FILE: examples/online_srv/update_online_pred.py
class UpdatePredExample (line 27) | class UpdatePredExample:
method __init__ (line 28) | def __init__(
method first_train (line 36) | def first_train(self):
method update_online_pred (line 40) | def update_online_pred(self):
method main (line 43) | def main(self):
FILE: examples/orderbook_data/create_dataset.py
function get_library_name (line 45) | def get_library_name(doc_type):
function is_stock (line 52) | def is_stock(exchange_place, code):
function add_one_stock_daily_data (line 60) | def add_one_stock_daily_data(filepath, type, exchange_place, arc, date):
function add_one_stock_daily_data_wrapper (line 137) | def add_one_stock_daily_data_wrapper(filepath, type, exchange_place, ind...
function add_data (line 161) | def add_data(tick_date, doc_type, stock_name_dict):
class DSCreator (line 246) | class DSCreator:
method clear (line 249) | def clear(self):
method initialize_library (line 253) | def initialize_library(self):
method _get_empty_folder (line 258) | def _get_empty_folder(self, fp: Path):
method import_data (line 264) | def import_data(self, doc_type_l=["Tick", "Transaction", "Order"]):
FILE: examples/orderbook_data/example.py
class TestClass (line 10) | class TestClass(unittest.TestCase):
method setUp (line 17) | def setUp(self):
method test_basic (line 43) | def test_basic(self):
method test_basic_without_time (line 54) | def test_basic_without_time(self):
method test_basic01 (line 58) | def test_basic01(self):
method test_basic02 (line 68) | def test_basic02(self):
method test_basic03 (line 78) | def test_basic03(self):
method total_func (line 98) | def total_func(name, method):
method test_exp_01 (line 101) | def test_exp_01(self):
method test_exp_02 (line 113) | def test_exp_02(self):
method test_exp_03 (line 130) | def test_exp_03(self):
method test_exp_04 (line 144) | def test_exp_04(self):
method test_exp_05 (line 155) | def test_exp_05(self):
method test_exp_06 (line 167) | def test_exp_06(self):
method expr7_init (line 199) | def expr7_init(funccode, ordercode, time_interval):
method test_exp_07_1 (line 204) | def test_exp_07_1(self):
method test_exp_07_2 (line 219) | def test_exp_07_2(self):
method expr7_3_init (line 236) | def expr7_3_init(funccode, code, time_interval):
method test_exp_08_1 (line 241) | def test_exp_08_1(self):
method test_exp_08_2 (line 257) | def test_exp_08_2(self):
method test_exp_09_trans (line 275) | def test_exp_09_trans(self):
method test_exp_09_order (line 285) | def test_exp_09_order(self):
method test_exp_10 (line 298) | def test_exp_10(self):
FILE: examples/portfolio/prepare_riskdata.py
function prepare_data (line 11) | def prepare_data(riskdata_root="./riskdata", T=240, start_time="2016-01-...
FILE: examples/rl_order_execution/scripts/gen_training_orders.py
function generate_order (line 14) | def generate_order(stock: str, start_idx: int, end_idx: int) -> bool:
FILE: examples/rolling_process_data/rolling_handler.py
class RollingDataHandler (line 6) | class RollingDataHandler(DataHandlerLP):
method __init__ (line 7) | def __init__(
FILE: examples/rolling_process_data/workflow.py
class RollingDataWorkflow (line 15) | class RollingDataWorkflow:
method _init_qlib (line 21) | def _init_qlib(self):
method _dump_pre_handler (line 27) | def _dump_pre_handler(self, path):
method _load_pre_handler (line 43) | def _load_pre_handler(self, path):
method rolling_process (line 48) | def rolling_process(self):
FILE: examples/run_all_model.py
function only_allow_defined_args (line 28) | def only_allow_defined_args(function_to_decorate):
function handler (line 45) | def handler(signum, frame):
function cal_mean_std (line 53) | def cal_mean_std(results) -> dict:
function create_env (line 65) | def create_env():
function execute (line 79) | def execute(cmd, wait_when_err=False, raise_err=True):
function get_all_folders (line 100) | def get_all_folders(models, exclude) -> dict:
function get_all_files (line 120) | def get_all_files(folder_path, dataset, universe="") -> (str, str):
function get_all_results (line 134) | def get_all_results(folders) -> dict:
function gen_and_save_md_table (line 170) | def gen_and_save_md_table(metrics, dataset):
function gen_yaml_file_without_seed_kwargs (line 189) | def gen_yaml_file_without_seed_kwargs(yaml_path, temp_dir):
class ModelRunner (line 208) | class ModelRunner:
method _init_qlib (line 209) | def _init_qlib(self, exp_folder_name):
method run (line 225) | def run(
method _collect_results (line 383) | def _collect_results(self, exp_folder_name, dataset):
FILE: qlib/__init__.py
function init (line 25) | def init(default_conf="client", **kwargs):
function _mount_nfs_uri (line 87) | def _mount_nfs_uri(provider_uri, mount_path, auto_mount: bool = False):
function init_from_yaml_conf (line 188) | def init_from_yaml_conf(conf_path, **kwargs):
function get_project_path (line 205) | def get_project_path(config_name="config.yaml", cur_path: Union[Path, st...
function auto_init (line 243) | def auto_init(**kwargs):
FILE: qlib/backtest/__init__.py
function get_exchange (line 33) | def get_exchange(
function create_account_instance (line 113) | def create_account_instance(
function get_strategy_executor (line 177) | def get_strategy_executor(
function backtest (line 217) | def backtest(
function collect_data (line 279) | def collect_data(
function format_decisions (line 312) | def format_decisions(
FILE: qlib/backtest/account.py
class AccumulatedInfo (line 35) | class AccumulatedInfo:
method __init__ (line 41) | def __init__(self) -> None:
method reset (line 44) | def reset(self) -> None:
method add_return_value (line 49) | def add_return_value(self, value: float) -> None:
method add_cost (line 52) | def add_cost(self, value: float) -> None:
method add_turnover (line 55) | def add_turnover(self, value: float) -> None:
method get_return (line 59) | def get_return(self) -> float:
method get_cost (line 63) | def get_cost(self) -> float:
method get_turnover (line 67) | def get_turnover(self) -> float:
class Account (line 71) | class Account:
method __init__ (line 79) | def __init__(
method init_vars (line 111) | def init_vars(self, init_cash: float, position_dict: dict, freq: str, ...
method is_port_metr_enabled (line 132) | def is_port_metr_enabled(self) -> bool:
method reset_report (line 138) | def reset_report(self, freq: str, benchmark_config: dict) -> None:
method reset (line 155) | def reset(
method get_hist_positions (line 177) | def get_hist_positions(self) -> Dict[pd.Timestamp, BasePosition]:
method get_cash (line 180) | def get_cash(self) -> float:
method _update_state_from_order (line 183) | def _update_state_from_order(self, order: Order, trade_val: float, cos...
method update_order (line 203) | def update_order(self, order: Order, trade_val: float, cost: float, tr...
method update_current_position (line 225) | def update_current_position(
method update_portfolio_metrics (line 250) | def update_portfolio_metrics(self, trade_start_time: pd.Timestamp, tra...
method update_hist_positions (line 293) | def update_hist_positions(self, trade_start_time: pd.Timestamp) -> None:
method update_indicator (line 303) | def update_indicator(
method update_bar_end (line 338) | def update_bar_end(
method get_portfolio_metrics (line 405) | def get_portfolio_metrics(self) -> Tuple[pd.DataFrame, dict]:
method get_trade_indicator (line 415) | def get_trade_indicator(self) -> Indicator:
FILE: qlib/backtest/backtest.py
function backtest_loop (line 25) | def backtest_loop(
function collect_data_loop (line 52) | def collect_data_loop(
FILE: qlib/backtest/decision.py
class OrderDir (line 30) | class OrderDir(IntEnum):
class Order (line 37) | class Order:
method __post_init__ (line 83) | def __post_init__(self) -> None:
method amount_delta (line 90) | def amount_delta(self) -> float:
method deal_amount_delta (line 99) | def deal_amount_delta(self) -> float:
method sign (line 108) | def sign(self) -> int:
method parse_dir (line 117) | def parse_dir(direction: Union[str, int, np.integer, OrderDir, np.ndar...
method key_by_day (line 139) | def key_by_day(self) -> tuple:
method key (line 144) | def key(self) -> tuple:
method date (line 149) | def date(self) -> pd.Timestamp:
class OrderHelper (line 154) | class OrderHelper:
method __init__ (line 162) | def __init__(self, exchange: Exchange) -> None:
method create (line 166) | def create(
class TradeRange (line 206) | class TradeRange:
method __call__ (line 208) | def __call__(self, trade_calendar: TradeCalendarManager) -> Tuple[int,...
method clip_time_range (line 235) | def clip_time_range(self, start_time: pd.Timestamp, end_time: pd.Times...
class IdxTradeRange (line 252) | class IdxTradeRange(TradeRange):
method __init__ (line 253) | def __init__(self, start_idx: int, end_idx: int) -> None:
method __call__ (line 257) | def __call__(self, trade_calendar: TradeCalendarManager | None = None)...
method clip_time_range (line 260) | def clip_time_range(self, start_time: pd.Timestamp, end_time: pd.Times...
class TradeRangeByTime (line 264) | class TradeRangeByTime(TradeRange):
method __init__ (line 267) | def __init__(self, start_time: str | time, end_time: str | time) -> None:
method __call__ (line 286) | def __call__(self, trade_calendar: TradeCalendarManager) -> Tuple[int,...
method clip_time_range (line 294) | def clip_time_range(self, start_time: pd.Timestamp, end_time: pd.Times...
class BaseTradeDecision (line 302) | class BaseTradeDecision(Generic[DecisionType]):
method __init__ (line 318) | def __init__(self, strategy: BaseStrategy, trade_range: Union[Tuple[in...
method get_decision (line 344) | def get_decision(self) -> List[DecisionType]:
method update (line 361) | def update(self, trade_calendar: TradeCalendarManager) -> Optional[Bas...
method _get_range_limit (line 385) | def _get_range_limit(self, **kwargs: Any) -> Tuple[int, int]:
method get_range_limit (line 391) | def get_range_limit(self, **kwargs: Any) -> Tuple[int, int]:
method get_data_cal_range_limit (line 452) | def get_data_cal_range_limit(self, rtype: str = "full", raise_error: b...
method empty (line 508) | def empty(self) -> bool:
method mod_inner_decision (line 518) | def mod_inner_decision(self, inner_trade_decision: BaseTradeDecision) ...
class EmptyTradeDecision (line 539) | class EmptyTradeDecision(BaseTradeDecision[object]):
method get_decision (line 540) | def get_decision(self) -> List[object]:
method empty (line 543) | def empty(self) -> bool:
class TradeDecisionWO (line 547) | class TradeDecisionWO(BaseTradeDecision[Order]):
method __init__ (line 553) | def __init__(
method get_decision (line 569) | def get_decision(self) -> List[Order]:
method __repr__ (line 572) | def __repr__(self) -> str:
class TradeDecisionWithDetails (line 581) | class TradeDecisionWithDetails(TradeDecisionWO):
method __init__ (line 587) | def __init__(
FILE: qlib/backtest/exchange.py
class Exchange (line 28) | class Exchange:
method __init__ (line 38) | def __init__(
method get_quote_from_qlib (line 201) | def get_quote_from_qlib(self) -> None:
method _get_limit_type (line 262) | def _get_limit_type(self, limit_threshold: Union[tuple, float, None]) ...
method _update_limit (line 273) | def _update_limit(self, limit_threshold: Union[Tuple, float, None]) ->...
method _get_vol_limit (line 295) | def _get_vol_limit(volume_threshold: Union[tuple, dict, None]) -> Tupl...
method check_stock_limit (line 338) | def check_stock_limit(
method check_stock_suspended (line 378) | def check_stock_suspended(
method is_stock_tradable (line 404) | def is_stock_tradable(
method check_order (line 417) | def check_order(self, order: Order) -> bool:
method deal_order (line 421) | def deal_order(
method get_quote_info (line 465) | def get_quote_info(
method get_close (line 475) | def get_close(
method get_volume (line 484) | def get_volume(
method get_deal_price (line 494) | def get_deal_price(
method get_factor (line 516) | def get_factor(
method generate_amount_position_from_weight_position (line 534) | def generate_amount_position_from_weight_position(
method get_real_deal_amount (line 589) | def get_real_deal_amount(self, current_amount: float, target_amount: f...
method generate_order_for_target_amount_position (line 611) | def generate_order_for_target_amount_position(
method calculate_amount_position_value (line 679) | def calculate_amount_position_value(
method _get_factor_or_raise_error (line 712) | def _get_factor_or_raise_error(
method get_amount_of_trade_unit (line 728) | def get_amount_of_trade_unit(
method round_amount_by_trade_unit (line 761) | def round_amount_by_trade_unit(
method _clip_amount_by_volume (line 786) | def _clip_amount_by_volume(self, order: Order, dealt_order_amount: dic...
method _get_buy_amount_by_cash_limit (line 834) | def _get_buy_amount_by_cash_limit(self, trade_price: float, cash: floa...
method _calc_trade_info_by_order (line 859) | def _calc_trade_info_by_order(
method get_order_helper (line 954) | def get_order_helper(self) -> OrderHelper:
FILE: qlib/backtest/executor.py
class BaseExecutor (line 22) | class BaseExecutor:
method __init__ (line 25) | def __init__(
method reset_common_infra (line 127) | def reset_common_infra(self, common_infra: CommonInfrastructure, copy_...
method trade_exchange (line 152) | def trade_exchange(self) -> Exchange:
method trade_calendar (line 157) | def trade_calendar(self) -> TradeCalendarManager:
method reset (line 164) | def reset(self, common_infra: CommonInfrastructure | None = None, **kw...
method get_level_infra (line 177) | def get_level_infra(self) -> LevelInfrastructure:
method finished (line 180) | def finished(self) -> bool:
method execute (line 183) | def execute(self, trade_decision: BaseTradeDecision, level: int = 0) -...
method _collect_data (line 206) | def _collect_data(
method collect_data (line 227) | def collect_data(
method get_all_executors (line 305) | def get_all_executors(self) -> List[BaseExecutor]:
class NestedExecutor (line 310) | class NestedExecutor(BaseExecutor):
method __init__ (line 317) | def __init__(
method reset_common_infra (line 375) | def reset_common_infra(self, common_infra: CommonInfrastructure, copy_...
method _init_sub_trading (line 389) | def _init_sub_trading(self, trade_decision: BaseTradeDecision) -> None:
method _update_trade_decision (line 396) | def _update_trade_decision(self, trade_decision: BaseTradeDecision) ->...
method _collect_data (line 406) | def _collect_data(
method post_inner_exe_step (line 485) | def post_inner_exe_step(self, inner_exe_res: List[object]) -> None:
method get_all_executors (line 496) | def get_all_executors(self) -> List[BaseExecutor]:
function _retrieve_orders_from_decision (line 501) | def _retrieve_orders_from_decision(trade_decision: BaseTradeDecision) ->...
class SimulatorExecutor (line 513) | class SimulatorExecutor(BaseExecutor):
method __init__ (line 528) | def __init__(
method _get_order_iterator (line 561) | def _get_order_iterator(self, trade_decision: BaseTradeDecision) -> Li...
method _collect_data (line 590) | def _collect_data(self, trade_decision: BaseTradeDecision, level: int ...
FILE: qlib/backtest/high_performance_ds.py
class BaseQuote (line 23) | class BaseQuote:
method __init__ (line 24) | def __init__(self, quote_df: pd.DataFrame, freq: str) -> None:
method get_all_stock (line 27) | def get_all_stock(self) -> Iterable:
method get_data (line 38) | def get_data(
class PandasQuote (line 103) | class PandasQuote(BaseQuote):
method __init__ (line 104) | def __init__(self, quote_df: pd.DataFrame, freq: str) -> None:
method get_all_stock (line 111) | def get_all_stock(self):
method get_data (line 114) | def get_data(self, stock_id, start_time, end_time, field, method=None):
class NumpyQuote (line 128) | class NumpyQuote(BaseQuote):
method __init__ (line 129) | def __init__(self, quote_df: pd.DataFrame, freq: str, region: str = "c...
method get_all_stock (line 152) | def get_all_stock(self):
method get_data (line 156) | def get_data(self, stock_id, start_time, end_time, field, method=None):
method _agg_data (line 184) | def _agg_data(data: IndexData, method: str) -> Union[IndexData, np.nda...
class BaseSingleMetric (line 207) | class BaseSingleMetric:
method __init__ (line 213) | def __init__(self, metric: Union[dict, pd.Series]):
method __add__ (line 230) | def __add__(self, other: Union[BaseSingleMetric, int, float]) -> BaseS...
method __radd__ (line 233) | def __radd__(self, other: Union[BaseSingleMetric, int, float]) -> Base...
method __sub__ (line 236) | def __sub__(self, other: Union[BaseSingleMetric, int, float]) -> BaseS...
method __rsub__ (line 239) | def __rsub__(self, other: Union[BaseSingleMetric, int, float]) -> Base...
method __mul__ (line 242) | def __mul__(self, other: Union[BaseSingleMetric, int, float]) -> BaseS...
method __truediv__ (line 245) | def __truediv__(self, other: Union[BaseSingleMetric, int, float]) -> B...
method __eq__ (line 248) | def __eq__(self, other: object) -> BaseSingleMetric:
method __gt__ (line 251) | def __gt__(self, other: Union[BaseSingleMetric, int, float]) -> BaseSi...
method __lt__ (line 254) | def __lt__(self, other: Union[BaseSingleMetric, int, float]) -> BaseSi...
method __len__ (line 257) | def __len__(self) -> int:
method sum (line 260) | def sum(self) -> float:
method mean (line 263) | def mean(self) -> float:
method count (line 266) | def count(self) -> int:
method abs (line 271) | def abs(self) -> BaseSingleMetric:
method empty (line 275) | def empty(self) -> bool:
method add (line 280) | def add(self, other: BaseSingleMetric, fill_value: float = None) -> Ba...
method replace (line 285) | def replace(self, replace_dict: dict) -> BaseSingleMetric:
method apply (line 290) | def apply(self, func: Callable) -> BaseSingleMetric:
class BaseOrderIndicator (line 298) | class BaseOrderIndicator:
method __init__ (line 310) | def __init__(self):
method assign (line 314) | def assign(self, col: str, metric: Union[dict, pd.Series]) -> None:
method transfer (line 334) | def transfer(self, func: Callable, new_col: str = None) -> Optional[Ba...
method get_metric_series (line 362) | def get_metric_series(self, metric: str) -> pd.Series:
method get_index_data (line 379) | def get_index_data(self, metric: str) -> SingleData:
method sum_all_indicators (line 396) | def sum_all_indicators(
method to_series (line 420) | def to_series(self) -> Dict[Text, pd.Series]:
class SingleMetric (line 436) | class SingleMetric(BaseSingleMetric):
method __init__ (line 437) | def __init__(self, metric):
method __add__ (line 440) | def __add__(self, other):
method __sub__ (line 448) | def __sub__(self, other):
method __rsub__ (line 456) | def __rsub__(self, other):
method __mul__ (line 464) | def __mul__(self, other):
method __truediv__ (line 472) | def __truediv__(self, other):
method __eq__ (line 480) | def __eq__(self, other):
method __gt__ (line 488) | def __gt__(self, other):
method __lt__ (line 496) | def __lt__(self, other):
method __len__ (line 504) | def __len__(self):
class PandasSingleMetric (line 508) | class PandasSingleMetric(SingleMetric):
method __init__ (line 511) | def __init__(self, metric: Union[dict, pd.Series] = {}):
method sum (line 519) | def sum(self):
method mean (line 522) | def mean(self):
method count (line 525) | def count(self):
method abs (line 528) | def abs(self):
method empty (line 532) | def empty(self):
method index (line 536) | def index(self):
method add (line 539) | def add(self, other: BaseSingleMetric, fill_value: float = None) -> Pa...
method replace (line 543) | def replace(self, replace_dict: dict) -> PandasSingleMetric:
method apply (line 546) | def apply(self, func: Callable) -> PandasSingleMetric:
method reindex (line 549) | def reindex(self, index: Any, fill_value: float) -> PandasSingleMetric:
method __repr__ (line 552) | def __repr__(self):
class PandasOrderIndicator (line 556) | class PandasOrderIndicator(BaseOrderIndicator):
method __init__ (line 563) | def __init__(self) -> None:
method assign (line 567) | def assign(self, col: str, metric: Union[dict, pd.Series]) -> None:
method get_index_data (line 570) | def get_index_data(self, metric: str) -> SingleData:
method get_metric_series (line 576) | def get_metric_series(self, metric: str) -> Union[pd.Series]:
method to_series (line 582) | def to_series(self):
method sum_all_indicators (line 586) | def sum_all_indicators(
method __repr__ (line 600) | def __repr__(self):
class NumpyOrderIndicator (line 604) | class NumpyOrderIndicator(BaseOrderIndicator):
method __init__ (line 611) | def __init__(self) -> None:
method assign (line 615) | def assign(self, col: str, metric: dict) -> None:
method get_index_data (line 618) | def get_index_data(self, metric: str) -> SingleData:
method get_metric_series (line 624) | def get_metric_series(self, metric: str) -> Union[pd.Series]:
method to_series (line 627) | def to_series(self) -> Dict[str, pd.Series]:
method sum_all_indicators (line 634) | def sum_all_indicators(
method __repr__ (line 657) | def __repr__(self):
FILE: qlib/backtest/position.py
class BasePosition (line 16) | class BasePosition:
method __init__ (line 22) | def __init__(self, *args: Any, cash: float = 0.0, **kwargs: Any) -> None:
method fill_stock_value (line 26) | def fill_stock_value(self, start_time: Union[str, pd.Timestamp], freq:...
method skip_update (line 29) | def skip_update(self) -> bool:
method check_stock (line 41) | def check_stock(self, stock_id: str) -> bool:
method update_order (line 57) | def update_order(self, order: Order, trade_val: float, cost: float, tr...
method update_stock_price (line 72) | def update_stock_price(self, stock_id: str, price: float) -> None:
method calculate_stock_value (line 86) | def calculate_stock_value(self) -> float:
method calculate_value (line 97) | def calculate_value(self) -> float:
method get_stock_list (line 100) | def get_stock_list(self) -> List[str]:
method get_stock_price (line 106) | def get_stock_price(self, code: str) -> float:
method get_stock_amount (line 117) | def get_stock_amount(self, code: str) -> float:
method get_cash (line 133) | def get_cash(self, include_settle: bool = False) -> float:
method get_stock_amount_dict (line 148) | def get_stock_amount_dict(self) -> dict:
method get_stock_weight_dict (line 159) | def get_stock_weight_dict(self, only_stock: bool = False) -> dict:
method add_count_all (line 178) | def add_count_all(self, bar: str) -> None:
method update_weight_all (line 189) | def update_weight_all(self) -> None:
method settle_start (line 201) | def settle_start(self, settle_type: str) -> None:
method settle_commit (line 218) | def settle_commit(self) -> None:
method __str__ (line 224) | def __str__(self) -> str:
method __repr__ (line 227) | def __repr__(self) -> str:
class Position (line 231) | class Position(BasePosition):
method __init__ (line 245) | def __init__(self, cash: float = 0, position_dict: Dict[str, Union[Dic...
method fill_stock_value (line 280) | def fill_stock_value(self, start_time: Union[str, pd.Timestamp], freq:...
method _init_stock (line 324) | def _init_stock(self, stock_id: str, amount: float, price: float | Non...
method _buy_stock (line 342) | def _buy_stock(self, stock_id: str, trade_val: float, cost: float, tra...
method _sell_stock (line 352) | def _sell_stock(self, stock_id: str, trade_val: float, cost: float, tr...
method _del_stock (line 384) | def _del_stock(self, stock_id: str) -> None:
method check_stock (line 387) | def check_stock(self, stock_id: str) -> bool:
method update_order (line 390) | def update_order(self, order: Order, trade_val: float, cost: float, tr...
method update_stock_price (line 401) | def update_stock_price(self, stock_id: str, price: float) -> None:
method update_stock_count (line 404) | def update_stock_count(self, stock_id: str, bar: str, count: float) ->...
method update_stock_weight (line 407) | def update_stock_weight(self, stock_id: str, weight: float) -> None:
method calculate_stock_value (line 410) | def calculate_stock_value(self) -> float:
method calculate_value (line 417) | def calculate_value(self) -> float:
method get_stock_list (line 422) | def get_stock_list(self) -> List[str]:
method get_stock_price (line 426) | def get_stock_price(self, code: str) -> float:
method get_stock_amount (line 429) | def get_stock_amount(self, code: str) -> float:
method get_stock_count (line 432) | def get_stock_count(self, code: str, bar: str) -> float:
method get_stock_weight (line 439) | def get_stock_weight(self, code: str) -> float:
method get_cash (line 442) | def get_cash(self, include_settle: bool = False) -> float:
method get_stock_amount_dict (line 448) | def get_stock_amount_dict(self) -> dict:
method get_stock_weight_dict (line 456) | def get_stock_weight_dict(self, only_stock: bool = False) -> dict:
method add_count_all (line 474) | def add_count_all(self, bar: str) -> None:
method update_weight_all (line 482) | def update_weight_all(self) -> None:
method settle_start (line 487) | def settle_start(self, settle_type: str) -> None:
method settle_commit (line 493) | def settle_commit(self) -> None:
class InfPosition (line 503) | class InfPosition(BasePosition):
method skip_update (line 510) | def skip_update(self) -> bool:
method check_stock (line 514) | def check_stock(self, stock_id: str) -> bool:
method update_order (line 518) | def update_order(self, order: Order, trade_val: float, cost: float, tr...
method update_stock_price (line 521) | def update_stock_price(self, stock_id: str, price: float) -> None:
method calculate_stock_value (line 524) | def calculate_stock_value(self) -> float:
method calculate_value (line 533) | def calculate_value(self) -> float:
method get_stock_list (line 536) | def get_stock_list(self) -> List[str]:
method get_stock_price (line 539) | def get_stock_price(self, code: str) -> float:
method get_stock_amount (line 543) | def get_stock_amount(self, code: str) -> float:
method get_cash (line 546) | def get_cash(self, include_settle: bool = False) -> float:
method get_stock_amount_dict (line 549) | def get_stock_amount_dict(self) -> dict:
method get_stock_weight_dict (line 552) | def get_stock_weight_dict(self, only_stock: bool = False) -> dict:
method add_count_all (line 555) | def add_count_all(self, bar: str) -> None:
method update_weight_all (line 558) | def update_weight_all(self) -> None:
method settle_start (line 561) | def settle_start(self, settle_type: str) -> None:
method settle_commit (line 564) | def settle_commit(self) -> None:
FILE: qlib/backtest/profit_attribution.py
function get_benchmark_weight (line 18) | def get_benchmark_weight(
function get_stock_weight_df (line 56) | def get_stock_weight_df(positions):
function decompose_portofolio_weight (line 72) | def decompose_portofolio_weight(stock_weight_df, stock_group_df):
function decompose_portofolio (line 110) | def decompose_portofolio(stock_weight_df, stock_group_df, stock_ret_df):
function get_daily_bin_group (line 179) | def get_daily_bin_group(bench_values, stock_values, group_n):
function get_stock_group (line 205) | def get_stock_group(stock_group_field_df, bench_stock_weight_df, group_m...
function brinson_pa (line 226) | def brinson_pa(
FILE: qlib/backtest/report.py
class PortfolioMetrics (line 22) | class PortfolioMetrics:
method __init__ (line 42) | def __init__(self, freq: str = "day", benchmark_config: dict = {}) -> ...
method init_vars (line 78) | def init_vars(self) -> None:
method init_bench (line 90) | def init_bench(self, freq: str | None = None, benchmark_config: dict |...
method _cal_benchmark (line 97) | def _cal_benchmark(benchmark_config: Optional[dict], freq: str) -> Opt...
method _sample_benchmark (line 123) | def _sample_benchmark(
method is_empty (line 138) | def is_empty(self) -> bool:
method get_latest_date (line 141) | def get_latest_date(self) -> pd.Timestamp:
method get_latest_account_value (line 144) | def get_latest_account_value(self) -> float:
method get_latest_total_cost (line 147) | def get_latest_total_cost(self) -> Any:
method get_latest_total_turnover (line 150) | def get_latest_total_turnover(self) -> Any:
method update_portfolio_metrics_record (line 153) | def update_portfolio_metrics_record(
method generate_portfolio_metrics_dataframe (line 203) | def generate_portfolio_metrics_dataframe(self) -> pd.DataFrame:
method save_portfolio_metrics (line 217) | def save_portfolio_metrics(self, path: str) -> None:
method load_portfolio_metrics (line 221) | def load_portfolio_metrics(self, path: str) -> None:
class Indicator (line 249) | class Indicator:
method __init__ (line 278) | def __init__(self, order_indicator_cls: Type[BaseOrderIndicator] = Num...
method reset (line 292) | def reset(self) -> None:
method record (line 297) | def record(self, trade_start_time: Union[str, pd.Timestamp]) -> None:
method _update_order_trade_info (line 301) | def _update_order_trade_info(self, trade_info: List[Tuple[Order, float...
method _update_order_fulfill_rate (line 330) | def _update_order_fulfill_rate(self) -> None:
method update_order_indicators (line 339) | def update_order_indicators(self, trade_info: List[Tuple[Order, float,...
method _agg_order_trade_info (line 343) | def _agg_order_trade_info(self, inner_order_indicators: List[BaseOrder...
method _update_trade_amount (line 372) | def _update_trade_amount(self, outer_trade_decision: BaseTradeDecision...
method _get_base_vol_pri (line 380) | def _get_base_vol_pri(
method _agg_base_price (line 455) | def _agg_base_price(
method _agg_order_price_advantage (line 524) | def _agg_order_price_advantage(self) -> None:
method agg_order_indicators (line 539) | def agg_order_indicators(
method _cal_trade_fulfill_rate (line 554) | def _cal_trade_fulfill_rate(self, method: str = "mean") -> Optional[Ba...
method _cal_trade_price_advantage (line 570) | def _cal_trade_price_advantage(self, method: str = "mean") -> Optional...
method _cal_trade_positive_rate (line 584) | def _cal_trade_positive_rate(self) -> Optional[BaseSingleMetric]:
method _cal_deal_amount (line 590) | def _cal_deal_amount(self) -> Optional[BaseSingleMetric]:
method _cal_trade_value (line 596) | def _cal_trade_value(self) -> Optional[BaseSingleMetric]:
method _cal_trade_order_count (line 602) | def _cal_trade_order_count(self) -> Optional[BaseSingleMetric]:
method cal_trade_indicators (line 608) | def cal_trade_indicators(
method get_order_indicator (line 644) | def get_order_indicator(self, raw: bool = True) -> Union[BaseOrderIndi...
method get_trade_indicator (line 647) | def get_trade_indicator(self) -> Dict[str, Optional[BaseSingleMetric]]:
method generate_trade_indicators_dataframe (line 650) | def generate_trade_indicators_dataframe(self) -> pd.DataFrame:
FILE: qlib/backtest/signal.py
class Signal (line 16) | class Signal(metaclass=abc.ABCMeta):
method get_signal (line 25) | def get_signal(self, start_time: pd.Timestamp, end_time: pd.Timestamp)...
class SignalWCache (line 36) | class SignalWCache(Signal):
method __init__ (line 42) | def __init__(self, signal: Union[pd.Series, pd.DataFrame]) -> None:
method get_signal (line 60) | def get_signal(self, start_time: pd.Timestamp, end_time: pd.Timestamp)...
class ModelSignal (line 68) | class ModelSignal(SignalWCache):
method __init__ (line 69) | def __init__(self, model: BaseModel, dataset: Dataset) -> None:
method _update_model (line 77) | def _update_model(self) -> None:
function create_signal_from (line 88) | def create_signal_from(
FILE: qlib/backtest/utils.py
class TradeCalendarManager (line 23) | class TradeCalendarManager:
method __init__ (line 29) | def __init__(
method reset (line 51) | def reset(
method finished (line 78) | def finished(self) -> bool:
method step (line 87) | def step(self) -> None:
method get_freq (line 92) | def get_freq(self) -> str:
method get_trade_len (line 95) | def get_trade_len(self) -> int:
method get_trade_step (line 99) | def get_trade_step(self) -> int:
method get_step_time (line 102) | def get_step_time(self, trade_step: int | None = None, shift: int = 0)...
method get_data_cal_range (line 133) | def get_data_cal_range(self, rtype: str = "full") -> Tuple[int, int]:
method get_all_time (line 167) | def get_all_time(self) -> Tuple[pd.Timestamp, pd.Timestamp]:
method get_range_idx (line 172) | def get_range_idx(self, start_time: pd.Timestamp, end_time: pd.Timesta...
method __repr__ (line 196) | def __repr__(self) -> str:
class BaseInfrastructure (line 204) | class BaseInfrastructure:
method __init__ (line 205) | def __init__(self, **kwargs: Any) -> None:
method get_support_infra (line 209) | def get_support_infra(self) -> Set[str]:
method reset_infra (line 212) | def reset_infra(self, **kwargs: Any) -> None:
method get (line 220) | def get(self, infra_name: str) -> Any:
method has (line 226) | def has(self, infra_name: str) -> bool:
method update (line 229) | def update(self, other: BaseInfrastructure) -> None:
class CommonInfrastructure (line 235) | class CommonInfrastructure(BaseInfrastructure):
method get_support_infra (line 236) | def get_support_infra(self) -> Set[str]:
class LevelInfrastructure (line 240) | class LevelInfrastructure(BaseInfrastructure):
method get_support_infra (line 243) | def get_support_infra(self) -> Set[str]:
method reset_cal (line 252) | def reset_cal(
method set_sub_level_infra (line 266) | def set_sub_level_infra(self, sub_level_infra: LevelInfrastructure) ->...
function get_start_end_idx (line 271) | def get_start_end_idx(trade_calendar: TradeCalendarManager, outer_trade_...
FILE: qlib/cli/run.py
function get_path_list (line 23) | def get_path_list(path):
function sys_config (line 30) | def sys_config(config, config_path):
function render_template (line 52) | def render_template(config_path: str) -> str:
function workflow (line 86) | def workflow(config_path, experiment_name="workflow", uri_folder="mlruns"):
function run (line 152) | def run():
FILE: qlib/config.py
class MLflowSettings (line 34) | class MLflowSettings(BaseSettings):
class QSettings (line 39) | class QSettings(BaseSettings):
class Config (line 64) | class Config:
method __init__ (line 65) | def __init__(self, default_conf):
method __getitem__ (line 69) | def __getitem__(self, key):
method __getattr__ (line 72) | def __getattr__(self, attr):
method get (line 78) | def get(self, key, default=None):
method __setitem__ (line 81) | def __setitem__(self, key, value):
method __setattr__ (line 84) | def __setattr__(self, attr, value):
method __contains__ (line 87) | def __contains__(self, item):
method __getstate__ (line 90) | def __getstate__(self):
method __setstate__ (line 93) | def __setstate__(self, state):
method __str__ (line 96) | def __str__(self):
method __repr__ (line 99) | def __repr__(self):
method reset (line 102) | def reset(self):
method update (line 105) | def update(self, *args, **kwargs):
method set_conf_from_C (line 108) | def set_conf_from_C(self, config_c):
method register_from_C (line 112) | def register_from_C(config, skip_register=True):
class QlibConfig (line 315) | class QlibConfig(Config):
method __init__ (line 321) | def __init__(self, default_conf):
class DataPathManager (line 325) | class DataPathManager:
method __init__ (line 332) | def __init__(self, provider_uri: Union[str, Path, dict], mount_path:...
method format_provider_uri (line 342) | def format_provider_uri(provider_uri: Union[str, dict, Path]) -> dict:
method get_uri_type (line 356) | def get_uri_type(uri: Union[str, Path]):
method get_data_uri (line 367) | def get_data_uri(self, freq: Optional[Union[str, Freq]] = None) -> P...
method set_mode (line 387) | def set_mode(self, mode):
method set_region (line 392) | def set_region(self, region):
method is_depend_redis (line 397) | def is_depend_redis(cache_name: str):
method dpm (line 401) | def dpm(self):
method resolve_path (line 404) | def resolve_path(self):
method set (line 424) | def set(self, default_conf: str = "client", **kwargs):
method register (line 483) | def register(self):
method reset_qlib_version (line 504) | def reset_qlib_version(self):
method get_kernels (line 515) | def get_kernels(self, freq: str):
method registered (line 522) | def registered(self):
FILE: qlib/contrib/data/data.py
class ArcticFeatureProvider (line 19) | class ArcticFeatureProvider(FeatureProvider):
method __init__ (line 20) | def __init__(
method feature (line 32) | def feature(self, instrument, field, start_index, end_index, freq):
FILE: qlib/contrib/data/dataset.py
function _to_tensor (line 17) | def _to_tensor(x):
function _create_ts_slices (line 23) | def _create_ts_slices(index, seq_len):
function _get_date_parse_fn (line 57) | def _get_date_parse_fn(target):
function _maybe_padding (line 84) | def _maybe_padding(x, seq_len, zeros=None):
class MTSDatasetH (line 102) | class MTSDatasetH(DatasetH):
method __init__ (line 119) | def __init__(
method setup_data (line 163) | def setup_data(self, handler_kwargs: dict = None, **kwargs):
method _prepare_seg (line 211) | def _prepare_seg(self, slc, **kwargs):
method restore_index (line 236) | def restore_index(self, index):
method restore_daily_index (line 239) | def restore_daily_index(self, daily_index):
method assign_data (line 242) | def assign_data(self, index, vals):
method clear_memory (line 249) | def clear_memory(self):
method train (line 254) | def train(self):
method eval (line 258) | def eval(self):
method _get_slices (line 265) | def _get_slices(self):
method __len__ (line 274) | def __len__(self):
method __iter__ (line 280) | def __iter__(self):
FILE: qlib/contrib/data/handler.py
function check_transform_proc (line 12) | def check_transform_proc(proc_l, fit_start_time, fit_end_time):
class Alpha360 (line 48) | class Alpha360(DataHandlerLP):
method __init__ (line 49) | def __init__(
method get_label_config (line 89) | def get_label_config(self):
class Alpha360vwap (line 93) | class Alpha360vwap(Alpha360):
method get_label_config (line 94) | def get_label_config(self):
class Alpha158 (line 98) | class Alpha158(DataHandlerLP):
method __init__ (line 99) | def __init__(
method get_feature_config (line 140) | def get_feature_config(self):
method get_label_config (line 151) | def get_label_config(self):
class Alpha158vwap (line 155) | class Alpha158vwap(Alpha158):
method get_label_config (line 156) | def get_label_config(self):
FILE: qlib/contrib/data/highfreq_handler.py
class HighFreqHandler (line 8) | class HighFreqHandler(DataHandlerLP):
method __init__ (line 9) | def __init__(
method get_feature_config (line 41) | def get_feature_config(self):
class HighFreqGeneralHandler (line 103) | class HighFreqGeneralHandler(DataHandlerLP):
method __init__ (line 104) | def __init__(
method get_feature_config (line 144) | def get_feature_config(self):
class HighFreqBacktestHandler (line 199) | class HighFreqBacktestHandler(DataHandler):
method __init__ (line 200) | def __init__(
method get_feature_config (line 221) | def get_feature_config(self):
class HighFreqGeneralBacktestHandler (line 252) | class HighFreqGeneralBacktestHandler(DataHandler):
method __init__ (line 253) | def __init__(
method get_feature_config (line 281) | def get_feature_config(self):
class HighFreqOrderHandler (line 307) | class HighFreqOrderHandler(DataHandlerLP):
method __init__ (line 308) | def __init__(
method get_feature_config (line 342) | def get_feature_config(self):
class HighFreqBacktestOrderHandler (line 462) | class HighFreqBacktestOrderHandler(DataHandler):
method __init__ (line 463) | def __init__(
method get_feature_config (line 484) | def get_feature_config(self):
FILE: qlib/contrib/data/highfreq_processor.py
class HighFreqTrans (line 10) | class HighFreqTrans(Processor):
method __init__ (line 11) | def __init__(self, dtype: str = "bool"):
method fit (line 14) | def fit(self, df_features):
method __call__ (line 17) | def __call__(self, df_features):
class HighFreqNorm (line 24) | class HighFreqNorm(Processor):
method __init__ (line 25) | def __init__(
method fit (line 37) | def fit(self, df_features) -> None:
method __call__ (line 62) | def __call__(self, df_features):
FILE: qlib/contrib/data/highfreq_provider.py
class HighFreqProvider (line 18) | class HighFreqProvider:
method __init__ (line 19) | def __init__(
method get_pre_datasets (line 48) | def get_pre_datasets(self):
method get_backtest (line 101) | def get_backtest(self, **kwargs) -> None:
method _init_qlib (line 104) | def _init_qlib(self, qlib_conf):
method _prepare_calender_cache (line 115) | def _prepare_calender_cache(self):
method _gen_dataframe (line 124) | def _gen_dataframe(self, config, datasets=["train", "valid", "test"]):
method _gen_data (line 166) | def _gen_data(self, config, datasets=["train", "valid", "test"]):
method _gen_dataset (line 196) | def _gen_dataset(self, config):
method _gen_day_dataset (line 222) | def _gen_day_dataset(self, config, conf_type):
method _gen_stock_dataset (line 263) | def _gen_stock_dataset(self, config, conf_type):
FILE: qlib/contrib/data/loader.py
class Alpha360DL (line 4) | class Alpha360DL(QlibDataLoader):
method __init__ (line 7) | def __init__(self, config=None, **kwargs):
method get_feature_config (line 16) | def get_feature_config():
class Alpha158DL (line 61) | class Alpha158DL(QlibDataLoader):
method __init__ (line 64) | def __init__(self, config=None, **kwargs):
method get_feature_config (line 73) | def get_feature_config(
FILE: qlib/contrib/data/processor.py
class ConfigSectionProcessor (line 7) | class ConfigSectionProcessor(Processor):
method __init__ (line 12) | def __init__(self, fields_group=None, **kwargs):
method __call__ (line 23) | def __call__(self, df):
method _transform (line 26) | def _transform(self, df):
FILE: qlib/contrib/data/utils/sepdf.py
function align_index (line 7) | def align_index(df_dict, join):
class SepDataFrame (line 17) | class SepDataFrame:
method __init__ (line 31) | def __init__(self, df_dict: Dict[str, pd.DataFrame], join: str, skip_a...
method loc (line 55) | def loc(self):
method index (line 59) | def index(self):
method apply_each (line 62) | def apply_each(self, method: str, skip_align=True, *args, **kwargs):
method sort_index (line 76) | def sort_index(self, *args, **kwargs):
method copy (line 79) | def copy(self, *args, **kwargs):
method _update_join (line 82) | def _update_join(self):
method __getitem__ (line 90) | def __getitem__(self, item):
method __setitem__ (line 94) | def __setitem__(self, item: str, df: Union[pd.DataFrame, pd.Series]):
method __delitem__ (line 116) | def __delitem__(self, item: str):
method __contains__ (line 120) | def __contains__(self, item):
method __len__ (line 123) | def __len__(self):
method droplevel (line 126) | def droplevel(self, *args, **kwargs):
method columns (line 130) | def columns(self):
method merge (line 140) | def merge(df_dict: Dict[str, pd.DataFrame], join: str):
class SDFLoc (line 148) | class SDFLoc:
method __init__ (line 151) | def __init__(self, sdf: SepDataFrame, join):
method __call__ (line 156) | def __call__(self, axis):
method __getitem__ (line 160) | def __getitem__(self, args):
function _isinstance (line 193) | def _isinstance(instance, cls):
FILE: qlib/contrib/eva/alpha.py
function calc_long_short_prec (line 14) | def calc_long_short_prec(
function calc_long_short_return (line 71) | def calc_long_short_return(
function pred_autocorr (line 116) | def pred_autocorr(pred: pd.Series, lag=1, inst_col="instrument", date_co...
function pred_autocorr_all (line 143) | def pred_autocorr_all(pred_dict, n_jobs=-1, **kwargs):
function calc_ic (line 160) | def calc_ic(pred: pd.Series, label: pd.Series, date_col="datetime", drop...
function calc_all_ic (line 186) | def calc_all_ic(pred_dict_all, label, date_col="datetime", dropna=False,...
FILE: qlib/contrib/evaluate.py
function risk_analysis (line 26) | def risk_analysis(r, N: int = None, freq: str = "day", mode: Literal["su...
function indicator_analysis (line 96) | def indicator_analysis(df, method="mean"):
function backtest_daily (line 147) | def backtest_daily(
function long_short_backtest (line 276) | def long_short_backtest(
function t_run (line 400) | def t_run():
FILE: qlib/contrib/evaluate_portfolio.py
function _get_position_value_from_df (line 17) | def _get_position_value_from_df(evaluate_date, position, close_data_df):
function get_position_value (line 36) | def get_position_value(evaluate_date, position):
function get_position_list_value (line 76) | def get_position_list_value(positions):
function get_daily_return_series_from_positions (line 105) | def get_daily_return_series_from_positions(positions, init_asset_value):
function get_annual_return_from_positions (line 122) | def get_annual_return_from_positions(positions, init_asset_value):
function get_annaul_return_from_return_series (line 143) | def get_annaul_return_from_return_series(r, method="ci"):
function get_sharpe_ratio_from_return_series (line 159) | def get_sharpe_ratio_from_return_series(r, risk_free_rate=0.00, method="...
function get_max_drawdown_from_series (line 178) | def get_max_drawdown_from_series(r):
function get_turnover_rate (line 195) | def get_turnover_rate():
function get_beta (line 200) | def get_beta(r, b):
function get_alpha (line 215) | def get_alpha(r, b, risk_free_rate=0.03):
function get_volatility_from_series (line 225) | def get_volatility_from_series(r):
function get_rank_ic (line 229) | def get_rank_ic(a, b):
function get_normal_ic (line 243) | def get_normal_ic(a, b):
FILE: qlib/contrib/meta/data_selection/dataset.py
class InternalData (line 23) | class InternalData:
method __init__ (line 24) | def __init__(self, task_tpl: dict, step: int, exp_name: str):
method setup (line 29) | def setup(self, trainer=TrainerR, trainer_kwargs={}):
method _calc_perf (line 107) | def _calc_perf(self, pred, label):
method update (line 113) | def update(self):
class MetaTaskDS (line 121) | class MetaTaskDS(MetaTask):
method __init__ (line 124) | def __init__(self, task: dict, meta_info: pd.DataFrame, mode: str = Me...
method _get_processed_meta_info (line 191) | def _get_processed_meta_info(self):
method get_meta_input (line 233) | def get_meta_input(self):
class MetaDatasetDS (line 237) | class MetaDatasetDS(MetaTaskDataset):
method __init__ (line 238) | def __init__(
method _prepare_meta_ipt (line 331) | def _prepare_meta_ipt(self, task) -> pd.DataFrame:
method _prepare_seg (line 386) | def _prepare_seg(self, segment: Text) -> List[MetaTask]:
FILE: qlib/contrib/meta/data_selection/model.py
class TimeReweighter (line 27) | class TimeReweighter(Reweighter):
method __init__ (line 28) | def __init__(self, time_weight: pd.Series):
method reweight (line 31) | def reweight(self, data: Union[pd.DataFrame, pd.Series]):
class MetaModelDS (line 40) | class MetaModelDS(MetaTaskModel):
method __init__ (line 45) | def __init__(
method run_epoch (line 74) | def run_epoch(self, phase, task_list, epoch, opt, loss_l, ignore_weigh...
method fit (line 137) | def fit(self, meta_dataset: MetaDatasetDS):
method _prepare_task (line 183) | def _prepare_task(self, task: MetaTask) -> dict:
method inference (line 192) | def inference(self, meta_dataset: MetaTaskDataset) -> List[dict]:
FILE: qlib/contrib/meta/data_selection/net.py
class TimeWeightMeta (line 11) | class TimeWeightMeta(SingleMetaBase):
method __init__ (line 12) | def __init__(self, hist_step_n, clip_weight=None, clip_method="clamp"):
method forward (line 18) | def forward(self, time_perf, time_belong=None, return_preds=False):
class PredNet (line 43) | class PredNet(nn.Module):
method __init__ (line 44) | def __init__(self, step, hist_step_n, clip_weight=None, clip_method="t...
method get_sample_weights (line 57) | def get_sample_weights(self, X, time_perf, time_belong, ignore_weight=...
method forward (line 65) | def forward(self, X, y, time_perf, time_belong, X_test, ignore_weight=...
method init_paramters (line 72) | def init_paramters(self, hist_step_n):
FILE: qlib/contrib/meta/data_selection/utils.py
class ICLoss (line 12) | class ICLoss(nn.Module):
method __init__ (line 13) | def __init__(self, skip_size=50):
method forward (line 17) | def forward(self, pred, y, idx):
function preds_to_weight_with_clamp (line 67) | def preds_to_weight_with_clamp(preds, clip_weight=None, clip_method="tan...
class SingleMetaBase (line 99) | class SingleMetaBase(nn.Module):
method __init__ (line 100) | def __init__(self, hist_n, clip_weight=None, clip_method="clamp"):
method is_enabled (line 109) | def is_enabled(self):
FILE: qlib/contrib/model/catboost_model.py
class CatBoostModel (line 17) | class CatBoostModel(Model, FeatureInt):
method __init__ (line 20) | def __init__(self, loss="RMSE", **kwargs):
method fit (line 28) | def fit(
method predict (line 80) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method get_feature_importance (line 86) | def get_feature_importance(self, *args, **kwargs) -> pd.Series:
FILE: qlib/contrib/model/double_ensemble.py
class DEnsembleModel (line 15) | class DEnsembleModel(Model, FeatureInt):
method __init__ (line 18) | def __init__(
method fit (line 65) | def fit(self, dataset: DatasetH):
method train_submodel (line 105) | def train_submodel(self, df_train, df_valid, weights, features):
method _prepare_data_gbm (line 126) | def _prepare_data_gbm(self, df_train, df_valid, weights, features):
method sample_reweight (line 140) | def sample_reweight(self, loss_curve, loss_values, k_th):
method feature_selection (line 175) | def feature_selection(self, df_train, loss_values):
method get_loss (line 221) | def get_loss(self, label, pred):
method retrieve_loss_curve (line 227) | def retrieve_loss_curve(self, model, df_train, features):
method predict (line 247) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method predict_sub (line 261) | def predict_sub(self, submodel, df_data, features):
method get_feature_importance (line 266) | def get_feature_importance(self, *args, **kwargs) -> pd.Series:
FILE: qlib/contrib/model/gbdt.py
class LGBModel (line 16) | class LGBModel(ModelFT, LightGBMFInt):
method __init__ (line 19) | def __init__(self, loss="mse", early_stopping_rounds=50, num_boost_rou...
method _prepare_data (line 28) | def _prepare_data(self, dataset: DatasetH, reweighter=None) -> List[Tu...
method fit (line 57) | def fit(
method predict (line 92) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method finetune (line 98) | def finetune(self, dataset: DatasetH, num_boost_round=10, verbose_eval...
FILE: qlib/contrib/model/highfreq_gdbt_model.py
class HFLGBModel (line 15) | class HFLGBModel(ModelFT, LightGBMFInt):
method __init__ (line 18) | def __init__(self, loss="mse", **kwargs):
method _cal_signal_metrics (line 25) | def _cal_signal_metrics(self, y_test, l_cut, r_cut):
method hf_signal_test (line 57) | def hf_signal_test(self, dataset: DatasetH, threhold=0.2):
method _prepare_data (line 81) | def _prepare_data(self, dataset: DatasetH):
method fit (line 116) | def fit(
method predict (line 141) | def predict(self, dataset):
method finetune (line 147) | def finetune(self, dataset: DatasetH, num_boost_round=10, verbose_eval...
FILE: qlib/contrib/model/linear.py
class LinearModel (line 17) | class LinearModel(Model):
method __init__ (line 33) | def __init__(self, estimator="ols", alpha=0.0, fit_intercept=False, in...
method fit (line 58) | def fit(self, dataset: DatasetH, reweighter: Reweighter = None):
method _fit (line 85) | def _fit(self, X, y, w):
method _fit_nnls (line 96) | def _fit_nnls(self, X, y, w=None):
method predict (line 109) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
FILE: qlib/contrib/model/pytorch_adarnn.py
class ADARNN (line 23) | class ADARNN(Model):
method __init__ (line 38) | def __init__(
method use_gpu (line 150) | def use_gpu(self):
method train_AdaRNN (line 153) | def train_AdaRNN(self, train_loader_list, epoch, dist_old=None, weight...
method calc_all_metrics (line 214) | def calc_all_metrics(pred):
method test_epoch (line 229) | def test_epoch(self, df):
method log_metrics (line 237) | def log_metrics(self, mode, metrics):
method fit (line 242) | def fit(
method predict (line 304) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method infer (line 310) | def infer(self, x_test):
method transform_type (line 333) | def transform_type(self, init_weight):
class data_loader (line 341) | class data_loader(Dataset):
method __init__ (line 342) | def __init__(self, df):
method __getitem__ (line 351) | def __getitem__(self, index):
method __len__ (line 355) | def __len__(self):
function get_stock_loader (line 359) | def get_stock_loader(df, batch_size, shuffle=True):
function get_index (line 364) | def get_index(num_domain=2):
class AdaRNN (line 372) | class AdaRNN(nn.Module):
method __init__ (line 377) | def __init__(
method init_layers (line 440) | def init_layers(self):
method forward_pre_train (line 445) | def forward_pre_train(self, x, len_win=0):
method gru_features (line 474) | def gru_features(self, x, predict=False):
method process_gate_weight (line 488) | def process_gate_weight(self, out, index):
method get_features (line 499) | def get_features(output_list):
method forward_Boosting (line 507) | def forward_Boosting(self, x, weight_mat=None):
method update_weight_Boosting (line 533) | def update_weight_Boosting(self, weight_mat, dist_old, dist_new):
method predict (line 543) | def predict(self, x):
class TransferLoss (line 554) | class TransferLoss:
method __init__ (line 555) | def __init__(self, loss_type="cosine", input_dim=512, GPU=0):
method compute (line 563) | def compute(self, X, Y):
function cosine (line 600) | def cosine(source, target):
class ReverseLayerF (line 607) | class ReverseLayerF(Function):
method forward (line 609) | def forward(ctx, x, alpha):
method backward (line 614) | def backward(ctx, grad_output):
class Discriminator (line 619) | class Discriminator(nn.Module):
method __init__ (line 620) | def __init__(self, input_dim=256, hidden_dim=256):
method forward (line 627) | def forward(self, x):
function adv (line 634) | def adv(source, target, device, input_dim=256, hidden_dim=512):
function CORAL (line 650) | def CORAL(source, target, device):
class MMD_loss (line 669) | class MMD_loss(nn.Module):
method __init__ (line 670) | def __init__(self, kernel_type="linear", kernel_mul=2.0, kernel_num=5):
method guassian_kernel (line 678) | def guassian_kernel(source, target, kernel_mul=2.0, kernel_num=5, fix_...
method linear_mmd (line 694) | def linear_mmd(X, Y):
method forward (line 699) | def forward(self, source, target):
class Mine_estimator (line 716) | class Mine_estimator(nn.Module):
method __init__ (line 717) | def __init__(self, input_dim=2048, hidden_dim=512):
method forward (line 721) | def forward(self, X, Y):
class Mine (line 730) | class Mine(nn.Module):
method __init__ (line 731) | def __init__(self, input_dim=2048, hidden_dim=512):
method forward (line 737) | def forward(self, x, y):
function pairwise_dist (line 743) | def pairwise_dist(X, Y):
function pairwise_dist_np (line 752) | def pairwise_dist_np(X, Y):
function pa (line 763) | def pa(X, Y):
function kl_div (line 773) | def kl_div(source, target):
function js (line 783) | def js(source, target):
FILE: qlib/contrib/model/pytorch_add.py
class ADD (line 29) | class ADD(Model):
method __init__ (line 46) | def __init__(
method use_gpu (line 164) | def use_gpu(self):
method loss_pre_excess (line 167) | def loss_pre_excess(self, pred_excess, label_excess, record=None):
method loss_pre_market (line 174) | def loss_pre_market(self, pred_market, label_market, record=None):
method loss_pre (line 180) | def loss_pre(self, pred_excess, label_excess, pred_market, label_marke...
method loss_adv_excess (line 188) | def loss_adv_excess(self, adv_excess, label_excess, record=None):
method loss_adv_market (line 195) | def loss_adv_market(self, adv_market, label_market, record=None):
method loss_adv (line 201) | def loss_adv(self, adv_excess, label_excess, adv_market, label_market,...
method loss_fn (line 209) | def loss_fn(self, x, preds, label_excess, label_market, record=None):
method loss_rec (line 219) | def loss_rec(self, x, rec_x, record=None):
method get_daily_inter (line 227) | def get_daily_inter(self, df, shuffle=False):
method cal_ic_metrics (line 239) | def cal_ic_metrics(self, pred, label):
method test_epoch (line 249) | def test_epoch(self, data_x, data_y, data_m):
method train_epoch (line 278) | def train_epoch(self, x_train_values, y_train_values, m_train_values):
method log_metrics (line 304) | def log_metrics(self, mode, metrics):
method bootstrap_fit (line 309) | def bootstrap_fit(self, x_train, y_train, m_train, x_valid, y_valid, m...
method gen_market_label (line 351) | def gen_market_label(self, df, raw_label):
method fit_thresh (line 359) | def fit_thresh(self, train_label):
method fit (line 363) | def fit(
method predict (line 419) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class ADDModel (line 442) | class ADDModel(nn.Module):
method __init__ (line 443) | def __init__(
method forward (line 494) | def forward(self, x):
class Decoder (line 527) | class Decoder(nn.Module):
method __init__ (line 528) | def __init__(self, d_feat=6, hidden_size=128, num_layers=1, dropout=0....
method forward (line 552) | def forward(self, x, hidden):
class RevGradFunc (line 560) | class RevGradFunc(Function):
method forward (line 562) | def forward(ctx, input_, alpha_):
method backward (line 568) | def backward(ctx, grad_output): # pragma: no cover
class RevGrad (line 576) | class RevGrad(nn.Module):
method __init__ (line 577) | def __init__(self, gamma=0.1, gamma_clip=0.4, *args, **kwargs):
method step_alpha (line 590) | def step_alpha(self):
method forward (line 596) | def forward(self, input_):
FILE: qlib/contrib/model/pytorch_alstm.py
class ALSTM (line 25) | class ALSTM(Model):
method __init__ (line 40) | def __init__(
method use_gpu (line 133) | def use_gpu(self):
method mse (line 136) | def mse(self, pred, label):
method loss_fn (line 140) | def loss_fn(self, pred, label):
method metric_fn (line 148) | def metric_fn(self, pred, label):
method train_epoch (line 156) | def train_epoch(self, x_train, y_train):
method test_epoch (line 180) | def test_epoch(self, data_x, data_y):
method fit (line 209) | def fit(
method predict (line 267) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class ALSTMModel (line 294) | class ALSTMModel(nn.Module):
method __init__ (line 295) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method _build_model (line 304) | def _build_model(self):
method forward (line 333) | def forward(self, inputs):
FILE: qlib/contrib/model/pytorch_alstm_ts.py
class ALSTM (line 28) | class ALSTM(Model):
method __init__ (line 43) | def __init__(
method use_gpu (line 140) | def use_gpu(self):
method mse (line 143) | def mse(self, pred, label, weight):
method loss_fn (line 147) | def loss_fn(self, pred, label, weight=None):
method metric_fn (line 158) | def metric_fn(self, pred, label):
method train_epoch (line 170) | def train_epoch(self, data_loader):
method test_epoch (line 185) | def test_epoch(self, data_loader):
method fit (line 206) | def fit(
method predict (line 287) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class ALSTMModel (line 308) | class ALSTMModel(nn.Module):
method __init__ (line 309) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method _build_model (line 318) | def _build_model(self):
method forward (line 347) | def forward(self, inputs):
FILE: qlib/contrib/model/pytorch_gats.py
class GATs (line 26) | class GATs(Model):
method __init__ (line 43) | def __init__(
method use_gpu (line 141) | def use_gpu(self):
method mse (line 144) | def mse(self, pred, label):
method loss_fn (line 148) | def loss_fn(self, pred, label):
method metric_fn (line 156) | def metric_fn(self, pred, label):
method get_daily_inter (line 164) | def get_daily_inter(self, df, shuffle=False):
method train_epoch (line 176) | def train_epoch(self, x_train, y_train):
method test_epoch (line 197) | def test_epoch(self, data_x, data_y):
method fit (line 224) | def fit(
method predict (line 301) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class GATModel (line 326) | class GATModel(nn.Module):
method __init__ (line 327) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method cal_attention (line 359) | def cal_attention(self, x, y):
method forward (line 374) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_gats_ts.py
class DailyBatchSampler (line 26) | class DailyBatchSampler(Sampler):
method __init__ (line 27) | def __init__(self, data_source):
method __iter__ (line 36) | def __iter__(self):
method __len__ (line 40) | def __len__(self):
class GATs (line 44) | class GATs(Model):
method __init__ (line 61) | def __init__(
method use_gpu (line 161) | def use_gpu(self):
method mse (line 164) | def mse(self, pred, label):
method loss_fn (line 168) | def loss_fn(self, pred, label):
method metric_fn (line 176) | def metric_fn(self, pred, label):
method get_daily_inter (line 184) | def get_daily_inter(self, df, shuffle=False):
method train_epoch (line 196) | def train_epoch(self, data_loader):
method test_epoch (line 212) | def test_epoch(self, data_loader):
method fit (line 233) | def fit(
method predict (line 315) | def predict(self, dataset):
class GATModel (line 338) | class GATModel(nn.Module):
method __init__ (line 339) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method cal_attention (line 371) | def cal_attention(self, x, y):
method forward (line 386) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_general_nn.py
class GeneralPTNN (line 33) | class GeneralPTNN(Model):
method __init__ (line 52) | def __init__(
method use_gpu (line 148) | def use_gpu(self):
method mse (line 151) | def mse(self, pred, label, weight):
method loss_fn (line 155) | def loss_fn(self, pred, label, weight=None):
method metric_fn (line 166) | def metric_fn(self, pred, label):
method _get_fl (line 174) | def _get_fl(self, data: torch.Tensor):
method train_epoch (line 202) | def train_epoch(self, data_loader):
method test_epoch (line 216) | def test_epoch(self, data_loader):
method fit (line 235) | def fit(
method predict (line 334) | def predict(
FILE: qlib/contrib/model/pytorch_gru.py
class GRU (line 25) | class GRU(Model):
method __init__ (line 40) | def __init__(
method use_gpu (line 133) | def use_gpu(self):
method mse (line 136) | def mse(self, pred, label):
method loss_fn (line 140) | def loss_fn(self, pred, label):
method metric_fn (line 148) | def metric_fn(self, pred, label):
method train_epoch (line 156) | def train_epoch(self, x_train, y_train):
method test_epoch (line 180) | def test_epoch(self, data_x, data_y):
method fit (line 209) | def fit(
method predict (line 292) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class GRUModel (line 319) | class GRUModel(nn.Module):
method __init__ (line 320) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
method forward (line 334) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_gru_ts.py
class GRU (line 26) | class GRU(Model):
method __init__ (line 41) | def __init__(
method use_gpu (line 138) | def use_gpu(self):
method mse (line 141) | def mse(self, pred, label, weight):
method loss_fn (line 145) | def loss_fn(self, pred, label, weight=None):
method metric_fn (line 156) | def metric_fn(self, pred, label):
method train_epoch (line 164) | def train_epoch(self, data_loader):
method test_epoch (line 179) | def test_epoch(self, data_loader):
method fit (line 200) | def fit(
method predict (line 281) | def predict(self, dataset):
class GRUModel (line 302) | class GRUModel(nn.Module):
method __init__ (line 303) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
method forward (line 317) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_hist.py
class HIST (line 27) | class HIST(Model):
method __init__ (line 44) | def __init__(
method use_gpu (line 147) | def use_gpu(self):
method mse (line 150) | def mse(self, pred, label):
method loss_fn (line 154) | def loss_fn(self, pred, label):
method metric_fn (line 162) | def metric_fn(self, pred, label):
method get_daily_inter (line 178) | def get_daily_inter(self, df, shuffle=False):
method train_epoch (line 190) | def train_epoch(self, x_train, y_train, stock_index):
method test_epoch (line 214) | def test_epoch(self, data_x, data_y, stock_index):
method fit (line 244) | def fit(
method predict (line 330) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class HISTModel (line 365) | class HISTModel(nn.Module):
method __init__ (line 366) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method cal_cos_similarity (line 424) | def cal_cos_similarity(self, x, y): # the 2nd dimension of x and y ar...
method forward (line 431) | def forward(self, x, concept_matrix):
FILE: qlib/contrib/model/pytorch_igmtf.py
class IGMTF (line 27) | class IGMTF(Model):
method __init__ (line 42) | def __init__(
method use_gpu (line 140) | def use_gpu(self):
method mse (line 143) | def mse(self, pred, label):
method loss_fn (line 147) | def loss_fn(self, pred, label):
method metric_fn (line 155) | def metric_fn(self, pred, label):
method get_daily_inter (line 171) | def get_daily_inter(self, df, shuffle=False):
method get_train_hidden (line 183) | def get_train_hidden(self, x_train):
method train_epoch (line 202) | def train_epoch(self, x_train, y_train, train_hidden, train_hidden_day):
method test_epoch (line 222) | def test_epoch(self, data_x, data_y, train_hidden, train_hidden_day):
method fit (line 248) | def fit(
method predict (line 327) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class IGMTFModel (line 357) | class IGMTFModel(nn.Module):
method __init__ (line 358) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0...
method cal_cos_similarity (line 391) | def cal_cos_similarity(self, x, y): # the 2nd dimension of x and y ar...
method sparse_dense_mul (line 398) | def sparse_dense_mul(self, s, d):
method forward (line 404) | def forward(self, x, get_hidden=False, train_hidden=None, train_hidden...
FILE: qlib/contrib/model/pytorch_krnn.py
class CNNEncoderBase (line 28) | class CNNEncoderBase(nn.Module):
method __init__ (line 29) | def __init__(self, input_dim, output_dim, kernel_size, device):
method forward (line 52) | def forward(self, x):
class KRNNEncoderBase (line 74) | class KRNNEncoderBase(nn.Module):
method __init__ (line 75) | def __init__(self, input_dim, output_dim, dup_num, rnn_layers, dropout...
method forward (line 102) | def forward(self, x):
class CNNKRNNEncoder (line 136) | class CNNKRNNEncoder(nn.Module):
method __init__ (line 137) | def __init__(
method forward (line 162) | def forward(self, x):
class KRNNModel (line 182) | class KRNNModel(nn.Module):
method __init__ (line 183) | def __init__(self, fea_dim, cnn_dim, cnn_kernel_size, rnn_dim, rnn_dup...
method forward (line 217) | def forward(self, x):
class KRNN (line 225) | class KRNN(Model):
method __init__ (line 240) | def __init__(
method use_gpu (line 346) | def use_gpu(self):
method mse (line 349) | def mse(self, pred, label):
method loss_fn (line 353) | def loss_fn(self, pred, label):
method metric_fn (line 361) | def metric_fn(self, pred, label):
method get_daily_inter (line 369) | def get_daily_inter(self, df, shuffle=False):
method train_epoch (line 381) | def train_epoch(self, x_train, y_train):
method test_epoch (line 404) | def test_epoch(self, data_x, data_y):
method fit (line 432) | def fit(
method predict (line 490) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
FILE: qlib/contrib/model/pytorch_localformer.py
class LocalformerModel (line 28) | class LocalformerModel(Model):
method __init__ (line 29) | def __init__(
method use_gpu (line 82) | def use_gpu(self):
method mse (line 85) | def mse(self, pred, label):
method loss_fn (line 89) | def loss_fn(self, pred, label):
method metric_fn (line 97) | def metric_fn(self, pred, label):
method train_epoch (line 105) | def train_epoch(self, x_train, y_train):
method test_epoch (line 129) | def test_epoch(self, data_x, data_y):
method fit (line 158) | def fit(
method predict (line 216) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class PositionalEncoding (line 243) | class PositionalEncoding(nn.Module):
method __init__ (line 244) | def __init__(self, d_model, max_len=1000):
method forward (line 254) | def forward(self, x):
function _get_clones (line 259) | def _get_clones(module, N):
class LocalformerEncoder (line 263) | class LocalformerEncoder(nn.Module):
method __init__ (line 266) | def __init__(self, encoder_layer, num_layers, d_model):
method forward (line 272) | def forward(self, src, mask):
class Transformer (line 286) | class Transformer(nn.Module):
method __init__ (line 287) | def __init__(self, d_feat=6, d_model=8, nhead=4, num_layers=2, dropout...
method forward (line 304) | def forward(self, src):
FILE: qlib/contrib/model/pytorch_localformer_ts.py
class LocalformerModel (line 26) | class LocalformerModel(Model):
method __init__ (line 27) | def __init__(
method use_gpu (line 82) | def use_gpu(self):
method mse (line 85) | def mse(self, pred, label):
method loss_fn (line 89) | def loss_fn(self, pred, label):
method metric_fn (line 97) | def metric_fn(self, pred, label):
method train_epoch (line 105) | def train_epoch(self, data_loader):
method test_epoch (line 120) | def test_epoch(self, data_loader):
method fit (line 140) | def fit(
method predict (line 203) | def predict(self, dataset):
class PositionalEncoding (line 224) | class PositionalEncoding(nn.Module):
method __init__ (line 225) | def __init__(self, d_model, max_len=1000):
method forward (line 235) | def forward(self, x):
function _get_clones (line 240) | def _get_clones(module, N):
class LocalformerEncoder (line 244) | class LocalformerEncoder(nn.Module):
method __init__ (line 247) | def __init__(self, encoder_layer, num_layers, d_model):
method forward (line 253) | def forward(self, src, mask):
class Transformer (line 267) | class Transformer(nn.Module):
method __init__ (line 268) | def __init__(self, d_feat=6, d_model=8, nhead=4, num_layers=2, dropout...
method forward (line 285) | def forward(self, src):
FILE: qlib/contrib/model/pytorch_lstm.py
class LSTM (line 24) | class LSTM(Model):
method __init__ (line 39) | def __init__(
method use_gpu (line 129) | def use_gpu(self):
method mse (line 132) | def mse(self, pred, label):
method loss_fn (line 136) | def loss_fn(self, pred, label):
method metric_fn (line 144) | def metric_fn(self, pred, label):
method train_epoch (line 152) | def train_epoch(self, x_train, y_train):
method test_epoch (line 176) | def test_epoch(self, data_x, data_y):
method fit (line 204) | def fit(
method predict (line 262) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class LSTMModel (line 286) | class LSTMModel(nn.Module):
method __init__ (line 287) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
method forward (line 301) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_lstm_ts.py
class LSTM (line 25) | class LSTM(Model):
method __init__ (line 40) | def __init__(
method use_gpu (line 134) | def use_gpu(self):
method mse (line 137) | def mse(self, pred, label, weight):
method loss_fn (line 141) | def loss_fn(self, pred, label, weight):
method metric_fn (line 152) | def metric_fn(self, pred, label):
method train_epoch (line 160) | def train_epoch(self, data_loader):
method test_epoch (line 175) | def test_epoch(self, data_loader):
method fit (line 195) | def fit(
method predict (line 276) | def predict(self, dataset):
class LSTMModel (line 297) | class LSTMModel(nn.Module):
method __init__ (line 298) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
method forward (line 312) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_nn.py
class DNNModelPytorch (line 39) | class DNNModelPytorch(Model):
method __init__ (line 57) | def __init__(
method use_gpu (line 187) | def use_gpu(self):
method fit (line 190) | def fit(
method get_lr (line 338) | def get_lr(self):
method get_loss (line 342) | def get_loss(self, pred, w, target, loss_type):
method get_metric (line 354) | def get_metric(self, pred, target, index):
method _nn_predict (line 358) | def _nn_predict(self, data, return_cpu=True):
method predict (line 382) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method save (line 389) | def save(self, filename, **kwargs):
method load (line 395) | def load(self, buffer, **kwargs):
class AverageMeter (line 407) | class AverageMeter:
method __init__ (line 410) | def __init__(self):
method reset (line 413) | def reset(self):
method update (line 419) | def update(self, val, n=1):
class Net (line 426) | class Net(nn.Module):
method __init__ (line 427) | def __init__(self, input_dim, output_dim=1, layers=(256,), act="LeakyR...
method _weight_init (line 454) | def _weight_init(self):
method forward (line 459) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_sandwich.py
class SandwichModel (line 25) | class SandwichModel(nn.Module):
method __init__ (line 26) | def __init__(
method forward (line 88) | def forward(self, x):
class Sandwich (line 97) | class Sandwich(Model):
method __init__ (line 112) | def __init__(
method use_gpu (line 228) | def use_gpu(self):
method mse (line 231) | def mse(self, pred, label):
method loss_fn (line 235) | def loss_fn(self, pred, label):
method metric_fn (line 243) | def metric_fn(self, pred, label):
method train_epoch (line 251) | def train_epoch(self, x_train, y_train):
method test_epoch (line 274) | def test_epoch(self, data_x, data_y):
method fit (line 302) | def fit(
method predict (line 360) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
FILE: qlib/contrib/model/pytorch_sfm.py
class SFM_Model (line 25) | class SFM_Model(nn.Module):
method __init__ (line 26) | def __init__(
method forward (line 77) | def forward(self, input):
method init_states (line 141) | def init_states(self, x):
method get_constants (line 170) | def get_constants(self, x):
class SFM (line 180) | class SFM(Model):
method __init__ (line 197) | def __init__(
method use_gpu (line 305) | def use_gpu(self):
method test_epoch (line 308) | def test_epoch(self, data_x, data_y):
method train_epoch (line 336) | def train_epoch(self, x_train, y_train):
method fit (line 360) | def fit(
method mse (line 416) | def mse(self, pred, label):
method loss_fn (line 420) | def loss_fn(self, pred, label):
method metric_fn (line 428) | def metric_fn(self, pred, label):
method predict (line 436) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class AverageMeter (line 463) | class AverageMeter:
method __init__ (line 466) | def __init__(self):
method reset (line 469) | def reset(self):
method update (line 475) | def update(self, val, n=1):
FILE: qlib/contrib/model/pytorch_tabnet.py
class TabnetModel (line 25) | class TabnetModel(Model):
method __init__ (line 26) | def __init__(
method use_gpu (line 109) | def use_gpu(self):
method pretrain_fn (line 112) | def pretrain_fn(self, dataset=DatasetH, pretrain_file="./pretrain/best...
method fit (line 151) | def fit(
method predict (line 217) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method test_epoch (line 245) | def test_epoch(self, data_x, data_y):
method train_epoch (line 274) | def train_epoch(self, x_train, y_train):
method pretrain_epoch (line 299) | def pretrain_epoch(self, x_train):
method pretrain_test_epoch (line 328) | def pretrain_test_epoch(self, x_train):
method pretrain_loss_fn (line 359) | def pretrain_loss_fn(self, f_hat, f, S):
method loss_fn (line 368) | def loss_fn(self, pred, label):
method metric_fn (line 374) | def metric_fn(self, pred, label):
method mse (line 380) | def mse(self, pred, label):
class FinetuneModel (line 385) | class FinetuneModel(nn.Module):
method __init__ (line 390) | def __init__(self, input_dim, output_dim, trained_model):
method forward (line 395) | def forward(self, x, priors):
class DecoderStep (line 399) | class DecoderStep(nn.Module):
method __init__ (line 400) | def __init__(self, inp_dim, out_dim, shared, n_ind, vbs):
method forward (line 405) | def forward(self, x):
class TabNet_Decoder (line 410) | class TabNet_Decoder(nn.Module):
method __init__ (line 411) | def __init__(self, inp_dim, out_dim, n_shared, n_ind, vbs, n_steps):
method forward (line 429) | def forward(self, x):
class TabNet (line 436) | class TabNet(nn.Module):
method __init__ (line 437) | def __init__(self, inp_dim=6, out_dim=6, n_d=64, n_a=64, n_shared=2, n...
method forward (line 469) | def forward(self, x, priors):
class GBN (line 483) | class GBN(nn.Module):
method __init__ (line 492) | def __init__(self, inp, vbs=1024, momentum=0.01):
method forward (line 497) | def forward(self, x):
class GLU (line 506) | class GLU(nn.Module):
method __init__ (line 514) | def __init__(self, inp_dim, out_dim, fc=None, vbs=1024):
method forward (line 523) | def forward(self, x):
class AttentionTransformer (line 528) | class AttentionTransformer(nn.Module):
method __init__ (line 536) | def __init__(self, d_a, inp_dim, relax, vbs=1024):
method forward (line 543) | def forward(self, a, priors):
class FeatureTransformer (line 550) | class FeatureTransformer(nn.Module):
method __init__ (line 551) | def __init__(self, inp_dim, out_dim, shared, n_ind, vbs):
method forward (line 569) | def forward(self, x):
class DecisionStep (line 581) | class DecisionStep(nn.Module):
method __init__ (line 586) | def __init__(self, inp_dim, n_d, n_a, shared, n_ind, relax, vbs):
method forward (line 591) | def forward(self, x, a, priors):
function make_ix_like (line 598) | def make_ix_like(input, dim=0):
class SparsemaxFunction (line 606) | class SparsemaxFunction(Function):
method forward (line 612) | def forward(ctx, input, dim=-1):
method backward (line 622) | def backward(ctx, grad_output):
method threshold_and_support (line 634) | def threshold_and_support(input, dim=-1):
FILE: qlib/contrib/model/pytorch_tcn.py
class TCN (line 26) | class TCN(Model):
method __init__ (line 43) | def __init__(
method use_gpu (line 141) | def use_gpu(self):
method mse (line 144) | def mse(self, pred, label):
method loss_fn (line 148) | def loss_fn(self, pred, label):
method metric_fn (line 156) | def metric_fn(self, pred, label):
method train_epoch (line 164) | def train_epoch(self, x_train, y_train):
method test_epoch (line 188) | def test_epoch(self, data_x, data_y):
method fit (line 216) | def fit(
method predict (line 272) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class TCNModel (line 299) | class TCNModel(nn.Module):
method __init__ (line 300) | def __init__(self, num_input, output_size, num_channels, kernel_size, ...
method forward (line 306) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_tcn_ts.py
class TCN (line 25) | class TCN(Model):
method __init__ (line 40) | def __init__(
method use_gpu (line 142) | def use_gpu(self):
method mse (line 145) | def mse(self, pred, label):
method loss_fn (line 149) | def loss_fn(self, pred, label):
method metric_fn (line 157) | def metric_fn(self, pred, label):
method train_epoch (line 165) | def train_epoch(self, data_loader):
method test_epoch (line 181) | def test_epoch(self, data_loader):
method fit (line 203) | def fit(
method predict (line 266) | def predict(self, dataset):
class TCNModel (line 287) | class TCNModel(nn.Module):
method __init__ (line 288) | def __init__(self, num_input, output_size, num_channels, kernel_size, ...
method forward (line 294) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_tcts.py
class TCTS (line 24) | class TCTS(Model):
method __init__ (line 39) | def __init__(
method loss_fn (line 121) | def loss_fn(self, pred, label, weight):
method train_epoch (line 134) | def train_epoch(self, x_train, y_train, x_valid, y_valid):
method test_epoch (line 211) | def test_epoch(self, data_x, data_y):
method fit (line 235) | def fit(
method training (line 269) | def training(
method predict (line 351) | def predict(self, dataset):
class MLPModel (line 381) | class MLPModel(nn.Module):
method __init__ (line 382) | def __init__(self, d_feat, hidden_size=256, num_layers=3, dropout=0.0,...
method forward (line 396) | def forward(self, x):
class GRUModel (line 404) | class GRUModel(nn.Module):
method __init__ (line 405) | def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
method forward (line 419) | def forward(self, x):
FILE: qlib/contrib/model/pytorch_tra.py
class TRAModel (line 33) | class TRAModel(Model):
method __init__ (line 62) | def __init__(
method _init_model (line 137) | def _init_model(self):
method train_epoch (line 176) | def train_epoch(self, epoch, data_set, is_pretrain=False):
method test_epoch (line 273) | def test_epoch(self, epoch, data_set, return_pred=False, prefix="test"...
method _fit (line 358) | def _fit(self, train_set, valid_set, test_set, evals_result, is_pretra...
method fit (line 416) | def fit(self, dataset, evals_result=dict()):
method predict (line 499) | def predict(self, dataset, segment="test"):
class RNN (line 513) | class RNN(nn.Module):
method __init__ (line 526) | def __init__(
method forward (line 565) | def forward(self, x):
class PositionalEncoding (line 583) | class PositionalEncoding(nn.Module):
method __init__ (line 585) | def __init__(self, d_model, dropout=0.1, max_len=5000):
method forward (line 597) | def forward(self, x):
class Transformer (line 602) | class Transformer(nn.Module):
method __init__ (line 613) | def __init__(
method forward (line 639) | def forward(self, x):
class TRA (line 649) | class TRA(nn.Module):
method __init__ (line 664) | def __init__(
method reset_parameters (line 699) | def reset_parameters(self):
method forward (line 703) | def forward(self, hidden, hist_loss):
function evaluate (line 727) | def evaluate(pred):
function shoot_infs (line 738) | def shoot_infs(inp_tensor):
function sinkhorn (line 757) | def sinkhorn(Q, n_iters=3, epsilon=0.1):
function loss_fn (line 768) | def loss_fn(pred, label):
function minmax_norm (line 775) | def minmax_norm(x):
function transport_sample (line 784) | def transport_sample(all_preds, label, choice, prob, hist_loss, count, t...
function transport_daily (line 829) | def transport_daily(all_preds, label, choice, prob, hist_loss, count, tr...
function load_state_dict_unsafe (line 886) | def load_state_dict_unsafe(model, state_dict):
function plot (line 916) | def plot(P):
FILE: qlib/contrib/model/pytorch_transformer.py
class TransformerModel (line 27) | class TransformerModel(Model):
method __init__ (line 28) | def __init__(
method use_gpu (line 81) | def use_gpu(self):
method mse (line 84) | def mse(self, pred, label):
method loss_fn (line 88) | def loss_fn(self, pred, label):
method metric_fn (line 96) | def metric_fn(self, pred, label):
method train_epoch (line 104) | def train_epoch(self, x_train, y_train):
method test_epoch (line 128) | def test_epoch(self, data_x, data_y):
method fit (line 157) | def fit(
method predict (line 215) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
class PositionalEncoding (line 242) | class PositionalEncoding(nn.Module):
method __init__ (line 243) | def __init__(self, d_model, max_len=1000):
method forward (line 253) | def forward(self, x):
class Transformer (line 258) | class Transformer(nn.Module):
method __init__ (line 259) | def __init__(self, d_feat=6, d_model=8, nhead=4, num_layers=2, dropout...
method forward (line 269) | def forward(self, src):
FILE: qlib/contrib/model/pytorch_transformer_ts.py
class TransformerModel (line 25) | class TransformerModel(Model):
method __init__ (line 26) | def __init__(
method use_gpu (line 79) | def use_gpu(self):
method mse (line 82) | def mse(self, pred, label):
method loss_fn (line 86) | def loss_fn(self, pred, label):
method metric_fn (line 94) | def metric_fn(self, pred, label):
method train_epoch (line 102) | def train_epoch(self, data_loader):
method test_epoch (line 117) | def test_epoch(self, data_loader):
method fit (line 137) | def fit(
method predict (line 201) | def predict(self, dataset):
class PositionalEncoding (line 222) | class PositionalEncoding(nn.Module):
method __init__ (line 223) | def __init__(self, d_model, max_len=1000):
method forward (line 233) | def forward(self, x):
class Transformer (line 238) | class Transformer(nn.Module):
method __init__ (line 239) | def __init__(self, d_feat=6, d_model=8, nhead=4, num_layers=2, dropout...
method forward (line 249) | def forward(self, src):
FILE: qlib/contrib/model/pytorch_utils.py
function count_parameters (line 7) | def count_parameters(models_or_parameters, unit="m"):
FILE: qlib/contrib/model/tcn.py
class Chomp1d (line 7) | class Chomp1d(nn.Module):
method __init__ (line 8) | def __init__(self, chomp_size):
method forward (line 12) | def forward(self, x):
class TemporalBlock (line 16) | class TemporalBlock(nn.Module):
method __init__ (line 17) | def __init__(self, n_inputs, n_outputs, kernel_size, stride, dilation,...
method init_weights (line 40) | def init_weights(self):
method forward (line 46) | def forward(self, x):
class TemporalConvNet (line 52) | class TemporalConvNet(nn.Module):
method __init__ (line 53) | def __init__(self, num_inputs, num_channels, kernel_size=2, dropout=0.2):
method forward (line 75) | def forward(self, x):
FILE: qlib/contrib/model/xgboost.py
class XGBModel (line 15) | class XGBModel(Model, FeatureInt):
method __init__ (line 18) | def __init__(self, **kwargs):
method fit (line 23) | def fit(
method predict (line 71) | def predict(self, dataset: DatasetH, segment: Union[Text, slice] = "te...
method get_feature_importance (line 77) | def get_feature_importance(self, *args, **kwargs) -> pd.Series:
FILE: qlib/contrib/online/manager.py
class UserManager (line 17) | class UserManager:
method __init__ (line 18) | def __init__(self, user_data_path, save_report=True):
method load_users (line 46) | def load_users(self):
method load_user (line 55) | def load_user(self, user_id):
method save_user_data (line 77) | def save_user_data(self, user_id):
method add_user (line 95) | def add_user(self, user_id, config_file, add_date):
method remove_user (line 135) | def remove_user(self, user_id):
FILE: qlib/contrib/online/online_model.py
class ScoreFileModel (line 13) | class ScoreFileModel(Model):
method __init__ (line 18) | def __init__(self, score_path):
method get_data_with_date (line 22) | def get_data_with_date(self, date, **kwargs):
method predict (line 29) | def predict(self, x_test, **kwargs):
method score (line 32) | def score(self, x_test, **kwargs):
method fit (line 35) | def fit(self, x_train, y_train, x_valid, y_valid, w_train=None, w_vali...
method save (line 38) | def save(self, fname, **kwargs):
FILE: qlib/contrib/online/operator.py
class Operator (line 27) | class Operator:
method __init__ (line 28) | def __init__(self, client: str):
method init (line 39) | def init(client, path, date=None):
method add_user (line 67) | def add_user(self, id, config, path, date):
method remove_user (line 89) | def remove_user(self, id, path):
method generate (line 102) | def generate(self, date, path):
method execute (line 138) | def execute(self, date, exchange_config, path):
method update (line 172) | def update(self, date, path, type="SIM"):
method simulate (line 213) | def simulate(self, id, config, exchange_config, start, end, path, benc...
method show (line 284) | def show(self, id, path, bench="SH000905"):
function run (line 315) | def run():
FILE: qlib/contrib/online/user.py
class User (line 14) | class User:
method __init__ (line 15) | def __init__(self, account, strategy, model, verbose=False):
method init_state (line 35) | def init_state(self, date):
method get_latest_trading_date (line 45) | def get_latest_trading_date(self):
method showReport (line 57) | def showReport(self, benchmark="SH000905"):
FILE: qlib/contrib/online/utils.py
function load_instance (line 21) | def load_instance(file_path):
function save_instance (line 38) | def save_instance(instance, file_path):
function create_user_folder (line 52) | def create_user_folder(path):
function prepare (line 61) | def prepare(um, today, user_id, exchange_config=None):
FILE: qlib/contrib/ops/high_freq.py
function get_calendar_day (line 13) | def get_calendar_day(freq="1min", future=False):
function get_calendar_minute (line 39) | def get_calendar_minute(freq="day", future=False):
class DayCumsum (line 50) | class DayCumsum(ElemOperator):
method __init__ (line 73) | def __init__(self, feature, start: str = "9:30", end: str = "14:59", d...
method period_cusum (line 88) | def period_cusum(self, df):
method _load_internal (line 96) | def _load_internal(self, instrument, start_index, end_index, freq):
class DayLast (line 102) | class DayLast(ElemOperator):
method _load_internal (line 116) | def _load_internal(self, instrument, start_index, end_index, freq):
class FFillNan (line 122) | class FFillNan(ElemOperator):
method _load_internal (line 136) | def _load_internal(self, instrument, start_index, end_index, freq):
class BFillNan (line 141) | class BFillNan(ElemOperator):
method _load_internal (line 155) | def _load_internal(self, instrument, start_index, end_index, freq):
class Date (line 160) | class Date(ElemOperator):
method _load_internal (line 174) | def _load_internal(self, instrument, start_index, end_index, freq):
class Select (line 180) | class Select(PairOperator):
method _load_internal (line 197) | def _load_internal(self, instrument, start_index, end_index, freq):
class IsNull (line 203) | class IsNull(ElemOperator):
method _load_internal (line 217) | def _load_internal(self, instrument, start_index, end_index, freq):
class IsInf (line 222) | class IsInf(ElemOperator):
method _load_internal (line 236) | def _load_internal(self, instrument, start_index, end_index, freq):
class Cut (line 241) | class Cut(ElemOperator):
method __init__ (line 259) | def __init__(self, feature, left=None, right=None):
method _load_internal (line 267) | def _load_internal(self, instrument, start_index, end_index, freq):
method get_extended_window_size (line 271) | def get_extended_window_size(self):
FILE: qlib/contrib/report/analysis_model/analysis_model_performance.py
function _group_return (line 21) | def _group_return(pred_label: pd.DataFrame = None, reverse: bool = False...
function _plot_qq (line 81) | def _plot_qq(data: pd.Series = None, dist=stats.norm) -> go.Figure:
function _pred_ic (line 119) | def _pred_ic(
function _pred_autocorr (line 223) | def _pred_autocorr(pred_label: pd.DataFrame, lag=1, **kwargs) -> tuple:
function _pred_turnover (line 240) | def _pred_turnover(pred_label: pd.DataFrame, N=5, lag=1, **kwargs) -> tu...
function ic_figure (line 271) | def ic_figure(ic_df: pd.DataFrame, show_nature_day=True, **kwargs) -> go...
function model_performance_graph (line 293) | def model_performance_graph(
FILE: qlib/contrib/report/analysis_position/cumulative_return.py
function _get_cum_return_data_with_position (line 15) | def _get_cum_return_data_with_position(
function _get_figure_with_position (line 89) | def _get_figure_with_position(
function cumulative_return_graph (line 182) | def cumulative_return_graph(
FILE: qlib/contrib/report/analysis_position/parse_position.py
function parse_position (line 10) | def parse_position(position: dict = None) -> pd.DataFrame:
function _add_label_to_position (line 86) | def _add_label_to_position(position_df: pd.DataFrame, label_data: pd.Dat...
function _add_bench_to_position (line 102) | def _add_bench_to_position(position_df: pd.DataFrame = None, bench: pd.S...
function _calculate_label_rank (line 116) | def _calculate_label_rank(df: pd.DataFrame) -> pd.DataFrame:
function get_position_data (line 138) | def get_position_data(
FILE: qlib/contrib/report/analysis_position/rank_label.py
function _get_figure_with_position (line 14) | def _get_figure_with_position(
function rank_label_graph (line 62) | def rank_label_graph(
FILE: qlib/contrib/report/analysis_position/report.py
function _calculate_maximum (line 9) | def _calculate_maximum(df: pd.DataFrame, is_ex: bool = False):
function _calculate_mdd (line 25) | def _calculate_mdd(series):
function _calculate_report_data (line 35) | def _calculate_report_data(df: pd.DataFrame) -> pd.DataFrame:
function _report_figure (line 66) | def _report_figure(df: pd.DataFrame) -> [list, tuple]:
function report_graph (line 166) | def report_graph(report_df: pd.DataFrame, show_notebook: bool = True) ->...
FILE: qlib/contrib/report/analysis_position/risk_analysis.py
function _get_risk_analysis_data_with_report (line 15) | def _get_risk_analysis_data_with_report(
function _get_all_risk_analysis (line 44) | def _get_all_risk_analysis(risk_df: pd.DataFrame) -> pd.DataFrame:
function _get_monthly_risk_analysis_with_report (line 57) | def _get_monthly_risk_analysis_with_report(report_normal_df: pd.DataFram...
function _get_monthly_analysis_with_feature (line 95) | def _get_monthly_analysis_with_feature(monthly_df: pd.DataFrame, feature...
function _get_risk_analysis_figure (line 112) | def _get_risk_analysis_figure(analysis_df: pd.DataFrame) -> Iterable[py....
function _get_monthly_risk_analysis_figure (line 129) | def _get_monthly_risk_analysis_figure(report_normal_df: pd.DataFrame) ->...
function risk_analysis_graph (line 162) | def risk_analysis_graph(
FILE: qlib/contrib/report/analysis_position/score_ic.py
function _get_score_ic (line 10) | def _get_score_ic(pred_label: pd.DataFrame):
function score_ic_graph (line 25) | def score_ic_graph(pred_label: pd.DataFrame, show_notebook: bool = True,...
FILE: qlib/contrib/report/data/ana.py
class CombFeaAna (line 28) | class CombFeaAna(FeaAnalyser):
method __init__ (line 33) | def __init__(self, dataset: pd.DataFrame, *fea_ana_cls):
method skip (line 39) | def skip(self, col):
method calc_stat_values (line 42) | def calc_stat_values(self):
method plot_all (line 45) | def plot_all(self, *args, **kwargs):
class NumFeaAnalyser (line 59) | class NumFeaAnalyser(FeaAnalyser):
method skip (line 60) | def skip(self, col):
class ValueCNT (line 67) | class ValueCNT(FeaAnalyser):
method __init__ (line 68) | def __init__(self, dataset: pd.DataFrame, ratio=False):
method calc_stat_values (line 72) | def calc_stat_values(self):
method plot_single (line 85) | def plot_single(self, col, ax):
class FeaDistAna (line 90) | class FeaDistAna(NumFeaAnalyser):
method plot_single (line 91) | def plot_single(self, col, ax):
class FeaInfAna (line 97) | class FeaInfAna(NumFeaAnalyser):
method calc_stat_values (line 98) | def calc_stat_values(self):
method skip (line 105) | def skip(self, col):
method plot_single (line 108) | def plot_single(self, col, ax):
class FeaNanAna (line 113) | class FeaNanAna(FeaAnalyser):
method calc_stat_values (line 114) | def calc_stat_values(self):
method skip (line 117) | def skip(self, col):
method plot_single (line 120) | def plot_single(self, col, ax):
class FeaNanAnaRatio (line 125) | class FeaNanAnaRatio(FeaAnalyser):
method calc_stat_values (line 126) | def calc_stat_values(self):
method skip (line 130) | def skip(self, col):
method plot_single (line 133) | def plot_single(self, col, ax):
class FeaACAna (line 138) | class FeaACAna(FeaAnalyser):
method calc_stat_values (line 141) | def calc_stat_values(self):
method plot_single (line 147) | def plot_single(self, col, ax):
class FeaSkewTurt (line 152) | class FeaSkewTurt(NumFeaAnalyser):
method calc_stat_values (line 153) | def calc_stat_values(self):
method plot_single (line 157) | def plot_single(self, col, ax):
class FeaMeanStd (line 178) | class FeaMeanStd(NumFeaAnalyser):
method calc_stat_values (line 179) | def calc_stat_values(self):
method plot_single (line 183) | def plot_single(self, col, ax):
class RawFeaAna (line 206) | class RawFeaAna(FeaAnalyser):
method calc_stat_values (line 212) | def calc_stat_values(self):
method plot_single (line 216) | def plot_single(self, col, ax):
FILE: qlib/contrib/report/data/base.py
class FeaAnalyser (line 16) | class FeaAnalyser:
method __init__ (line 17) | def __init__(self, dataset: pd.DataFrame):
method calc_stat_values (line 40) | def calc_stat_values(self):
method plot_single (line 43) | def plot_single(self, col, ax):
method skip (line 46) | def skip(self, col):
method plot_all (line 49) | def plot_all(self, *args, **kwargs):
FILE: qlib/contrib/report/graph.py
class BaseGraph (line 17) | class BaseGraph:
method __init__ (line 20) | def __init__(
method _init_data (line 46) | def _init_data(self):
method _init_parameters (line 56) | def _init_parameters(self, **kwargs):
method get_instance_with_graph_parameters (line 70) | def get_instance_with_graph_parameters(graph_type: str = None, **kwargs):
method show_graph_in_notebook (line 86) | def show_graph_in_notebook(figure_list: Iterable[go.Figure] = None):
method _get_layout (line 108) | def _get_layout(self) -> go.Layout:
method _get_data (line 115) | def _get_data(self) -> list:
method figure (line 130) | def figure(self) -> go.Figure:
class ScatterGraph (line 141) | class ScatterGraph(BaseGraph):
class BarGraph (line 145) | class BarGraph(BaseGraph):
class DistplotGraph (line 149) | class DistplotGraph(BaseGraph):
method _get_data (line 152) | def _get_data(self):
class HeatmapGraph (line 165) | class HeatmapGraph(BaseGraph):
method _get_data (line 168) | def _get_data(self):
class HistogramGraph (line 185) | class HistogramGraph(BaseGraph):
method _get_data (line 188) | def _get_data(self):
class SubplotsGraph (line 202) | class SubplotsGraph:
method __init__ (line 208) | def __init__(
method _init_sub_graph_data (line 295) | def _init_sub_graph_data(self):
method _init_subplots_kwargs (line 321) | def _init_subplots_kwargs(self):
method _init_figure (line 338) | def _init_figure(self):
method figure (line 383) | def figure(self):
FILE: qlib/contrib/report/utils.py
function sub_fig_generator (line 7) | def sub_fig_generator(sub_figsize=(3, 3), col_n=10, row_n=1, wspace=None...
function guess_plotly_rangebreaks (line 49) | def guess_plotly_rangebreaks(dt_index: pd.DatetimeIndex):
FILE: qlib/contrib/rolling/base.py
class Rolling (line 24) | class Rolling:
method __init__ (line 53) | def __init__(
method _raw_conf (line 118) | def _raw_conf(self) -> dict:
method _replace_handler_with_cache (line 123) | def _replace_handler_with_cache(self, task: dict):
method _update_start_end_time (line 135) | def _update_start_end_time(self, task: dict):
method basic_task (line 145) | def basic_task(self, enable_handler_cache: Optional[bool] = True):
method run_basic_task (line 184) | def run_basic_task(self):
method get_task_list (line 194) | def get_task_list(self) -> List[dict]:
method _train_rolling_tasks (line 206) | def _train_rolling_tasks(self):
method _ens_rolling (line 218) | def _ens_rolling(self):
method _update_rolling_rec (line 232) | def _update_rolling_rec(self):
method run (line 253) | def run(self):
FILE: qlib/contrib/rolling/ddgda.py
class DDGDA (line 70) | class DDGDA(Rolling):
method __init__ (line 79) | def __init__(
method _adjust_task (line 128) | def _adjust_task(self, task: dict, astype: UTIL_MODEL_TYPE):
method _get_feature_importance (line 159) | def _get_feature_importance(self):
method _dump_data_for_proxy_model (line 179) | def _dump_data_for_proxy_model(self):
method _internal_data_path (line 231) | def _internal_data_path(self):
method _dump_meta_ipt (line 234) | def _dump_meta_ipt(self):
method _train_meta_model (line 254) | def _train_meta_model(self, fill_method="max"):
method _task_path (line 322) | def _task_path(self):
method get_task_list (line 325) | def get_task_list(self):
method run (line 373) | def run(self):
FILE: qlib/contrib/strategy/cost_control.py
class SoftTopkStrategy (line 8) | class SoftTopkStrategy(WeightStrategyBase):
method __init__ (line 9) | def __init__(
method get_risk_degree (line 44) | def get_risk_degree(self, trade_step=None):
method generate_target_weight_position (line 47) | def generate_target_weight_position(self, score, current, trade_start_...
FILE: qlib/contrib/strategy/optimizer/base.py
class BaseOptimizer (line 7) | class BaseOptimizer(abc.ABC):
method __call__ (line 11) | def __call__(self, *args, **kwargs) -> object:
FILE: qlib/contrib/strategy/optimizer/enhanced_indexing.py
class EnhancedIndexingOptimizer (line 15) | class EnhancedIndexingOptimizer(BaseOptimizer):
method __init__ (line 46) | def __init__(
method __call__ (line 87) | def __call__(
FILE: qlib/contrib/strategy/optimizer/optimizer.py
class PortfolioOptimizer (line 14) | class PortfolioOptimizer(BaseOptimizer):
method __init__ (line 32) | def __init__(
method __call__ (line 65) | def __call__(
method _optimize (line 114) | def _optimize(self, S: np.ndarray, r: Optional[np.ndarray] = None, w0:...
method _optimize_inv (line 139) | def _optimize_inv(self, S: np.ndarray) -> np.ndarray:
method _optimize_gmv (line 146) | def _optimize_gmv(self, S: np.ndarray, w0: Optional[np.ndarray] = None...
method _optimize_mvo (line 156) | def _optimize_mvo(
method _optimize_rp (line 169) | def _optimize_rp(self, S: np.ndarray, w0: Optional[np.ndarray] = None)...
method _get_objective_gmv (line 179) | def _get_objective_gmv(self, S: np.ndarray) -> Callable:
method _get_objective_mvo (line 191) | def _get_objective_mvo(self, S: np.ndarray, r: np.ndarray = None) -> C...
method _get_objective_rp (line 205) | def _get_objective_rp(self, S: np.ndarray) -> Callable:
method _get_constrains (line 220) | def _get_constrains(self, w0: Optional[np.ndarray] = None):
method _solve (line 241) | def _solve(self, n: int, obj: Callable, bounds: so.Bounds, cons: List)...
FILE: qlib/contrib/strategy/order_generator.py
class OrderGenerator (line 15) | class OrderGenerator:
method generate_order_list_from_target_weight_position (line 16) | def generate_order_list_from_target_weight_position(
class OrderGenWInteract (line 51) | class OrderGenWInteract(OrderGenerator):
method generate_order_list_from_target_weight_position (line 54) | def generate_order_list_from_target_weight_position(
class OrderGenWOInteract (line 143) | class OrderGenWOInteract(OrderGenerator):
method generate_order_list_from_target_weight_position (line 146) | def generate_order_list_from_target_weight_position(
FILE: qlib/contrib/strategy/rule_strategy.py
class TWAPStrategy (line 22) | class TWAPStrategy(BaseStrategy):
method reset (line 30) | def reset(self, outer_trade_decision: BaseTradeDecision = None, **kwar...
method generate_trade_decision (line 43) | def generate_trade_decision(self, execute_result=None):
class SBBStrategyBase (line 125) | class SBBStrategyBase(BaseStrategy):
method reset (line 139) | def reset(self, outer_trade_decision: BaseTradeDecision = None, **kwar...
method _pred_price_trend (line 154) | def _pred_price_trend(self, stock_id, pred_start_time=None, pred_end_t...
method generate_trade_decision (line 157) | def generate_trade_decision(self, execute_result=None):
class SBBStrategyEMA (line 297) | class SBBStrategyEMA(SBBStrategyBase):
method __init__ (line 307) | def __init__(
method _reset_signal (line 338) | def _reset_signal(self):
method reset_level_infra (line 353) | def reset_level_infra(self, level_infra):
method _pred_price_trend (line 361) | def _pred_price_trend(self, stock_id, pred_start_time=None, pred_end_t...
class ACStrategy (line 383) | class ACStrategy(BaseStrategy):
method __init__ (line 388) | def __init__(
method _reset_signal (line 423) | def _reset_signal(self):
method reset_level_infra (line 440) | def reset_level_infra(self, level_infra):
method reset (line 448) | def reset(self, outer_trade_decision: BaseTradeDecision = None, **kwar...
method generate_trade_decision (line 461) | def generate_trade_decision(self, execute_result=None):
class RandomOrderStrategy (line 539) | class RandomOrderStrategy(BaseStrategy):
method __init__ (line 540) | def __init__(
method generate_trade_decision (line 577) | def generate_trade_decision(self, execute_result=None):
class FileOrderStrategy (line 596) | class FileOrderStrategy(BaseStrategy):
method __init__ (line 602) | def __init__(
method generate_trade_decision (line 648) | def generate_trade_decision(self, execute_result=None) -> TradeDecisio...
FILE: qlib/contrib/strategy/signal_strategy.py
class BaseSignalStrategy (line 25) | class BaseSignalStrategy(BaseStrategy, ABC):
method __init__ (line 26) | def __init__(
method get_risk_degree (line 66) | def get_risk_degree(self, trade_step=None):
class TopkDropoutStrategy (line 75) | class TopkDropoutStrategy(BaseSignalStrategy):
method __init__ (line 81) | def __init__(
method generate_trade_decision (line 138) | def generate_trade_decision(self, execute_result=None):
class WeightStrategyBase (line 298) | class WeightStrategyBase(BaseSignalStrategy):
method __init__ (line 303) | def __init__(
method generate_target_weight_position (line 330) | def generate_target_weight_position(self, score, current, trade_start_...
method generate_trade_decision (line 345) | def generate_trade_decision(self, execute_result=None):
class EnhancedIndexingStrategy (line 375) | class EnhancedIndexingStrategy(WeightStrategyBase):
method __init__ (line 406) | def __init__(
method get_risk_data (line 436) | def get_risk_data(self, date):
method generate_target_weight_position (line 462) | def generate_target_weight_position(self, score, current, trade_start_...
FILE: qlib/contrib/torch.py
function data_to_tensor (line 14) | def data_to_tensor(data, device="cpu", raise_error=False):
FILE: qlib/contrib/tuner/config.py
class TunerConfigManager (line 12) | class TunerConfigManager:
method __init__ (line 13) | def __init__(self, config_path):
class PipelineExperimentConfig (line 33) | class PipelineExperimentConfig:
method __init__ (line 34) | def __init__(self, config, TUNER_CONFIG_MANAGER):
class OptimizationConfig (line 59) | class OptimizationConfig:
method __init__ (line 60) | def __init__(self, config, TUNER_CONFIG_MANAGER):
FILE: qlib/contrib/tuner/launcher.py
function run (line 30) | def run():
FILE: qlib/contrib/tuner/pipeline.py
class Pipeline (line 17) | class Pipeline:
method __init__ (line 20) | def __init__(self, tuner_config_manager):
method run (line 37) | def run(self):
method init_tuner (line 50) | def init_tuner(self, tuner_index, tuner_config):
method save_tuner_exp_info (line 76) | def save_tuner_exp_info(self):
FILE: qlib/contrib/tuner/tuner.py
class Tuner (line 25) | class Tuner:
method __init__ (line 26) | def __init__(self, tuner_config, optim_config):
method tune (line 43) | def tune(self):
method objective (line 60) | def objective(self, params):
method setup_space (line 69) | def setup_space(self):
method save_local_best_params (line 77) | def save_local_best_params(self):
class QLibTuner (line 84) | class QLibTuner(Tuner):
method objective (line 91) | def objective(self, params):
method fetch_result (line 118) | def fetch_result(self):
method setup_estimator_config (line 152) | def setup_estimator_config(self, params):
method setup_space (line 169) | def setup_space(self):
method save_local_best_params (line 208) | def save_local_best_params(self):
FILE: qlib/contrib/workflow/record_temp.py
class MultiSegRecord (line 19) | class MultiSegRecord(RecordTemp):
method __init__ (line 25) | def __init__(self, model, dataset, recorder=None):
method generate (line 32) | def generate(self, segments: Dict[Text, Any], save: bool = False):
class SignalMseRecord (line 60) | class SignalMseRecord(RecordTemp):
method __init__ (line 69) | def __init__(self, recorder, **kwargs):
method generate (line 72) | def generate(self):
method list (line 85) | def list(self):
FILE: qlib/data/base.py
class Expression (line 13) | class Expression(abc.ABC):
method __str__ (line 26) | def __str__(self):
method __repr__ (line 29) | def __repr__(self):
method __gt__ (line 32) | def __gt__(self, other):
method __ge__ (line 37) | def __ge__(self, other):
method __lt__ (line 42) | def __lt__(self, other):
method __le__ (line 47) | def __le__(self, other):
method __eq__ (line 52) | def __eq__(self, other):
method __ne__ (line 57) | def __ne__(self, other):
method __add__ (line 62) | def __add__(self, other):
method __radd__ (line 67) | def __radd__(self, other):
method __sub__ (line 72) | def __sub__(self, other):
method __rsub__ (line 77) | def __rsub__(self, other):
method __mul__ (line 82) | def __mul__(self, other):
method __rmul__ (line 87) | def __rmul__(self, other):
method __div__ (line 92) | def __div__(self, other):
method __rdiv__ (line 97) | def __rdiv__(self, other):
method __truediv__ (line 102) | def __truediv__(self, other):
method __rtruediv__ (line 107) | def __rtruediv__(self, other):
method __pow__ (line 112) | def __pow__(self, other):
method __rpow__ (line 117) | def __rpow__(self, other):
method __and__ (line 122) | def __and__(self, other):
method __rand__ (line 127) | def __rand__(self, other):
method __or__ (line 132) | def __or__(self, other):
method __ror__ (line 137) | def __ror__(self, other):
method load (line 142) | def load(self, instrument, start_index, end_index, *args):
method _load_internal (line 206) | def _load_internal(self, instrument, start_index, end_index, *args) ->...
method get_longest_back_rolling (line 210) | def get_longest_back_rolling(self):
method get_extended_window_size (line 223) | def get_extended_window_size(self):
class Feature (line 238) | class Feature(Expression):
method __init__ (line 244) | def __init__(self, name=None):
method __str__ (line 250) | def __str__(self):
method _load_internal (line 253) | def _load_internal(self, instrument, start_index, end_index, freq):
method get_longest_back_rolling (line 259) | def get_longest_back_rolling(self):
method get_extended_window_size (line 262) | def get_extended_window_size(self):
class PFeature (line 266) | class PFeature(Feature):
method __str__ (line 267) | def __str__(self):
method _load_internal (line 270) | def _load_internal(self, instrument, start_index, end_index, cur_time,...
class ExpressionOps (line 276) | class ExpressionOps(Expression):
FILE: qlib/data/cache.py
class QlibCacheException (line 40) | class QlibCacheException(RuntimeError):
class MemCacheUnit (line 44) | class MemCacheUnit(abc.ABC):
method __init__ (line 47) | def __init__(self, *args, **kwargs):
method __setitem__ (line 52) | def __setitem__(self, key, value):
method __getitem__ (line 68) | def __getitem__(self, key):
method __contains__ (line 73) | def __contains__(self, key):
method __len__ (line 76) | def __len__(self):
method __repr__ (line 79) | def __repr__(self):
method set_limit_size (line 82) | def set_limit_size(self, limit):
method limited (line 86) | def limited(self):
method total_size (line 91) | def total_size(self):
method clear (line 94) | def clear(self):
method popitem (line 98) | def popitem(self, last=True):
method pop (line 104) | def pop(self, key):
method _adjust_size (line 110) | def _adjust_size(self, key, value):
method _get_value_size (line 117) | def _get_value_size(self, value):
class MemCacheLengthUnit (line 121) | class MemCacheLengthUnit(MemCacheUnit):
method __init__ (line 122) | def __init__(self, size_limit=0):
method _get_value_size (line 125) | def _get_value_size(self, value):
class MemCacheSizeofUnit (line 129) | class MemCacheSizeofUnit(MemCacheUnit):
method __init__ (line 130) | def __init__(self, size_limit=0):
method _get_value_size (line 133) | def _get_value_size(self, value):
class MemCache (line 137) | class MemCache:
method __init__ (line 140) | def __init__(self, mem_cache_size_limit=None, limit_type="length"):
method __getitem__ (line 165) | def __getitem__(self, key):
method clear (line 175) | def clear(self):
class MemCacheExpire (line 181) | class MemCacheExpire:
method set_cache (line 185) | def set_cache(mem_cache, key, value):
method get_cache (line 195) | def get_cache(mem_cache, key):
class CacheUtils (line 210) | class CacheUtils:
method organize_meta_file (line 214) | def organize_meta_file():
method reset_lock (line 218) | def reset_lock():
method visit (line 223) | def visit(cache_path: Union[str, Path]):
method acquire (line 241) | def acquire(lock, lock_name):
method reader_lock (line 258) | def reader_lock(redis_t, lock_name: str):
method writer_lock (line 286) | def writer_lock(redis_t, lock_name):
class BaseProviderCache (line 295) | class BaseProviderCache:
method __init__ (line 298) | def __init__(self, provider):
method __getattr__ (line 302) | def __getattr__(self, attr):
method check_cache_exists (line 306) | def check_cache_exists(cache_path: Union[str, Path], suffix_list: Iter...
method clear_cache (line 314) | def clear_cache(cache_path: Union[str, Path]):
method get_cache_dir (line 324) | def get_cache_dir(dir_name: str, freq: str = None) -> Path:
class ExpressionCache (line 330) | class ExpressionCache(BaseProviderCache):
method expression (line 338) | def expression(self, instrument, field, start_time, end_time, freq):
method _uri (line 348) | def _uri(self, instrument, field, start_time, end_time, freq):
method _expression (line 355) | def _expression(self, instrument, field, start_time, end_time, freq):
method update (line 362) | def update(self, cache_uri: Union[str, Path], freq: str = "day"):
class DatasetCache (line 381) | class DatasetCache(BaseProviderCache):
method dataset (line 391) | def dataset(
method _uri (line 418) | def _uri(self, instruments, fields, start_time, end_time, freq, **kwar...
method _dataset (line 425) | def _dataset(
method _dataset_uri (line 434) | def _dataset_uri(
method update (line 448) | def update(self, cache_uri: Union[str, Path], freq: str = "day"):
method cache_to_origin_data (line 467) | def cache_to_origin_data(data, fields):
method normalize_uri_args (line 481) | def normalize_uri_args(instruments, fields, freq):
class DiskExpressionCache (line 490) | class DiskExpressionCache(ExpressionCache):
method __init__ (line 493) | def __init__(self, provider, **kwargs):
method get_cache_dir (line 499) | def get_cache_dir(self, freq: str = None) -> Path:
method _uri (line 502) | def _uri(self, instrument, field, start_time, end_time, freq):
method _expression (line 507) | def _expression(self, instrument, field, start_time=None, end_time=Non...
method gen_expression_cache (line 566) | def gen_expression_cache(self, expression_data, cache_path, instrument...
method update (line 586) | def update(self, sid, cache_uri, freq: str = "day"):
class DiskDatasetCache (line 647) | class DiskDatasetCache(DatasetCache):
method __init__ (line 650) | def __init__(self, provider, **kwargs):
method _uri (line 656) | def _uri(instruments, fields, start_time, end_time, freq, disk_cache=1...
method get_cache_dir (line 659) | def get_cache_dir(self, freq: str = None) -> Path:
method read_data_from_cache (line 663) | def read_data_from_cache(cls, cache_path: Union[str, Path], start_time...
method _dataset (line 696) | def _dataset(
method _dataset_uri (line 750) | def _dataset_uri(
class IndexManager (line 794) | class IndexManager:
method __init__ (line 802) | def __init__(self, cache_path: Union[str, Path]):
method get_index (line 807) | def get_index(self, start_time=None, end_time=None):
method sync_to_disk (line 813) | def sync_to_disk(self):
method sync_from_disk (line 821) | def sync_from_disk(self):
method update (line 829) | def update(self, data, sync=True):
method append_index (line 834) | def append_index(self, data, to_disk=True):
method build_index_from_data (line 843) | def build_index_from_data(data, start_index=0):
method gen_dataset_cache (line 857) | def gen_dataset_cache(self, cache_path: Union[str, Path], instruments,...
method update (line 952) | def update(self, cache_uri, freq: str = "day"):
class SimpleDatasetCache (line 1064) | class SimpleDatasetCache(DatasetCache):
method __init__ (line 1067) | def __init__(self, provider):
method _uri (line 1079) | def _uri(self, instruments, fields, start_time, end_time, freq, disk_c...
method _dataset (line 1085) | def _dataset(
class DatasetURICache (line 1118) | class DatasetURICache(DatasetCache):
method _uri (line 1121) | def _uri(self, instruments, fields, start_time, end_time, freq, disk_c...
method dataset (line 1124) | def dataset(
class CalendarCache (line 1180) | class CalendarCache(BaseProviderCache):
class MemoryCalendarCache (line 1184) | class MemoryCalendarCache(CalendarCache):
method calendar (line 1185) | def calendar(self, start_time=None, end_time=None, freq="day", future=...
FILE: qlib/data/client.py
class Client (line 16) | class Client:
method __init__ (line 22) | def __init__(self, host, port):
method connect_server (line 35) | def connect_server(self):
method disconnect (line 42) | def disconnect(self):
method send_request (line 49) | def send_request(self, request_type, request_content, msg_queue, msg_p...
FILE: qlib/data/data.py
class ProviderBackendMixin (line 43) | class ProviderBackendMixin:
method get_default_backend (line 49) | def get_default_backend(self):
method backend_obj (line 58) | def backend_obj(self, **kwargs):
class CalendarProvider (line 65) | class CalendarProvider(abc.ABC):
method calendar (line 71) | def calendar(self, start_time=None, end_time=None, freq="day", future=...
method locate_index (line 111) | def locate_index(
method _get_calendar (line 154) | def _get_calendar(self, freq, future):
method _uri (line 178) | def _uri(self, start_time, end_time, freq, future=False):
method load_calendar (line 182) | def load_calendar(self, freq, future):
class InstrumentProvider (line 199) | class InstrumentProvider(abc.ABC):
method instruments (line 206) | def instruments(market: Union[List, str] = "all", filter_pipe: Union[L...
method list_instruments (line 267) | def list_instruments(self, instruments, start_time=None, end_time=None...
method _uri (line 288) | def _uri(self, instruments, start_time=None, end_time=None, freq="day"...
method get_inst_type (line 297) | def get_inst_type(cls, inst):
class FeatureProvider (line 307) | class FeatureProvider(abc.ABC):
method feature (line 314) | def feature(self, instrument, field, start_time, end_time, freq):
class PITProvider (line 338) | class PITProvider(abc.ABC):
method period_feature (line 340) | def period_feature(
class ExpressionProvider (line 383) | class ExpressionProvider(abc.ABC):
method __init__ (line 389) | def __init__(self):
method get_expression_instance (line 392) | def get_expression_instance(self, field):
method expression (line 410) | def expression(self, instrument, field, start_time=None, end_time=None...
class DatasetProvider (line 446) | class DatasetProvider(abc.ABC):
method dataset (line 453) | def dataset(self, instruments, fields, start_time=None, end_time=None,...
method _uri (line 478) | def _uri(
method get_instruments_d (line 511) | def get_instruments_d(instruments, freq):
method get_column_names (line 532) | def get_column_names(fields):
method parse_fields (line 543) | def parse_fields(fields):
method dataset_processor (line 548) | def dataset_processor(instruments_d, column_names, start_time, end_tim...
method inst_calculator (line 600) | def inst_calculator(inst, start_time, end_time, freq, column_names, sp...
class LocalCalendarProvider (line 637) | class LocalCalendarProvider(CalendarProvider, ProviderBackendMixin):
method __init__ (line 643) | def __init__(self, remote=False, backend={}):
method load_calendar (line 648) | def load_calendar(self, freq, future):
class LocalInstrumentProvider (line 678) | class LocalInstrumentProvider(InstrumentProvider, ProviderBackendMixin):
method __init__ (line 684) | def __init__(self, backend={}) -> None:
method _load_instruments (line 688) | def _load_instruments(self, market, freq):
method list_instruments (line 691) | def list_instruments(self, instruments, start_time=None, end_time=None...
class LocalFeatureProvider (line 726) | class LocalFeatureProvider(FeatureProvider, ProviderBackendMixin):
method __init__ (line 732) | def __init__(self, remote=False, backend={}):
method feature (line 737) | def feature(self, instrument, field, start_index, end_index, freq):
class LocalPITProvider (line 744) | class LocalPITProvider(PITProvider):
method period_feature (line 748) | def period_feature(self, instrument, field, start_index, end_index, cu...
class LocalExpressionProvider (line 833) | class LocalExpressionProvider(ExpressionProvider):
method __init__ (line 839) | def __init__(self, time2idx=True):
method expression (line 843) | def expression(self, instrument, field, start_time=None, end_time=None...
class LocalDatasetProvider (line 882) | class LocalDatasetProvider(DatasetProvider):
method __init__ (line 888) | def __init__(self, align_time: bool = True):
method dataset (line 902) | def dataset(
method multi_cache_walker (line 930) | def multi_cache_walker(instruments, fields, start_time=None, end_time=...
method cache_walker (line 951) | def cache_walker(inst, start_time, end_time, freq, column_names):
class ClientCalendarProvider (line 961) | class ClientCalendarProvider(CalendarProvider):
method __init__ (line 967) | def __init__(self):
method set_conn (line 971) | def set_conn(self, conn):
method calendar (line 974) | def calendar(self, start_time=None, end_time=None, freq="day", future=...
class ClientInstrumentProvider (line 985) | class ClientInstrumentProvider(InstrumentProvider):
method __init__ (line 991) | def __init__(self):
method set_conn (line 995) | def set_conn(self, conn):
method list_instruments (line 998) | def list_instruments(self, instruments, start_time=None, end_time=None...
class ClientDatasetProvider (line 1027) | class ClientDatasetProvider(DatasetProvider):
method __init__ (line 1033) | def __init__(self):
method set_conn (line 1036) | def set_conn(self, conn):
method dataset (line 1040) | def dataset(
class BaseProvider (line 1140) | class BaseProvider:
method calendar (line 1148) | def calendar(self, start_time=None, end_time=None, freq="day", future=...
method instruments (line 1151) | def instruments(self, market="all", filter_pipe=None, start_time=None,...
method list_instruments (line 1159) | def list_instruments(self, instruments, start_time=None, end_time=None...
method features (line 1162) | def features(
class LocalProvider (line 1193) | class LocalProvider(BaseProvider):
method _uri (line 1194) | def _uri(self, type, **kwargs):
method features_uri (line 1209) | def features_uri(self, instruments, fields, start_time, end_time, freq...
class ClientProvider (line 1224) | class ClientProvider(BaseProvider):
method __init__ (line 1239) | def __init__(self):
function register_all_wrappers (line 1292) | def register_all_wrappers(C):
FILE: qlib/data/dataset/__init__.py
class Dataset (line 15) | class Dataset(Serializable):
method __init__ (line 20) | def __init__(self, **kwargs):
method config (line 35) | def config(self, **kwargs):
method setup_data (line 41) | def setup_data(self, **kwargs):
method prepare (line 56) | def prepare(self, **kwargs) -> object:
class DatasetH (line 72) | class DatasetH(Dataset):
method __init__ (line 84) | def __init__(
method config (line 124) | def config(self, handler_kwargs: dict = None, **kwargs):
method setup_data (line 148) | def setup_data(self, handler_kwargs: dict = None, **kwargs):
method __repr__ (line 166) | def __repr__(self):
method _prepare_seg (line 171) | def _prepare_seg(self, slc, **kwargs):
method prepare (line 185) | def prepare(
method get_min_time (line 251) | def get_min_time(segments):
method get_max_time (line 255) | def get_max_time(segments):
method _get_extrema (line 259) | def _get_extrema(segments, idx: int, cmp: Callable, key_func=pd.Timest...
class TSDataSampler (line 272) | class TSDataSampler:
method __init__ (line 343) | def __init__(
method slice_idx_map_and_data_index (line 432) | def slice_idx_map_and_data_index(
method idx_map2arr (line 449) | def idx_map2arr(idx_map):
method flt_idx_map (line 468) | def flt_idx_map(flt_data, idx_map):
method get_index (line 477) | def get_index(self):
method config (line 484) | def config(self, **kwargs):
method build_index (line 490) | def build_index(data: pd.DataFrame) -> Tuple[pd.DataFrame, dict]:
method empty (line 533) | def empty(self):
method _get_indices (line 536) | def _get_indices(self, row: int, col: int) -> np.array:
method _get_row_col (line 565) | def _get_row_col(self, idx) -> Tuple[int]:
method __getitem__ (line 597) | def __getitem__(self, idx: Union[int, Tuple[object, str], List[int]]):
method __len__ (line 638) | def __len__(self):
class TSDatasetH (line 642) | class TSDatasetH(DatasetH):
method __init__ (line 663) | def __init__(self, step_len=DEFAULT_STEP_LEN, flt_col: Optional[str] =...
method config (line 668) | def config(self, **kwargs):
method setup_data (line 673) | def setup_data(self, **kwargs):
method _extend_slice (line 680) | def _extend_slice(slc: slice, cal: list, step_len: int) -> slice:
method _prepare_seg (line 688) | def _prepare_seg(self, slc: slice, **kwargs) -> TSDataSampler:
FILE: qlib/data/dataset/handler.py
class DataHandlerABC (line 25) | class DataHandlerABC(Serializable):
method __init__ (line 42) | def __init__(self, *args, **kwargs): # pylint: disable=W0246
method fetch (line 57) | def fetch(
class DataHandler (line 67) | class DataHandler(DataHandlerABC):
method __init__ (line 105) | def __init__(
method config (line 153) | def config(self, **kwargs):
method setup_data (line 173) | def setup_data(self, enable_cache: bool = False):
method fetch (line 197) | def fetch(
method _fetch_data (line 278) | def _fetch_data(
method get_cols (line 328) | def get_cols(self, col_set=DataHandlerABC.CS_ALL) -> list:
method get_range_selector (line 346) | def get_range_selector(self, cur_date: Union[pd.Timestamp, str], perio...
method get_range_iterator (line 363) | def get_range_iterator(
class DataHandlerLP (line 382) | class DataHandlerLP(DataHandler):
method __init__ (line 436) | def __init__(
method get_all_processors (line 510) | def get_all_processors(self):
method fit (line 513) | def fit(self):
method fit_process_data (line 521) | def fit_process_data(self):
method _run_proc_l (line 530) | def _run_proc_l(
method _is_proc_readonly (line 543) | def _is_proc_readonly(proc_l: List[processor_module.Processor]):
method process_data (line 552) | def process_data(self, with_fit: bool = False):
method config (line 614) | def config(self, processor_kwargs: dict = None, **kwargs):
method setup_data (line 633) | def setup_data(self, init_type: str = IT_FIT_SEQ, **kwargs):
method _get_df_by_key (line 665) | def _get_df_by_key(self, data_key: DATA_KEY_TYPE = DataHandlerABC.DK_I...
method fetch (line 673) | def fetch(
method get_cols (line 712) | def get_cols(self, col_set=DataHandler.CS_ALL, data_key: DATA_KEY_TYPE...
method cast (line 733) | def cast(cls, handler: "DataHandlerLP") -> "DataHandlerLP":
method from_df (line 765) | def from_df(cls, df: pd.DataFrame) -> "DataHandlerLP":
FILE: qlib/data/dataset/loader.py
class DataLoader (line 18) | class DataLoader(abc.ABC):
method load (line 24) | def load(self, instruments, start_time=None, end_time=None) -> pd.Data...
class DLWParser (line 62) | class DLWParser(DataLoader):
method __init__ (line 69) | def __init__(self, config: Union[list, tuple, dict]):
method _parse_fields_info (line 95) | def _parse_fields_info(self, fields_info: Union[list, tuple]) -> Tuple...
method load_group_df (line 111) | def load_group_df(
method load (line 138) | def load(self, instruments=None, start_time=None, end_time=None) -> pd...
class QlibDataLoader (line 153) | class QlibDataLoader(DLWParser):
method __init__ (line 156) | def __init__(
method load_group_df (line 202) | def load_group_df(
class StaticDataLoader (line 230) | class StaticDataLoader(DataLoader, Serializable):
method __init__ (line 237) | def __init__(self, config: Union[dict, str, pd.DataFrame], join="outer"):
method __getstate__ (line 250) | def __getstate__(self) -> dict:
method load (line 254) | def load(self, instruments=None, start_time=None, end_time=None) -> pd...
method _maybe_load_raw_data (line 271) | def _maybe_load_raw_data(self):
class NestedDataLoader (line 291) | class NestedDataLoader(DataLoader):
method __init__ (line 296) | def __init__(self, dataloader_l: List[Dict], join="left") -> None:
method load (line 329) | def load(self, instruments=None, start_time=None, end_time=None) -> pd...
class DataLoaderDH (line 350) | class DataLoaderDH(DataLoader):
method __init__ (line 363) | def __init__(self, handler_config: dict, fetch_kwargs: dict = {}, is_g...
method load (line 400) | def load(self, instruments=None, start_time=None, end_time=None) -> pd...
FILE: qlib/data/dataset/processor.py
function get_group_columns (line 18) | def get_group_columns(df: pd.DataFrame, group: Union[Text, None]):
class Processor (line 35) | class Processor(Serializable):
method fit (line 36) | def fit(self, df: pd.DataFrame = None):
method __call__ (line 49) | def __call__(self, df: pd.DataFrame):
method is_for_infer (line 62) | def is_for_infer(self) -> bool:
method readonly (line 74) | def readonly(self) -> bool:
method config (line 82) | def config(self, **kwargs):
class DropnaProcessor (line 94) | class DropnaProcessor(Processor):
method __init__ (line 95) | def __init__(self, fields_group=None):
method __call__ (line 98) | def __call__(self, df):
method readonly (line 101) | def readonly(self):
class DropnaLabel (line 105) | class DropnaLabel(DropnaProcessor):
method __init__ (line 106) | def __init__(self, fields_group="label"):
method is_for_infer (line 109) | def is_for_infer(self) -> bool:
class DropCol (line 114) | class DropCol(Processor):
method __init__ (line 115) | def __init__(self, col_list=[]):
method __call__ (line 118) | def __call__(self, df):
method readonly (line 125) | def readonly(self):
class FilterCol (line 129) | class FilterCol(Processor):
method __init__ (line 130) | def __init__(self, fields_group="feature", col_list=[]):
method __call__ (line 134) | def __call__(self, df):
method readonly (line 142) | def readonly(self):
class TanhProcess (line 146) | class TanhProcess(Processor):
method __call__ (line 149) | def __call__(self, df):
class ProcessInf (line 161) | class ProcessInf(Processor):
method __call__ (line 164) | def __call__(self, df):
class Fillna (line 179) | class Fillna(Processor):
method __init__ (line 182) | def __init__(self, fields_group=None, fill_value=0):
method __call__ (line 186) | def __call__(self, df):
class MinMaxNorm (line 196) | class MinMaxNorm(Processor):
method __init__ (line 197) | def __init__(self, fit_start_time, fit_end_time, fields_group=None):
method fit (line 204) | def fit(self, df: pd.DataFrame = None):
method __call__ (line 220) | def __call__(self, df):
class ZScoreNorm (line 228) | class ZScoreNorm(Processor):
method __init__ (line 231) | def __init__(self, fit_start_time, fit_end_time, fields_group=None):
method fit (line 238) | def fit(self, df: pd.DataFrame = None):
method __call__ (line 254) | def __call__(self, df):
class RobustZScoreNorm (line 262) | class RobustZScoreNorm(Processor):
method __init__ (line 273) | def __init__(self, fit_start_time, fit_end_time, fields_group=None, cl...
method fit (line 281) | def fit(self, df: pd.DataFrame = None):
method __call__ (line 290) | def __call__(self, df):
class CSZScoreNorm (line 300) | class CSZScoreNorm(Processor):
method __init__ (line 303) | def __init__(self, fields_group=None, method="zscore"):
method __call__ (line 312) | def __call__(self, df):
class CSRankNorm (line 326) | class CSRankNorm(Processor):
method __init__ (line 349) | def __init__(self, fields_group=None):
method __call__ (line 352) | def __call__(self, df):
class CSZFillna (line 362) | class CSZFillna(Processor):
method __init__ (line 365) | def __init__(self, fields_group=None):
method __call__ (line 368) | def __call__(self, df):
class HashStockFormat (line 374) | class HashStockFormat(Processor):
method __call__ (line 377) | def __call__(self, df: pd.DataFrame):
class TimeRangeFlt (line 383) | class TimeRangeFlt(InstProcessor):
method __init__ (line 390) | def __init__(
method __call__ (line 412) | def __call__(self, df: pd.DataFrame, instrument, *args, **kwargs):
FILE: qlib/data/dataset/storage.py
class BaseHandlerStorage (line 12) | class BaseHandlerStorage:
method fetch (line 20) | def fetch(
class NaiveDFStorage (line 54) | class NaiveDFStorage(BaseHandlerStorage):
method __init__ (line 60) | def __init__(self, df: pd.DataFrame):
method fetch (line 63) | def fetch(
class HashingStockStorage (line 88) | class HashingStockStorage(BaseHandlerStorage):
method __init__ (line 102) | def __init__(self, df):
method from_df (line 110) | def from_df(df):
method _fetch_hash_df_by_stock (line 113) | def _fetch_hash_df_by_stock(self, selector, level):
method fetch (line 168) | def fetch(
FILE: qlib/data/dataset/utils.py
function get_level_index (line 12) | def get_level_index(df: pd.DataFrame, level: Union[str, int]) -> int:
function fetch_df_by_index (line 41) | def fetch_df_by_index(
function fetch_df_by_col (line 81) | def fetch_df_by_col(df: pd.DataFrame, col_set: Union[str, List[str]]) ->...
function convert_index_format (line 92) | def convert_index_format(df: Union[pd.DataFrame, pd.Series], level: str ...
function init_task_handler (line 119) | def init_task_handler(task: dict) -> DataHandler:
FILE: qlib/data/dataset/weight.py
class Reweighter (line 5) | class Reweighter:
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method reweight (line 12) | def reweight(self, data: object) -> object:
FILE: qlib/data/filter.py
class BaseDFilter (line 15) | class BaseDFilter(abc.ABC):
method __init__ (line 25) | def __init__(self):
method from_config (line 29) | def from_config(config):
method to_config (line 40) | def to_config(self):
class SeriesDFilter (line 51) | class SeriesDFilter(BaseDFilter):
method __init__ (line 65) | def __init__(self, fstart_time=None, fend_time=None, keep=False):
method _getTimeBound (line 83) | def _getTimeBound(self, instruments):
method _toSeries (line 104) | def _toSeries(self, time_range, target_timestamp):
method _filterSeries (line 129) | def _filterSeries(self, timestamp_series, filter_series):
method _toTimestamp (line 149) | def _toTimestamp(self, timestamp_series):
method __call__ (line 189) | def __call__(self, instruments, start_time=None, end_time=None, freq="...
method _getFilterSeries (line 195) | def _getFilterSeries(self, instruments, fstart, fend):
method filter_main (line 216) | def filter_main(self, instruments, start_time=None, end_time=None):
class NameDFilter (line 265) | class NameDFilter(SeriesDFilter):
method __init__ (line 273) | def __init__(self, name_rule_re, fstart_time=None, fend_time=None):
method _getFilterSeries (line 284) | def _getFilterSeries(self, instruments, fstart, fend):
method from_config (line 296) | def from_config(config):
method to_config (line 303) | def to_config(self):
class ExpressionDFilter (line 312) | class ExpressionDFilter(SeriesDFilter):
method __init__ (line 326) | def __init__(self, rule_expression, fstart_time=None, fend_time=None, ...
method _getFilterSeries (line 341) | def _getFilterSeries(self, instruments, fstart, fend):
method from_config (line 360) | def from_config(config):
method to_config (line 368) | def to_config(self):
FILE: qlib/data/inst_processor.py
class InstProcessor (line 6) | class InstProcessor:
method __call__ (line 8) | def __call__(self, df: pd.DataFrame, instrument, *args, **kwargs):
method __str__ (line 21) | def __str__(self):
FILE: qlib/data/ops.py
class ElemOperator (line 37) | class ElemOperator(ExpressionOps):
method __init__ (line 51) | def __init__(self, feature):
method __str__ (line 54) | def __str__(self):
method get_longest_back_rolling (line 57) | def get_longest_back_rolling(self):
method get_extended_window_size (line 60) | def get_extended_window_size(self):
class ChangeInstrument (line 64) | class ChangeInstrument(ElemOperator):
method __init__ (line 82) | def __init__(self, instrument, feature):
method __str__ (line 86) | def __str__(self):
method load (line 89) | def load(self, instrument, start_index, end_index, *args):
method _load_internal (line 93) | def _load_internal(self, instrument, start_index, end_index, *args):
class NpElemOperator (line 97) | class NpElemOperator(ElemOperator):
method __init__ (line 113) | def __init__(self, feature, func):
method _load_internal (line 117) | def _load_internal(self, instrument, start_index, end_index, *args):
class Abs (line 122) | class Abs(NpElemOperator):
method __init__ (line 136) | def __init__(self, feature):
class Sign (line 140) | class Sign(NpElemOperator):
method __init__ (line 154) | def __init__(self, feature):
method _load_internal (line 157) | def _load_internal(self, instrument, start_index, end_index, *args):
class Log (line 167) | class Log(NpElemOperator):
method __init__ (line 181) | def __init__(self, feature):
class Mask (line 185) | class Mask(NpElemOperator):
method __init__ (line 201) | def __init__(self, feature, instrument):
method __str__ (line 205) | def __str__(self):
method _load_internal (line 208) | def _load_internal(self, instrument, start_index, end_index, *args):
class Not (line 212) | class Not(NpElemOperator):
method __init__ (line 226) | def __init__(self, feature):
class PairOperator (line 231) | class PairOperator(ExpressionOps):
method __init__ (line 247) | def __init__(self, feature_left, feature_right):
method __str__ (line 251) | def __str__(self):
method get_longest_back_rolling (line 254) | def get_longest_back_rolling(self):
method get_extended_window_size (line 266) | def get_extended_window_size(self):
class NpPairOperator (line 279) | class NpPairOperator(PairOperator):
method __init__ (line 297) | def __init__(self, feature_left, feature_right, func):
method _load_internal (line 301) | def _load_internal(self, instrument, start_index, end_index, *args):
class Power (line 338) | class Power(NpPairOperator):
method __init__ (line 354) | def __init__(self, feature_left, feature_right):
class Add (line 358) | class Add(NpPairOperator):
method __init__ (line 374) | def __init__(self, feature_left, feature_right):
class Sub (line 378) | class Sub(NpPairOperator):
method __init__ (line 394) | def __init__(self, feature_left, feature_right):
class Mul (line 398) | class Mul(NpPairOperator):
method __init__ (line 414) | def __init__(self, feature_left, feature_right):
class Div (line 418) | class Div(NpPairOperator):
method __init__ (line 434) | def __init__(self, feature_left, feature_right):
class Greater (line 438) | class Greater(NpPairOperator):
method __init__ (line 454) | def __init__(self, feature_left, feature_right):
class Less (line 458) | class Less(NpPairOperator):
method __init__ (line 474) | def __init__(self, feature_left, feature_right):
class Gt (line 478) | class Gt(NpPairOperator):
method __init__ (line 494) | def __init__(self, feature_left, feature_right):
class Ge (line 498) | class Ge(NpPairOperator):
method __init__ (line 514) | def __init__(self, feature_left, feature_right):
class Lt (line 518) | class Lt(NpPairOperator):
method __init__ (line 534) | def __init__(self, feature_left, feature_right):
class Le (line 538) | class Le(NpPairOperator):
method __init__ (line 554) | def __init__(self, feature_left, feature_right):
class Eq (line 558) | class Eq(NpPairOperator):
method __init__ (line 574) | def __init__(self, feature_left, feature_right):
class Ne (line 578) | class Ne(NpPairOperator):
method __init__ (line 594) | def __init__(self, feature_left, feature_right):
class And (line 598) | class And(NpPairOperator):
method __init__ (line 614) | def __init__(self, feature_left, feature_right):
class Or (line 618) | class Or(NpPairOperator):
method __init__ (line 634) | def __init__(self, feature_left, feature_right):
class If (line 639) | class If(ExpressionOps):
method __init__ (line 652) | def __init__(self, condition, feature_left, feature_right):
method __str__ (line 657) | def __str__(self):
method _load_internal (line 660) | def _load_internal(self, instrument, start_index, end_index, *args):
method get_longest_back_rolling (line 673) | def get_longest_back_rolling(self):
method get_extended_window_size (line 690) | def get_extended_window_size(self):
class Rolling (line 713) | class Rolling(ExpressionOps):
method __init__ (line 734) | def __init__(self, feature, N, func):
method __str__ (line 739) | def __str__(self):
method _load_internal (line 742) | def _load_internal(self, instrument, start_index, end_index, *args):
method get_longest_back_rolling (line 757) | def get_longest_back_rolling(self):
method get_extended_window_size (line 764) | def get_extended_window_size(self):
class Ref (line 781) | class Ref(Rolling):
method __init__ (line 797) | def __init__(self, feature, N):
method _load_internal (line 800) | def _load_internal(self, instrument, start_index, end_index, *args):
method get_longest_back_rolling (line 811) | def get_longest_back_rolling(self):
method get_extended_window_size (line 816) | def get_extended_window_size(self):
class Mean (line 827) | class Mean(Rolling):
method __init__ (line 843) | def __init__(self, feature, N):
class Sum (line 847) | class Sum(Rolling):
method __init__ (line 863) | def __init__(self, feature, N):
class Std (line 867) | class Std(Rolling):
method __init__ (line 883) | def __init__(self, feature, N):
class Var (line 887) | class Var(Rolling):
method __init__ (line 903) | def __init__(self, feature, N):
class Skew (line 907) | class Skew(Rolling):
method __init__ (line 923) | def __init__(self, feature, N):
class Kurt (line 929) | class Kurt(Rolling):
method __init__ (line 945) | def __init__(self, feature, N):
class Max (line 951) | class Max(Rolling):
method __init__ (line 967) | def __init__(self, feature, N):
class IdxMax (line 971) | class IdxMax(Rolling):
method __init__ (line 987) | def __init__(self, feature, N):
method _load_internal (line 990) | def _load_internal(self, instrument, start_index, end_index, *args):
class Min (line 999) | class Min(Rolling):
method __init__ (line 1015) | def __init__(self, feature, N):
class IdxMin (line 1019) | class IdxMin(Rolling):
method __init__ (line 1035) | def __init__(self, feature, N):
method _load_internal (line 1038) | def _load_internal(self, instrument, start_index, end_index, *args):
class Quantile (line 1047) | class Quantile(Rolling):
method __init__ (line 1063) | def __init__(self, feature, N, qscore):
method __str__ (line 1067) | def __str__(self):
method _load_internal (line 1070) | def _load_internal(self, instrument, start_index, end_index, *args):
class Med (line 1079) | class Med(Rolling):
method __init__ (line 1095) | def __init__(self, feature, N):
class Mad (line 1099) | class Mad(Rolling):
method __init__ (line 1115) | def __init__(self, feature, N):
method _load_internal (line 1118) | def _load_internal(self, instrument, start_index, end_index, *args):
class Rank (line 1133) | class Rank(Rolling):
method __init__ (line 1149) | def __init__(self, feature, N):
method _load_internal (line 1153) | def _load_internal(self, instrument, start_index, end_index, *args):
class Count (line 1171) | class Count(Rolling):
method __init__ (line 1187) | def __init__(self, feature, N):
class Delta (line 1191) | class Delta(Rolling):
method __init__ (line 1207) | def __init__(self, feature, N):
method _load_internal (line 1210) | def _load_internal(self, instrument, start_index, end_index, *args):
class Slope (line 1221) | class Slope(Rolling):
method __init__ (line 1245) | def __init__(self, feature, N):
method _load_internal (line 1248) | def _load_internal(self, instrument, start_index, end_index, *args):
class Rsquare (line 1257) | class Rsquare(Rolling):
method __init__ (line 1273) | def __init__(self, feature, N):
method _load_internal (line 1276) | def _load_internal(self, instrument, start_index, end_index, *args):
class Resi (line 1286) | class Resi(Rolling):
method __init__ (line 1302) | def __init__(self, feature, N):
method _load_internal (line 1305) | def _load_internal(self, instrument, start_index, end_index, *args):
class WMA (line 1314) | class WMA(Rolling):
method __init__ (line 1330) | def __init__(self, feature, N):
method _load_internal (line 1333) | def _load_internal(self, instrument, start_index, end_index, *args):
class EMA (line 1349) | class EMA(Rolling):
method __init__ (line 1365) | def __init__(self, feature, N):
method _load_internal (line 1368) | def _load_internal(self, instrument, start_index, end_index, *args):
class PairRolling (line 1387) | class PairRolling(ExpressionOps):
method __init__ (line 1405) | def __init__(self, feature_left, feature_right, N, func):
method __str__ (line 1412) | def __str__(self):
method _load_internal (line 1415) | def _load_internal(self, instrument, start_index, end_index, *args):
method get_longest_back_rolling (line 1435) | def get_longest_back_rolling(self):
method get_extended_window_size (line 1449) | def get_extended_window_size(self):
class Corr (line 1467) | class Corr(PairRolling):
method __init__ (line 1485) | def __init__(self, feature_left, feature_right, N):
method _load_internal (line 1488) | def _load_internal(self, instrument, start_index, end_index, *args):
class Cov (line 1501) | class Cov(PairRolling):
method __init__ (line 1519) | def __init__(self, feature_left, feature_right, N):
class TResample (line 1528) | class TResample(ElemOperator):
method __init__ (line 1529) | def __init__(self, feature, freq, func):
method __str__ (line 1550) | def __str__(self):
method _load_internal (line 1553) | def _load_internal(self, instrument, start_index, end_index, *args):
class OpsWrapper (line 1619) | class OpsWrapper:
method __init__ (line 1622) | def __init__(self):
method reset (line 1625) | def reset(self):
method register (line 1628) | def register(self, ops_list: List[Union[Type[ExpressionOps], dict]]):
method __getattr__ (line 1661) | def __getattr__(self, key):
function register_all_ops (line 1670) | def register_all_ops(C):
FILE: qlib/data/pit.py
class P (line 24) | class P(ElemOperator):
method _load_internal (line 25) | def _load_internal(self, instrument, start_index, end_index, freq):
method _load_feature (line 51) | def _load_feature(self, instrument, start_index, end_index, cur_time):
method get_longest_back_rolling (line 54) | def get_longest_back_rolling(self):
method get_extended_window_size (line 58) | def get_extended_window_size(self):
class PRef (line 63) | class PRef(P):
method __init__ (line 64) | def __init__(self, feature, period):
method __str__ (line 68) | def __str__(self):
method _load_feature (line 71) | def _load_feature(self, instrument, start_index, end_index, cur_time):
FILE: qlib/data/storage/file_storage.py
class FileStorageMixin (line 21) | class FileStorageMixin:
method provider_uri (line 32) | def provider_uri(self):
method dpm (line 36) | def dpm(self):
method support_freq (line 44) | def support_freq(self) -> List[str]:
method uri (line 60) | def uri(self) -> Path:
method check (line 65) | def check(self):
class FileCalendarStorage (line 76) | class FileCalendarStorage(FileStorageMixin, CalendarStorage):
method __init__ (line 77) | def __init__(self, freq: str, future: bool, provider_uri: dict = None,...
method file_name (line 85) | def file_name(self) -> str:
method _freq_file (line 89) | def _freq_file(self) -> str:
method _read_calendar (line 105) | def _read_calendar(self) -> List[CalVT]:
method _write_calendar (line 122) | def _write_calendar(self, values: Iterable[CalVT], mode: str = "wb"):
method uri (line 127) | def uri(self) -> Path:
method data (line 131) | def data(self) -> List[CalVT]:
method _get_storage_freq (line 147) | def _get_storage_freq(self) -> List[str]:
method extend (line 150) | def extend(self, values: Iterable[CalVT]) -> None:
method clear (line 153) | def clear(self) -> None:
method index (line 156) | def index(self, value: CalVT) -> int:
method insert (line 161) | def insert(self, index: int, value: CalVT):
method remove (line 166) | def remove(self, value: CalVT) -> None:
method __setitem__ (line 173) | def __setitem__(self, i: Union[int, slice], values: Union[CalVT, Itera...
method __delitem__ (line 178) | def __delitem__(self, i: Union[int, slice]) -> None:
method __getitem__ (line 184) | def __getitem__(self, i: Union[int, slice]) -> Union[CalVT, List[CalVT]]:
method __len__ (line 188) | def __len__(self) -> int:
class FileInstrumentStorage (line 192) | class FileInstrumentStorage(FileStorageMixin, InstrumentStorage):
method __init__ (line 198) | def __init__(self, market: str, freq: str, provider_uri: dict = None, ...
method _read_instrument (line 203) | def _read_instrument(self) -> Dict[InstKT, InstVT]:
method _write_instrument (line 220) | def _write_instrument(self, data: Dict[InstKT, InstVT] = None) -> None:
method clear (line 238) | def clear(self) -> None:
method data (line 242) | def data(self) -> Dict[InstKT, InstVT]:
method __setitem__ (line 246) | def __setitem__(self, k: InstKT, v: InstVT) -> None:
method __delitem__ (line 251) | def __delitem__(self, k: InstKT) -> None:
method __getitem__ (line 257) | def __getitem__(self, k: InstKT) -> InstVT:
method update (line 261) | def update(self, *args, **kwargs) -> None:
method __len__ (line 281) | def __len__(self) -> int:
class FileFeatureStorage (line 285) | class FileFeatureStorage(FileStorageMixin, FeatureStorage):
method __init__ (line 286) | def __init__(self, instrument: str, field: str, freq: str, provider_ur...
method clear (line 291) | def clear(self):
method data (line 296) | def data(self) -> pd.Series:
method write (line 299) | def write(self, data_array: Union[List, np.ndarray], index: int = None...
method start_index (line 332) | def start_index(self) -> Union[int, None]:
method end_index (line 340) | def end_index(self) -> Union[int, None]:
method __getitem__ (line 346) | def __getitem__(self, i: Union[int, slice]) -> Union[Tuple[int, float]...
method __len__ (line 377) | def __len__(self) -> int:
FILE: qlib/data/storage/storage.py
class BaseStorage (line 78) | class BaseStorage:
method storage_name (line 80) | def storage_name(self) -> str:
class CalendarStorage (line 84) | class CalendarStorage(BaseStorage):
method __init__ (line 89) | def __init__(self, freq: str, future: bool, **kwargs):
method data (line 95) | def data(self) -> Iterable[CalVT]:
method clear (line 105) | def clear(self) -> None:
method extend (line 108) | def extend(self, iterable: Iterable[CalVT]) -> None:
method index (line 111) | def index(self, value: CalVT) -> int:
method insert (line 120) | def insert(self, index: int, value: CalVT) -> None:
method remove (line 123) | def remove(self, value: CalVT) -> None:
method __setitem__ (line 127) | def __setitem__(self, i: int, value: CalVT) -> None:
method __setitem__ (line 131) | def __setitem__(self, s: slice, value: Iterable[CalVT]) -> None:
method __setitem__ (line 134) | def __setitem__(self, i, value) -> None:
method __delitem__ (line 140) | def __delitem__(self, i: int) -> None:
method __delitem__ (line 144) | def __delitem__(self, i: slice) -> None:
method __delitem__ (line 147) | def __delitem__(self, i) -> None:
method __getitem__ (line 159) | def __getitem__(self, s: slice) -> Iterable[CalVT]:
method __getitem__ (line 163) | def __getitem__(self, i: int) -> CalVT:
method __getitem__ (line 166) | def __getitem__(self, i) -> CalVT:
method __len__ (line 179) | def __len__(self) -> int:
class InstrumentStorage (line 191) | class InstrumentStorage(BaseStorage):
method __init__ (line 192) | def __init__(self, market: str, freq: str, **kwargs):
method data (line 198) | def data(self) -> Dict[InstKT, InstVT]:
method clear (line 208) | def clear(self) -> None:
method update (line 211) | def update(self, *args, **kwargs) -> None:
method __setitem__ (line 225) | def __setitem__(self, k: InstKT, v: InstVT) -> None:
method __delitem__ (line 229) | def __delitem__(self, k: InstKT) -> None:
method __getitem__ (line 239) | def __getitem__(self, k: InstKT) -> InstVT:
method __len__ (line 243) | def __len__(self) -> int:
class FeatureStorage (line 255) | class FeatureStorage(BaseStorage):
method __init__ (line 256) | def __init__(self, instrument: str, field: str, freq: str, **kwargs):
method data (line 263) | def data(self) -> pd.Series:
method start_index (line 273) | def start_index(self) -> Union[int, None]:
method end_index (line 283) | def end_index(self) -> Union[int, None]:
method clear (line 296) | def clear(self) -> None:
method write (line 299) | def write(self, data_array: Union[List, np.ndarray, Tuple], index: int...
method rebase (line 354) | def rebase(self, start_index: int = None, end_index: int = None):
method rewrite (line 443) | def rewrite(self, data: Union[List, np.ndarray, Tuple], index: int):
method __getitem__ (line 457) | def __getitem__(self, s: slice) -> pd.Series:
method __getitem__ (line 466) | def __getitem__(self, i: int) -> Tuple[int, float]:
method __getitem__ (line 469) | def __getitem__(self, i) -> Union[Tuple[int, float], pd.Series]:
method __len__ (line 485) | def __len__(self) -> int:
FILE: qlib/log.py
class MetaLogger (line 15) | class MetaLogger(type):
method __new__ (line 16) | def __new__(mcs, name, bases, attrs): # pylint: disable=C0204
class QlibLogger (line 24) | class QlibLogger(metaclass=MetaLogger):
method __init__ (line 29) | def __init__(self, module_name):
method logger (line 36) | def logger(self):
method setLevel (line 41) | def setLevel(self, level):
method __getattr__ (line 44) | def __getattr__(self, name):
class _QLibLoggerManager (line 51) | class _QLibLoggerManager:
method __init__ (line 52) | def __init__(self):
method setLevel (line 55) | def setLevel(self, level):
method __call__ (line 59) | def __call__(self, module_name, level: Optional[int] = None) -> QlibLo...
class TimeInspector (line 86) | class TimeInspector:
method set_time_mark (line 92) | def set_time_mark(cls):
method pop_time_mark (line 103) | def pop_time_mark(cls):
method get_cost_time (line 110) | def get_cost_time(cls):
method log_cost_time (line 120) | def log_cost_time(cls, info="Done"):
method logt (line 131) | def logt(cls, name="", show_start=False):
function set_log_with_config (line 152) | def set_log_with_config(log_config: Dict[Text, Any]):
class LogFilter (line 161) | class LogFilter(logging.Filter):
method __init__ (line 162) | def __init__(self, param=None):
method match_msg (line 167) | def match_msg(filter_str, msg):
method filter (line 176) | def filter(self, record):
function set_global_logger_level (line 185) | def set_global_logger_level(level: int, return_orig_handler_level: bool ...
function set_global_logger_level_cm (line 227) | def set_global_logger_level_cm(level: int):
FILE: qlib/model/base.py
class BaseModel (line 10) | class BaseModel(Serializable, metaclass=abc.ABCMeta):
method predict (line 14) | def predict(self, *args, **kwargs) -> object:
method __call__ (line 17) | def __call__(self, *args, **kwargs) -> object:
class Model (line 22) | class Model(BaseModel):
method fit (line 25) | def fit(self, dataset: Dataset, reweighter: Reweighter):
method predict (line 63) | def predict(self, dataset: Dataset, segment: Union[Text, slice] = "tes...
class ModelFT (line 81) | class ModelFT(Model):
method finetune (line 85) | def finetune(self, dataset: Dataset):
FILE: qlib/model/ens/ensemble.py
class Ensemble (line 14) | class Ensemble:
method __call__ (line 28) | def __call__(self, ensemble_dict: dict, *args, **kwargs):
class SingleKeyEnsemble (line 32) | class SingleKeyEnsemble(Ensemble):
method __call__ (line 51) | def __call__(self, ensemble_dict: Union[dict, object], recursion: bool...
class RollingEnsemble (line 65) | class RollingEnsemble(Ensemble):
method __call__ (line 80) | def __call__(self, ensemble_dict: dict) -> pd.DataFrame:
class AverageEnsemble (line 91) | class AverageEnsemble(Ensemble):
method __call__ (line 107) | def __call__(self, ensemble_dict: dict) -> pd.DataFrame:
FILE: qlib/model/ens/group.py
class Group (line 20) | class Group:
method __init__ (line 23) | def __init__(self, group_func=None, ens: Ensemble = None):
method group (line 39) | def group(self, *args, **kwargs) -> dict:
method reduce (line 53) | def reduce(self, *args, **kwargs) -> dict:
method __call__ (line 67) | def __call__(self, ungrouped_dict: dict, n_jobs: int = 1, verbose: int...
class RollingGroup (line 92) | class RollingGroup(Group):
method group (line 95) | def group(self, rolling_dict: dict) -> dict:
method __init__ (line 114) | def __init__(self, ens=RollingEnsemble()):
FILE: qlib/model/interpret/base.py
class FeatureInt (line 12) | class FeatureInt:
method get_feature_importance (line 16) | def get_feature_importance(self) -> pd.Series:
class LightGBMFInt (line 27) | class LightGBMFInt(FeatureInt):
method __init__ (line 30) | def __init__(self):
method get_feature_importance (line 33) | def get_feature_importance(self, *args, **kwargs) -> pd.Series:
FILE: qlib/model/meta/dataset.py
class MetaTaskDataset (line 10) | class MetaTaskDataset(Serializable, metaclass=abc.ABCMeta):
method __init__ (line 27) | def __init__(self, segments: Union[Dict[Text, Tuple], float], *args, *...
method prepare_tasks (line 39) | def prepare_tasks(self, segments: Union[List[Text], Text], *args, **kw...
method _prepare_seg (line 69) | def _prepare_seg(self, segment: Text):
FILE: qlib/model/meta/model.py
class MetaModel (line 10) | class MetaModel(metaclass=abc.ABCMeta):
method fit (line 20) | def fit(self, *args, **kwargs):
method inference (line 26) | def inference(self, *args, **kwargs) -> object:
class MetaTaskModel (line 37) | class MetaTaskModel(MetaModel):
method fit (line 42) | def fit(self, meta_dataset: MetaTaskDataset):
method inference (line 49) | def inference(self, meta_dataset: MetaTaskDataset) -> List[dict]:
class MetaGuideModel (line 64) | class MetaGuideModel(MetaModel):
method fit (line 70) | def fit(self, *args, **kwargs):
method inference (line 74) | def inference(self, *args, **kwargs):
FILE: qlib/model/meta/task.py
class MetaTask (line 8) | class MetaTask:
method __init__ (line 26) | def __init__(self, task: dict, meta_info: object, mode: str = PROC_MOD...
method get_dataset (line 46) | def get_dataset(self) -> Dataset:
method get_meta_input (line 49) | def get_meta_input(self) -> object:
method __repr__ (line 55) | def __repr__(self):
FILE: qlib/model/riskmodel/base.py
class RiskModel (line 12) | class RiskModel(BaseModel):
method __init__ (line 22) | def __init__(self, nan_option: str = "ignore", assume_centered: bool =...
method predict (line 40) | def predict(
method _predict (line 113) | def _predict(self, X: np.ndarray) -> np.ndarray:
method _preprocess (line 133) | def _preprocess(self, X: np.ndarray) -> Union[np.ndarray, np.ma.Masked...
FILE: qlib/model/riskmodel/poet.py
class POETCovEstimator (line 6) | class POETCovEstimator(RiskModel):
method __init__ (line 19) | def __init__(self, num_factors: int = 0, thresh: float = 1.0, thresh_m...
method _predict (line 45) | def _predict(self, X: np.ndarray) -> np.ndarray:
FILE: qlib/model/riskmodel/shrink.py
class ShrinkCovEstimator (line 7) | class ShrinkCovEstimator(RiskModel):
method __init__ (line 54) | def __init__(self, alpha: Union[str, float] = 0.0, target: Union[str, ...
method _predict (line 87) | def _predict(self, X: np.ndarray) -> np.ndarray:
method _get_shrink_target (line 105) | def _get_shrink_target(self, X: np.ndarray, S: np.ndarray) -> np.ndarray:
method _get_shrink_target_const_var (line 115) | def _get_shrink_target_const_var(self, X: np.ndarray, S: np.ndarray) -...
method _get_shrink_target_const_corr (line 126) | def _get_shrink_target_const_corr(self, X: np.ndarray, S: np.ndarray) ...
method _get_shrink_target_single_factor (line 141) | def _get_shrink_target_single_factor(self, X: np.ndarray, S: np.ndarra...
method _get_shrink_param (line 150) | def _get_shrink_param(self, X: np.ndarray, S: np.ndarray, F: np.ndarra...
method _get_shrink_param_oas (line 167) | def _get_shrink_param_oas(self, X: np.ndarray, S: np.ndarray, F: np.nd...
method _get_shrink_param_lw_const_var (line 188) | def _get_shrink_param_lw_const_var(self, X: np.ndarray, S: np.ndarray,...
method _get_shrink_param_lw_const_corr (line 205) | def _get_shrink_param_lw_const_corr(self, X: np.ndarray, S: np.ndarray...
method _get_shrink_param_lw_single_factor (line 231) | def _get_shrink_param_lw_single_factor(self, X: np.ndarray, S: np.ndar...
FILE: qlib/model/riskmodel/structured.py
class StructuredCovEstimator (line 11) | class StructuredCovEstimator(RiskModel):
method __init__ (line 45) | def __init__(self, factor_model: str = "pca", num_factors: int = 10, *...
method _predict (line 69) | def _predict(self, X: np.ndarray, return_decomposed_components=False) ...
FILE: qlib/model/trainer.py
function _log_task_info (line 36) | def _log_task_info(task_config: dict):
function _exe_task (line 42) | def _exe_task(task_config: dict):
function begin_task_train (line 74) | def begin_task_train(task_config: dict, experiment_name: str, recorder_n...
function end_task_train (line 91) | def end_task_train(rec: Recorder, experiment_name: str) -> Recorder:
function task_train (line 108) | def task_train(task_config: dict, experiment_name: str, recorder_name: s...
class Trainer (line 131) | class Trainer:
method __init__ (line 137) | def __init__(self):
method train (line 140) | def train(self, tasks: list, *args, **kwargs) -> list:
method end_train (line 155) | def end_train(self, models: list, *args, **kwargs) -> list:
method is_delay (line 172) | def is_delay(self) -> bool:
method __call__ (line 181) | def __call__(self, *args, **kwargs) -> list:
method has_worker (line 184) | def has_worker(self) -> bool:
method worker (line 197) | def worker(self):
class TrainerR (line 209) | class TrainerR(Trainer):
method __init__ (line 222) | def __init__(
method train (line 243) | def train(
method end_train (line 276) | def end_train(self, models: list, **kwargs) -> List[Recorder]:
class DelayTrainerR (line 293) | class DelayTrainerR(TrainerR):
method __init__ (line 298) | def __init__(
method end_train (line 313) | def end_train(self, models, end_train_func=None, experiment_name: str ...
class TrainerRM (line 341) | class TrainerRM(Trainer):
method __init__ (line 357) | def __init__(
method train (line 384) | def train(
method end_train (line 450) | def end_train(self, recs: list, **kwargs) -> List[Recorder]:
method worker (line 466) | def worker(
method has_worker (line 487) | def has_worker(self) -> bool:
class DelayTrainerRM (line 491) | class DelayTrainerRM(TrainerRM):
method __init__ (line 497) | def __init__(
method train (line 524) | def train(self, tasks: list, train_func=None, experiment_name: str = N...
method end_train (line 552) | def end_train(self, recs, end_train_func=None, experiment_name: str = ...
method worker (line 596) | def worker(self, end_train_func=None, experiment_name: str = None):
method has_worker (line 618) | def has_worker(self) -> bool:
FILE: qlib/model/utils.py
class ConcatDataset (line 7) | class ConcatDataset(Dataset):
method __init__ (line 8) | def __init__(self, *datasets):
method __getitem__ (line 11) | def __getitem__(self, i):
method __len__ (line 14) | def __len__(self):
class IndexSampler (line 18) | class IndexSampler:
method __init__ (line 19) | def __init__(self, sampler):
method __getitem__ (line 22) | def __getitem__(self, i: int):
method __len__ (line 25) | def __len__(self):
FILE: qlib/rl/aux_info.py
class AuxiliaryInfoCollector (line 21) | class AuxiliaryInfoCollector(Generic[StateType, AuxInfoType]):
method __call__ (line 27) | def __call__(self, simulator_state: StateType) -> AuxInfoType:
method collect (line 30) | def collect(self, simulator_state: StateType) -> AuxInfoType:
FILE: qlib/rl/contrib/backtest.py
function _get_multi_level_executor_config (line 29) | def _get_multi_level_executor_config(
function _convert_indicator_to_dataframe (line 64) | def _convert_indicator_to_dataframe(indicator: dict) -> Optional[pd.Data...
function _generate_report (line 88) | def _generate_report(
function single_with_simulator (line 127) | def single_with_simulator(
function single_with_collect_data_loop (line 222) | def single_with_collect_data_loop(
function backtest (line 317) | def backtest(backtest_config: dict, with_simulator: bool = False) -> pd....
FILE: qlib/rl/contrib/naive_config_parser.py
function merge_a_into_b (line 15) | def merge_a_into_b(a: dict, b: dict) -> dict:
function check_file_exist (line 26) | def check_file_exist(filename: str, msg_tmpl: str = 'file "{}" does not ...
function parse_backtest_config (line 31) | def parse_backtest_config(path: str) -> dict:
function _convert_all_list_to_tuple (line 73) | def _convert_all_list_to_tuple(config: dict) -> dict:
function get_backtest_config_fromfile (line 82) | def get_backtest_config_fromfile(path: str) -> dict:
FILE: qlib/rl/contrib/train_onpolicy.py
function seed_everything (line 32) | def seed_everything(seed: int) -> None:
function _read_orders (line 40) | def _read_orders(order_dir: Path) -> pd.DataFrame:
class LazyLoadDataset (line 51) | class LazyLoadDataset(Dataset):
method __init__ (line 52) | def __init__(
method __len__ (line 66) | def __len__(self) -> int:
method __getitem__ (line 69) | def __getitem__(self, index: int) -> Order:
function train_and_test (line 100) | def train_and_test(
function main (line 204) | def main(config: dict, run_training: bool, run_backtest: bool) -> None:
FILE: qlib/rl/contrib/utils.py
function read_order_file (line 11) | def read_order_file(order_file: Path | pd.DataFrame) -> pd.DataFrame:
FILE: qlib/rl/data/base.py
class BaseIntradayBacktestData (line 10) | class BaseIntradayBacktestData:
method __repr__ (line 19) | def __repr__(self) -> str:
method __len__ (line 23) | def __len__(self) -> int:
method get_deal_price (line 27) | def get_deal_price(self) -> pd.Series:
method get_volume (line 31) | def get_volume(self) -> pd.Series:
method get_time_index (line 35) | def get_time_index(self) -> pd.DatetimeIndex:
class BaseIntradayProcessedData (line 39) | class BaseIntradayProcessedData:
class ProcessedDataProvider (line 55) | class ProcessedDataProvider:
method get_data (line 58) | def get_data(
FILE: qlib/rl/data/integration.py
function init_qlib (line 18) | def init_qlib(qlib_config: dict) -> None:
FILE: qlib/rl/data/native.py
function get_ticks_slice (line 20) | def get_ticks_slice(
class IntradayBacktestData (line 31) | class IntradayBacktestData(BaseIntradayBacktestData):
method __init__ (line 34) | def __init__(
method __repr__ (line 68) | def __repr__(self) -> str:
method __len__ (line 74) | def __len__(self) -> int:
method get_deal_price (line 77) | def get_deal_price(self) -> pd.Series:
method get_volume (line 80) | def get_volume(self) -> pd.Series:
method get_time_index (line 83) | def get_time_index(self) -> pd.DatetimeIndex:
class DataframeIntradayBacktestData (line 87) | class DataframeIntradayBacktestData(BaseIntradayBacktestData):
method __init__ (line 90) | def __init__(self, df: pd.DataFrame, price_column: str = "$close0", vo...
method __repr__ (line 95) | def __repr__(self) -> str:
method __len__ (line 99) | def __len__(self) -> int:
method get_deal_price (line 102) | def get_deal_price(self) -> pd.Series:
method get_volume (line 105) | def get_volume(self) -> pd.Series:
method get_time_index (line 108) | def get_time_index(self) -> pd.DatetimeIndex:
function load_backtest_data (line 116) | def load_backtest_data(
class HandlerIntradayProcessedData (line 144) | class HandlerIntradayProcessedData(BaseIntradayProcessedData):
method __init__ (line 147) | def __init__(
method __repr__ (line 176) | def __repr__(self) -> str:
function load_handler_intraday_processed_data (line 190) | def load_handler_intraday_processed_data(
class HandlerProcessedDataProvider (line 204) | class HandlerProcessedDataProvider(ProcessedDataProvider):
method __init__ (line 205) | def __init__(
method get_data (line 219) | def get_data(
FILE: qlib/rl/data/pickle_styled.py
function _infer_processed_data_column_names (line 43) | def _infer_processed_data_column_names(shape: int) -> List[str]:
function _find_pickle (line 70) | def _find_pickle(filename_without_suffix: Path) -> Path:
function _read_pickle (line 85) | def _read_pickle(filename_without_suffix: Path) -> pd.DataFrame:
class SimpleIntradayBacktestData (line 98) | class SimpleIntradayBacktestData(BaseIntradayBacktestData):
method __init__ (line 101) | def __init__(
method __repr__ (line 121) | def __repr__(self) -> str:
method __len__ (line 125) | def __len__(self) -> int:
method get_deal_price (line 128) | def get_deal_price(self) -> pd.Series:
method get_volume (line 153) | def get_volume(self) -> pd.Series:
method get_time_index (line 157) | def get_time_index(self) -> pd.DatetimeIndex:
class PickleIntradayProcessedData (line 161) | class PickleIntradayProcessedData(BaseIntradayProcessedData):
method __init__ (line 164) | def __init__(
method __repr__ (line 200) | def __repr__(self) -> str:
function load_simple_intraday_backtest_data (line 206) | def load_simple_intraday_backtest_data(
function load_pickle_intraday_processed_data (line 220) | def load_pickle_intraday_processed_data(
class PickleProcessedDataProvider (line 230) | class PickleProcessedDataProvider(ProcessedDataProvider):
method __init__ (line 231) | def __init__(self, data_dir: Path) -> None:
method get_data (line 236) | def get_data(
function load_orders (line 252) | def load_orders(
FILE: qlib/rl/interpreter.py
class Interpreter (line 19) | class Interpreter:
class StateInterpreter (line 35) | class StateInterpreter(Generic[StateType, ObsType], Interpreter):
method observation_space (line 39) | def observation_space(self) -> gym.Space:
method __call__ (line 43) | def __call__(self, simulator_state: StateType) -> ObsType:
method validate (line 48) | def validate(self, obs: ObsType) -> None:
method interpret (line 52) | def interpret(self, simulator_state: StateType) -> ObsType:
class ActionInterpreter (line 67) | class ActionInterpreter(Generic[StateType, PolicyActType, ActType], Inte...
method action_space (line 71) | def action_space(self) -> gym.Space:
method __call__ (line 75) | def __call__(self, simulator_state: StateType, action: PolicyActType) ...
method validate (line 80) | def validate(self, action: PolicyActType) -> None:
method interpret (line 84) | def interpret(self, simulator_state: StateType, action: PolicyActType)...
function _gym_space_contains (line 101) | def _gym_space_contains(space: gym.Space, x: Any) -> None:
class GymSpaceValidationError (line 134) | class GymSpaceValidationError(Exception):
method __init__ (line 135) | def __init__(self, message: str, space: gym.Space, x: Any) -> None:
method __str__ (line 140) | def __str__(self) -> str:
FILE: qlib/rl/order_execution/interpreter.py
function canonicalize (line 30) | def canonicalize(value: int | float | np.ndarray | pd.DataFrame | dict) ...
class FullHistoryObs (line 44) | class FullHistoryObs(TypedDict):
class DummyStateInterpreter (line 56) | class DummyStateInterpreter(StateInterpreter[SAOEState, dict]):
method interpret (line 59) | def interpret(self, state: SAOEState) -> dict:
method observation_space (line 64) | def observation_space(self) -> spaces.Dict:
class FullHistoryStateInterpreter (line 68) | class FullHistoryStateInterpreter(StateInterpreter[SAOEState, FullHistor...
method __init__ (line 84) | def __init__(
method interpret (line 101) | def interpret(self, state: SAOEState) -> FullHistoryObs:
method observation_space (line 134) | def observation_space(self) -> spaces.Dict:
method _mask_future_info (line 150) | def _mask_future_info(arr: pd.DataFrame, current: pd.Timestamp) -> pd....
class CurrentStateObs (line 156) | class CurrentStateObs(TypedDict):
class CurrentStepStateInterpreter (line 164) | class CurrentStepStateInterpreter(StateInterpreter[SAOEState, CurrentSta...
method __init__ (line 171) | def __init__(self, max_step: int) -> None:
method observation_space (line 177) | def observation_space(self) -> spaces.Dict:
method interpret (line 187) | def interpret(self, state: SAOEState) -> CurrentStateObs:
class CategoricalActionInterpreter (line 199) | class CategoricalActionInterpreter(ActionInterpreter[SAOEState, int, flo...
method __init__ (line 213) | def __init__(self, values: int | List[float], max_step: Optional[int] ...
method action_space (line 222) | def action_space(self) -> spaces.Discrete:
method interpret (line 225) | def interpret(self, state: SAOEState, action: int) -> float:
class TwapRelativeActionInterpreter (line 233) | class TwapRelativeActionInterpreter(ActionInterpreter[SAOEState, float, ...
method action_space (line 243) | def action_space(self) -> spaces.Box:
method interpret (line 246) | def interpret(self, state: SAOEState, action: float) -> float:
function _to_int32 (line 252) | def _to_int32(val):
function _to_float32 (line 256) | def _to_float32(val):
FILE: qlib/rl/order_execution/network.py
class Recurrent (line 19) | class Recurrent(nn.Module):
method __init__ (line 30) | def __init__(
method _init_extra_branches (line 66) | def _init_extra_branches(self) -> None:
method _source_features (line 69) | def _source_features(self, obs: FullHistoryObs, device: torch.device) ...
method forward (line 99) | def forward(self, batch: Batch) -> torch.Tensor:
class Attention (line 122) | class Attention(nn.Module):
method __init__ (line 123) | def __init__(self, in_dim, out_dim):
method forward (line 129) | def forward(self, Q, K, V):
FILE: qlib/rl/order_execution/policy.py
class NonLearnablePolicy (l
Condensed preview — 571 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (3,438K chars).
[
{
"path": ".commitlintrc.js",
"chars": 920,
"preview": "module.exports = {\n extends: [\"@commitlint/config-conventional\"],\n rules: {\n // Configuration Format: [leve"
},
{
"path": ".deepsource.toml",
"chars": 179,
"preview": "version = 1\n\ntest_patterns = [\"tests/test_*.py\"]\n\nexclude_patterns = [\"examples/**\"]\n\n[[analyzers]]\nname = \"python\"\nenab"
},
{
"path": ".dockerignore",
"chars": 49,
"preview": "__pycache__\n*.pyc\n*.pyo\n*.pyd\n.Python\n.env\n.git\n\n"
},
{
"path": ".github/ISSUE_TEMPLATE/bug-report.md",
"chars": 832,
"preview": "---\nname: \"\\U0001F41B Bug Report\"\nabout: Submit a bug report to help us improve Qlib\nlabels: bug\n\n---\n\n## 🐛 Bug Descript"
},
{
"path": ".github/ISSUE_TEMPLATE/documentation.md",
"chars": 201,
"preview": "---\nname: \"\\U0001F4D6 Documentation\"\nabout: Report an issue related to documentation\n\n---\n\n## 📖 Documentation\n\n<!-- Plea"
},
{
"path": ".github/ISSUE_TEMPLATE/feature-request.md",
"chars": 589,
"preview": "---\nname: \"\\U0001F31FFeature Request\"\nabout: Request for a new Qlib feature\nlabels: enhancement\n\n---\n\n## 🌟 Feature Descr"
},
{
"path": ".github/ISSUE_TEMPLATE/question.md",
"chars": 392,
"preview": "---\nname: \"❓Questions & Help\"\nabout: Have some questions? We can offer help.\nlabels: question\n\n---\n\n## ❓ Questions and H"
},
{
"path": ".github/PULL_REQUEST_TEMPLATE.md",
"chars": 2310,
"preview": "<!--- Thank you for submitting a Pull Request! In order to make our work smoother. -->\n<!--- please make sure your Pull "
},
{
"path": ".github/brew_install.sh",
"chars": 18880,
"preview": "#!/bin/bash\nset -u\n\n# First check if the OS is Linux.\nif [[ \"$(uname)\" = \"Linux\" ]]; then\n HOMEBREW_ON_LINUX=1\nfi\n\n# On"
},
{
"path": ".github/release-drafter.yml",
"chars": 721,
"preview": "name-template: 'v$RESOLVED_VERSION 🌈'\ntag-template: 'v$RESOLVED_VERSION'\ncategories:\n - title: '🌟 Features'\n labels:"
},
{
"path": ".github/workflows/lint_title.yml",
"chars": 877,
"preview": "name: Lint pull request title\n\non:\n pull_request:\n types:\n - opened\n - synchronize\n - reopened\n "
},
{
"path": ".github/workflows/release.yml",
"chars": 3528,
"preview": "name: Release\n\non:\n push:\n branches:\n - main\n\npermissions:\n contents: read\n\njobs:\n release:\n runs-on: ubun"
},
{
"path": ".github/workflows/stale.yml",
"chars": 888,
"preview": "name: Mark stale issues and pull requests\n\non:\n schedule:\n - cron: \"0 0/3 * * *\"\n\njobs:\n stale:\n\n runs-on: ubuntu-"
},
{
"path": ".github/workflows/test_qlib_from_pip.yml",
"chars": 1652,
"preview": "name: Test qlib from pip\n\non:\n push:\n branches: [ main ]\n pull_request:\n branches: [ main ]\n\njobs:\n build:\n "
},
{
"path": ".github/workflows/test_qlib_from_source.yml",
"chars": 4568,
"preview": "name: Test qlib from source\n\non:\n push:\n branches: [ main ]\n pull_request:\n branches: [ main ]\n\njobs:\n build:\n "
},
{
"path": ".github/workflows/test_qlib_from_source_slow.yml",
"chars": 1701,
"preview": "name: Test qlib from source slow\n\non:\n push:\n branches: [ main ]\n pull_request:\n branches: [ main ]\n\njobs:\n bui"
},
{
"path": ".gitignore",
"chars": 622,
"preview": "# https://github.com/github/gitignore/blob/master/Python.gitignore\n__pycache__/\n\n*.pyc\n*.pyd\n*.so\n*.ipynb\n.ipynb_checkpo"
},
{
"path": ".mypy.ini",
"chars": 359,
"preview": "[mypy]\nexclude = (?x)(\n ^qlib/backtest/high_performance_ds\\.py$\n | ^qlib/contrib\n | ^qlib/data\n | ^qlib/mode"
},
{
"path": ".pre-commit-config.yaml",
"chars": 278,
"preview": "repos:\n- repo: https://github.com/psf/black\n rev: 23.7.0\n hooks:\n - id: black\n args: [\"qlib\", \"-l 12"
},
{
"path": ".pylintrc",
"chars": 218,
"preview": "[TYPECHECK]\n# https://stackoverflow.com/a/53572939 \n# List of members which are set dynamically and missed by Pylint inf"
},
{
"path": ".readthedocs.yaml",
"chars": 574,
"preview": "# .readthedocs.yml\n# Read the Docs configuration file\n# See https://docs.readthedocs.io/en/stable/config-file/v2.html fo"
},
{
"path": "CHANGELOG.md",
"chars": 0,
"preview": ""
},
{
"path": "CHANGES.rst",
"chars": 7611,
"preview": "Changelog\n=========\nHere you can see the full list of changes between each QLib release.\n\nVersion 0.1.0\n-------------\nTh"
},
{
"path": "CODE_OF_CONDUCT.md",
"chars": 444,
"preview": "# Microsoft Open Source Code of Conduct\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://op"
},
{
"path": "Dockerfile",
"chars": 796,
"preview": "FROM continuumio/miniconda3:latest\n\nWORKDIR /qlib\n\nCOPY . .\n\nRUN apt-get update && \\\n apt-get install -y build-essent"
},
{
"path": "LICENSE",
"chars": 1141,
"preview": " MIT License\n\n Copyright (c) Microsoft Corporation.\n\n Permission is hereby granted, free of charge, to any pers"
},
{
"path": "MANIFEST.in",
"chars": 111,
"preview": "exclude tests/*\ninclude qlib/*\ninclude qlib/*/*\ninclude qlib/*/*/*\ninclude qlib/*/*/*/*\ninclude qlib/*/*/*/*/*\n"
},
{
"path": "Makefile",
"chars": 9109,
"preview": ".PHONY: clean deepclean prerequisite dependencies lightgbm rl develop lint docs package test analysis all install dev bl"
},
{
"path": "README.md",
"chars": 43026,
"preview": "[](https://pypi.org/pro"
},
{
"path": "SECURITY.md",
"chars": 2780,
"preview": "<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->\n\n## Security\n\nMicrosoft takes the security of our software products an"
},
{
"path": "build_docker_image.sh",
"chars": 1069,
"preview": "#!/bin/bash\n\ndocker_user=\"your_dockerhub_username\"\n\nread -p \"Do you want to build the nightly version of the qlib image?"
},
{
"path": "docs/FAQ/FAQ.rst",
"chars": 6419,
"preview": "\nQlib FAQ\n############\n\nQlib Frequently Asked Questions\n===============================\n.. contents::\n :depth: 1\n "
},
{
"path": "docs/Makefile",
"chars": 643,
"preview": "# Minimal makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line.\nSPHINXOPTS =\nSPHI"
},
{
"path": "docs/_static/demo.sh",
"chars": 248,
"preview": "#!/bin/sh\ngit clone https://github.com/microsoft/qlib.git\ncd qlib\nls\npip install pyqlib\n# or\n# pip install numpy\n# pip i"
},
{
"path": "docs/advanced/PIT.rst",
"chars": 7294,
"preview": ".. _pit:\n\n============================\n(P)oint-(I)n-(T)ime Database\n============================\n.. currentmodule:: qlib"
},
{
"path": "docs/advanced/alpha.rst",
"chars": 2945,
"preview": ".. _alpha:\n\n=========================\nBuilding Formulaic Alphas\n=========================\n.. currentmodule:: qlib\n\nIntro"
},
{
"path": "docs/advanced/serial.rst",
"chars": 2209,
"preview": ".. _serial:\n\n=============\nSerialization\n=============\n.. currentmodule:: qlib\n\nIntroduction\n============\n``Qlib`` suppo"
},
{
"path": "docs/advanced/server.rst",
"chars": 1117,
"preview": ".. _server:\n\n=============================\n``Online`` & ``Offline`` mode\n=============================\n.. currentmodule:"
},
{
"path": "docs/advanced/task_management.rst",
"chars": 5910,
"preview": ".. _task_management:\n\n===============\nTask Management\n===============\n.. currentmodule:: qlib\n\n\nIntroduction\n==========="
},
{
"path": "docs/changelog/changelog.rst",
"chars": 31,
"preview": ".. include:: ../../CHANGES.rst\n"
},
{
"path": "docs/component/data.rst",
"chars": 27908,
"preview": ".. _data:\n\n==================================\nData Layer: Data Framework & Usage\n==================================\n\nInt"
},
{
"path": "docs/component/highfreq.rst",
"chars": 3877,
"preview": ".. _highfreq:\n\n========================================================================\nDesign of Nested Decision Execut"
},
{
"path": "docs/component/meta.rst",
"chars": 3002,
"preview": ".. _meta:\n\n======================================================\nMeta Controller: Meta-Task & Meta-Dataset & Meta-Model"
},
{
"path": "docs/component/model.rst",
"chars": 4756,
"preview": ".. _model:\n\n===========================================\nForecast Model: Model Training & Prediction\n===================="
},
{
"path": "docs/component/online.rst",
"chars": 2080,
"preview": ".. _online_serving:\n\n==============\nOnline Serving\n==============\n.. currentmodule:: qlib\n\n\nIntroduction\n============\n\n."
},
{
"path": "docs/component/recorder.rst",
"chars": 7049,
"preview": ".. _recorder:\n\n====================================\nQlib Recorder: Experiment Management\n==============================="
},
{
"path": "docs/component/report.rst",
"chars": 12114,
"preview": ".. _report:\n\n=======================================\nAnalysis: Evaluation & Results Analysis\n==========================="
},
{
"path": "docs/component/rl/framework.rst",
"chars": 4697,
"preview": "The Framework of QlibRL\n=======================\n\nQlibRL contains a full set of components that cover the entire lifecycl"
},
{
"path": "docs/component/rl/guidance.rst",
"chars": 4398,
"preview": "\n========\nGuidance\n========\n.. currentmodule:: qlib\n\nQlibRL can help users quickly get started and conveniently implemen"
},
{
"path": "docs/component/rl/overall.rst",
"chars": 8059,
"preview": "=====================================================\nReinforcement Learning in Quantitative Trading\n==================="
},
{
"path": "docs/component/rl/quickstart.rst",
"chars": 7642,
"preview": "\nQuick Start\n============\n.. currentmodule:: qlib\n\nQlibRL provides an example of an implementation of a single asset ord"
},
{
"path": "docs/component/rl/toctree.rst",
"chars": 317,
"preview": ".. _rl:\n\n========================================================================\nReinforcement Learning in Quantitative"
},
{
"path": "docs/component/strategy.rst",
"chars": 14354,
"preview": ".. _strategy:\n\n========================================\nPortfolio Strategy: Portfolio Management\n======================="
},
{
"path": "docs/component/workflow.rst",
"chars": 11020,
"preview": ".. _workflow:\n\n=============================\nWorkflow: Workflow Management\n=============================\n.. currentmodul"
},
{
"path": "docs/conf.py",
"chars": 6646,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\n\n# QLib documentation build configuration file"
},
{
"path": "docs/developer/code_standard_and_dev_guide.rst",
"chars": 2478,
"preview": ".. _code_standard:\n\n=============\nCode Standard\n=============\n\nDocstring\n=========\nPlease use the `Numpydoc Style <https"
},
{
"path": "docs/developer/how_to_build_image.rst",
"chars": 2573,
"preview": ".. _docker_image:\n\n==================\nBuild Docker Image\n==================\n\nDockerfile\n==========\n\nThere is a **Dockerf"
},
{
"path": "docs/hidden/client.rst",
"chars": 8415,
"preview": ".. _client:\n\nQlib Client-Server Framework\n============================\n\n.. currentmodule:: qlib\n\nIntroduction\n----------"
},
{
"path": "docs/hidden/online.rst",
"chars": 8746,
"preview": ".. _online:\n\nOnline\n======\n.. currentmodule:: qlib\n\nIntroduction\n------------\n\nWelcome to use Online, this module simula"
},
{
"path": "docs/hidden/tuner.rst",
"chars": 14521,
"preview": ".. _tuner:\r\n\r\nTuner\r\n=====\r\n.. currentmodule:: qlib\r\n\r\nIntroduction\r\n------------\r\n\r\nWelcome to use Tuner, this document"
},
{
"path": "docs/index.rst",
"chars": 2205,
"preview": "======================\n``Qlib`` Documentation\n======================\n\n``Qlib`` is an AI-oriented quantitative investment"
},
{
"path": "docs/introduction/introduction.rst",
"chars": 4210,
"preview": "===============================\n``Qlib``: Quantitative Platform\n===============================\n\nIntroduction\n=========="
},
{
"path": "docs/introduction/quick.rst",
"chars": 3948,
"preview": "\n===========\nQuick Start\n===========\n\nIntroduction\n============\n\nThis ``Quick Start`` guide tries to demonstrate\n\n- It's"
},
{
"path": "docs/make.bat",
"chars": 800,
"preview": "@ECHO OFF\r\n\r\npushd %~dp0\r\n\r\nREM Command file for Sphinx documentation\r\n\r\nif \"%SPHINXBUILD%\" == \"\" (\r\n\tset SPHINXBUILD=sp"
},
{
"path": "docs/reference/api.rst",
"chars": 4313,
"preview": ".. _api:\n\n=============\nAPI Reference\n=============\n\n\n\nHere you can find all ``Qlib`` interfaces.\n\n\nData\n====\n\nProvider\n"
},
{
"path": "docs/requirements.txt",
"chars": 71,
"preview": "Cython\ncmake\nnumpy\nscipy\nscikit-learn\npandas\ntianshou\nsphinx_rtd_theme\n"
},
{
"path": "docs/start/getdata.rst",
"chars": 6449,
"preview": ".. _getdata:\n\n==============\nData Retrieval\n==============\n\n.. currentmodule:: qlib\n\nIntroduction\n============\n\nUsers ca"
},
{
"path": "docs/start/initialization.rst",
"chars": 5438,
"preview": ".. _initialization:\n\n===================\nQlib Initialization\n===================\n\n.. currentmodule:: qlib\n\n\nInitializati"
},
{
"path": "docs/start/installation.rst",
"chars": 1179,
"preview": ".. _installation:\n\n============\nInstallation\n============\n\n.. currentmodule:: qlib\n\n\n``Qlib`` Installation\n============="
},
{
"path": "docs/start/integration.rst",
"chars": 7428,
"preview": "========================\nCustom Model Integration\n========================\n\nIntroduction\n============\n\n``Qlib``'s `Model"
},
{
"path": "examples/README.md",
"chars": 307,
"preview": "# Requirements\n\nHere is the minimal hardware requirements to run the `workflow_by_code` example.\n- Memory: 16G\n- Free Di"
},
{
"path": "examples/benchmarks/ADARNN/README.md",
"chars": 283,
"preview": "# AdaRNN\n* Code: [https://github.com/jindongwang/transferlearning/tree/master/code/deep/adarnn](https://github.com/jindo"
},
{
"path": "examples/benchmarks/ADARNN/requirements.txt",
"chars": 62,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/ADARNN/workflow_config_adarnn_Alpha360.yaml",
"chars": 2497,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/ADD/README.md",
"chars": 145,
"preview": "# ADD\n* Paper: [ADD: Augmented Disentanglement Distillation Framework for Improving Stock Trend Forecasting](https://arx"
},
{
"path": "examples/benchmarks/ADD/requirements.txt",
"chars": 62,
"preview": "numpy==1.21.0\npandas==1.1.2\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/ADD/workflow_config_add_Alpha360.yaml",
"chars": 2620,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/ALSTM/README.md",
"chars": 402,
"preview": "# ALSTM\r\n\r\n- ALSTM contains a temporal attentive aggregation layer based on normal LSTM.\r\n\r\n- Paper: A dual-stage attent"
},
{
"path": "examples/benchmarks/ALSTM/requirements.txt",
"chars": 62,
"preview": "numpy==1.21.0\npandas==1.1.2\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/ALSTM/workflow_config_alstm_Alpha158.yaml",
"chars": 2953,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/ALSTM/workflow_config_alstm_Alpha360.yaml",
"chars": 2521,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/CatBoost/README.md",
"chars": 343,
"preview": "# CatBoost\n* Code: [https://github.com/catboost/catboost](https://github.com/catboost/catboost)\n* Paper: CatBoost: unbia"
},
{
"path": "examples/benchmarks/CatBoost/requirements.txt",
"chars": 45,
"preview": "pandas==1.1.2\nnumpy==1.21.0\ncatboost==0.24.3\n"
},
{
"path": "examples/benchmarks/CatBoost/workflow_config_catboost_Alpha158.yaml",
"chars": 2070,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/CatBoost/workflow_config_catboost_Alpha158_csi500.yaml",
"chars": 2070,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/CatBoost/workflow_config_catboost_Alpha360.yaml",
"chars": 2279,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/CatBoost/workflow_config_catboost_Alpha360_csi500.yaml",
"chars": 2279,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/DoubleEnsemble/README.md",
"chars": 843,
"preview": "# DoubleEnsemble\n* DoubleEnsemble is an ensemble framework leveraging learning trajectory based sample reweighting and s"
},
{
"path": "examples/benchmarks/DoubleEnsemble/requirements.txt",
"chars": 45,
"preview": "pandas==1.1.2\r\nnumpy==1.21.0\r\nlightgbm==3.1.0"
},
{
"path": "examples/benchmarks/DoubleEnsemble/workflow_config_doubleensemble_Alpha158.yaml",
"chars": 2686,
"preview": "qlib_init:\r\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\r\n region: cn\r\nmarket: &market csi300\r\nbenchmark: &benchmark"
},
{
"path": "examples/benchmarks/DoubleEnsemble/workflow_config_doubleensemble_Alpha158_csi500.yaml",
"chars": 2664,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/DoubleEnsemble/workflow_config_doubleensemble_Alpha360.yaml",
"chars": 2905,
"preview": "qlib_init:\r\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\r\n region: cn\r\nmarket: &market csi300\r\nbenchmark: &benchmark"
},
{
"path": "examples/benchmarks/DoubleEnsemble/workflow_config_doubleensemble_Alpha360_csi500.yaml",
"chars": 2876,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/DoubleEnsemble/workflow_config_doubleensemble_early_stop_Alpha158.yaml",
"chars": 2727,
"preview": "qlib_init:\r\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\r\n region: cn\r\nmarket: &market csi300\r\nbenchmark: &benchmark"
},
{
"path": "examples/benchmarks/GATs/README.md",
"chars": 485,
"preview": "# GATs\n* Graph Attention Networks(GATs) leverage masked self-attentional layers on graph-structured data. The nodes in s"
},
{
"path": "examples/benchmarks/GATs/requirements.txt",
"chars": 62,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/GATs/workflow_config_gats_Alpha158.yaml",
"chars": 2963,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GATs/workflow_config_gats_Alpha360.yaml",
"chars": 2558,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GRU/README.md",
"chars": 174,
"preview": "# Gated Recurrent Unit (GRU)\n* Paper: [Learning Phrase Representations using RNN Encoder–Decoder for Statistical Machine"
},
{
"path": "examples/benchmarks/GRU/requirements.txt",
"chars": 62,
"preview": "numpy==1.21.0\npandas==1.1.2\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/GRU/workflow_config_gru_Alpha158.yaml",
"chars": 2923,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GRU/workflow_config_gru_Alpha360.yaml",
"chars": 2491,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GeneralPtNN/README.md",
"chars": 1067,
"preview": "\n\n# Introduction\n\nWhat is GeneralPtNN\n- Fix previous design that fail to support both Time-series and tabular data\n- Now"
},
{
"path": "examples/benchmarks/GeneralPtNN/workflow_config_gru.yaml",
"chars": 3078,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GeneralPtNN/workflow_config_gru2mlp.yaml",
"chars": 2890,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/GeneralPtNN/workflow_config_mlp.yaml",
"chars": 2768,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/HIST/README.md",
"chars": 293,
"preview": "# HIST\n* Code: [https://github.com/Wentao-Xu/HIST](https://github.com/Wentao-Xu/HIST)\n* Paper: [HIST: A Graph-based Fram"
},
{
"path": "examples/benchmarks/HIST/requirements.txt",
"chars": 61,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0"
},
{
"path": "examples/benchmarks/HIST/workflow_config_hist_Alpha360.yaml",
"chars": 2700,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/IGMTF/README.md",
"chars": 221,
"preview": "# IGMTF\n* Code: [https://github.com/Wentao-Xu/IGMTF](https://github.com/Wentao-Xu/IGMTF)\n* Paper: [IGMTF: An Instance-wi"
},
{
"path": "examples/benchmarks/IGMTF/requirements.txt",
"chars": 62,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/IGMTF/workflow_config_igmtf_Alpha360.yaml",
"chars": 2556,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/KRNN/README.md",
"chars": 406,
"preview": "# KRNN\n* Code: [https://github.com/microsoft/FOST/blob/main/fostool/model/krnn.py](https://github.com/microsoft/FOST/blo"
},
{
"path": "examples/benchmarks/KRNN/requirements.txt",
"chars": 28,
"preview": "numpy==1.23.4\npandas==1.5.2\n"
},
{
"path": "examples/benchmarks/KRNN/workflow_config_krnn_Alpha360.yaml",
"chars": 2523,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LSTM/README.md",
"chars": 174,
"preview": "# Long Short-Term Memory (LSTM)\n* Paper: [Long Short-Term Memory](https://direct.mit.edu/neco/article-abstract/9/8/1735/"
},
{
"path": "examples/benchmarks/LSTM/requirements.txt",
"chars": 62,
"preview": "numpy==1.21.0\npandas==1.1.2\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/LSTM/workflow_config_lstm_Alpha158.yaml",
"chars": 2924,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LSTM/workflow_config_lstm_Alpha360.yaml",
"chars": 2493,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/README.md",
"chars": 541,
"preview": "# LightGBM\n* Code: [https://github.com/microsoft/LightGBM](https://github.com/microsoft/LightGBM)\n* Paper: LightGBM: A H"
},
{
"path": "examples/benchmarks/LightGBM/features_resample_N.py",
"chars": 583,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\nimport pandas as pd\n\nfrom qlib.data.inst_pro"
},
{
"path": "examples/benchmarks/LightGBM/features_sample.py",
"chars": 623,
"preview": "import datetime\nimport pandas as pd\n\nfrom qlib.data.inst_processor import InstProcessor\n\n\nclass Resample1minProcessor(In"
},
{
"path": "examples/benchmarks/LightGBM/multi_freq_handler.py",
"chars": 7014,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\nimport pandas as pd\n\nfrom qlib.data.dataset."
},
{
"path": "examples/benchmarks/LightGBM/requirements.txt",
"chars": 37,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nlightgbm\n"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml",
"chars": 2080,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158_csi500.yaml",
"chars": 2074,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158_multi_freq.yaml",
"chars": 2393,
"preview": "qlib_init:\n provider_uri:\n day: \"~/.qlib/qlib_data/cn_data\"\n 1min: \"~/.qlib/qlib_data/cn_data_1min\"\n "
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha360.yaml",
"chars": 2292,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha360_csi500.yaml",
"chars": 2292,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_configurable_dataset.yaml",
"chars": 3131,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/LightGBM/workflow_config_lightgbm_multi_freq.yaml",
"chars": 2539,
"preview": "qlib_init:\n provider_uri:\n day: \"~/.qlib/qlib_data/cn_data\"\n 1min: \"~/.qlib/qlib_data/cn_data_1min\"\n "
},
{
"path": "examples/benchmarks/Linear/requirements.txt",
"chars": 49,
"preview": "numpy>=1.17.4\npandas>=1.0.1\nscikit-learn>=0.23.1\n"
},
{
"path": "examples/benchmarks/Linear/workflow_config_linear_Alpha158.yaml",
"chars": 2198,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Linear/workflow_config_linear_Alpha158_csi500.yaml",
"chars": 2198,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Linear/workflow_config_linear_Alpha158_multi_pass_bt.yaml",
"chars": 2255,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Localformer/README.md",
"chars": 14,
"preview": "# Localformer\n"
},
{
"path": "examples/benchmarks/Localformer/requirements.txt",
"chars": 42,
"preview": "numpy==1.21.0\r\npandas==1.1.2\r\ntorch==1.2.0"
},
{
"path": "examples/benchmarks/Localformer/workflow_config_localformer_Alpha158.yaml",
"chars": 2704,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Localformer/workflow_config_localformer_Alpha360.yaml",
"chars": 2229,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/MLP/README.md",
"chars": 31,
"preview": "# Multi-Layer Perceptron (MLP)\n"
},
{
"path": "examples/benchmarks/MLP/requirements.txt",
"chars": 62,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/MLP/workflow_config_mlp_Alpha158.yaml",
"chars": 2708,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/MLP/workflow_config_mlp_Alpha158_csi500.yaml",
"chars": 2708,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/MLP/workflow_config_mlp_Alpha360.yaml",
"chars": 2440,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/MLP/workflow_config_mlp_Alpha360_csi500.yaml",
"chars": 2440,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi500\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/README.md",
"chars": 16225,
"preview": "# Benchmarks Performance\nThis page lists a batch of methods designed for alpha seeking. Each method tries to give scores"
},
{
"path": "examples/benchmarks/SFM/README.md",
"chars": 479,
"preview": "# State-Frequency-Memory\n- State Frequency Memory (SFM) is a novel recurrent network that uses Discrete Fourier Transfor"
},
{
"path": "examples/benchmarks/SFM/requirements.txt",
"chars": 62,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/SFM/workflow_config_sfm_Alpha360.yaml",
"chars": 2575,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Sandwich/README.md",
"chars": 412,
"preview": "# Sandwich\n* Code: [https://github.com/microsoft/FOST/blob/main/fostool/model/sandwich.py](https://github.com/microsoft/"
},
{
"path": "examples/benchmarks/Sandwich/requirements.txt",
"chars": 28,
"preview": "numpy==1.23.4\npandas==1.5.2\n"
},
{
"path": "examples/benchmarks/Sandwich/workflow_config_sandwich_Alpha360.yaml",
"chars": 2587,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/TCN/README.md",
"chars": 222,
"preview": "# TCN\n* Code: [https://github.com/locuslab/TCN](https://github.com/locuslab/TCN)\n* Paper: [An Empirical Evaluation of Ge"
},
{
"path": "examples/benchmarks/TCN/requirements.txt",
"chars": 62,
"preview": "numpy==1.21.0\npandas==1.1.2\nscikit_learn==0.23.2\ntorch==1.7.0\n"
},
{
"path": "examples/benchmarks/TCN/workflow_config_tcn_Alpha158.yaml",
"chars": 2974,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/TCN/workflow_config_tcn_Alpha360.yaml",
"chars": 2544,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/TCTS/README.md",
"chars": 5594,
"preview": "# Temporally Correlated Task Scheduling for Sequence Learning\n### Background\nSequence learning has attracted much resear"
},
{
"path": "examples/benchmarks/TCTS/requirements.txt",
"chars": 61,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0"
},
{
"path": "examples/benchmarks/TCTS/workflow_config_tcts_Alpha360.yaml",
"chars": 2821,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/TFT/README.md",
"chars": 826,
"preview": "# Temporal Fusion Transformers Benchmark\r\n## Source\r\n**Reference**: Lim, Bryan, et al. \"Temporal fusion transformers for"
},
{
"path": "examples/benchmarks/TFT/data_formatters/__init__.py",
"chars": 621,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/data_formatters/base.py",
"chars": 7910,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/data_formatters/qlib_Alpha158.py",
"chars": 8466,
"preview": "# coding=utf-8\n# Copyright 2020 The Google Research Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"Li"
},
{
"path": "examples/benchmarks/TFT/expt_settings/__init__.py",
"chars": 621,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/expt_settings/configs.py",
"chars": 3380,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/libs/__init__.py",
"chars": 621,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/libs/hyperparam_opt.py",
"chars": 15323,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/libs/tft_model.py",
"chars": 48499,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/libs/utils.py",
"chars": 7165,
"preview": "# coding=utf-8\r\n# Copyright 2020 The Google Research Authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the "
},
{
"path": "examples/benchmarks/TFT/requirements.txt",
"chars": 39,
"preview": "tensorflow-gpu==1.15.0\r\npandas==1.1.0\r\n"
},
{
"path": "examples/benchmarks/TFT/tft.py",
"chars": 11011,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\nfrom pathlib import Path\nfrom typing import Un"
},
{
"path": "examples/benchmarks/TFT/workflow_config_tft_Alpha158.yaml",
"chars": 1800,
"preview": "sys:\n rel_path: .\nqlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenc"
},
{
"path": "examples/benchmarks/TRA/README.md",
"chars": 3982,
"preview": "# Learning Multiple Stock Trading Patterns with Temporal Routing Adaptor and Optimal Transport\n\nTemporal Routing Adaptor"
},
{
"path": "examples/benchmarks/TRA/configs/config_alstm.yaml",
"chars": 1346,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/configs/config_alstm_tra.yaml",
"chars": 1386,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/configs/config_alstm_tra_init.yaml",
"chars": 1354,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/configs/config_transformer.yaml",
"chars": 1359,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/configs/config_transformer_tra.yaml",
"chars": 1403,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/configs/config_transformer_tra_init.yaml",
"chars": 1367,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\ndata_loader_config: &data_loader_config\n class: St"
},
{
"path": "examples/benchmarks/TRA/data/README.md",
"chars": 96,
"preview": "Data Link: https://drive.google.com/drive/folders/1fMqZYSeLyrHiWmVzygeI4sw3vp5Gt8cY?usp=sharing\n"
},
{
"path": "examples/benchmarks/TRA/example.py",
"chars": 1207,
"preview": "import argparse\n\nimport qlib\nfrom ruamel.yaml import YAML\nfrom qlib.utils import init_instance_by_config\n\n\ndef main(seed"
},
{
"path": "examples/benchmarks/TRA/requirements.txt",
"chars": 70,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0\nseaborn\n"
},
{
"path": "examples/benchmarks/TRA/run.sh",
"chars": 807,
"preview": "#!/bin/bash\n\n# we used random seed(1 1000 2000 3000 4000 5000) in our experiments \n\n# Directly run from Qlib command `qr"
},
{
"path": "examples/benchmarks/TRA/src/dataset.py",
"chars": 8978,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\nimport copy\nimport torch\nimport numpy as np\nim"
},
{
"path": "examples/benchmarks/TRA/src/model.py",
"chars": 19366,
"preview": "# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n\nimport os\nimport copy\nimport math\nimport json\n"
},
{
"path": "examples/benchmarks/TRA/workflow_config_tra_Alpha158.yaml",
"chars": 3273,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\nmarket: &market csi300\nbenchmark: &benchmark SH0003"
},
{
"path": "examples/benchmarks/TRA/workflow_config_tra_Alpha158_full.yaml",
"chars": 2968,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\nmarket: &market csi300\nbenchmark: &benchmark SH0003"
},
{
"path": "examples/benchmarks/TRA/workflow_config_tra_Alpha360.yaml",
"chars": 2962,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\n\nmarket: &market csi300\nbenchmark: &benchmark SH0003"
},
{
"path": "examples/benchmarks/TabNet/README.md",
"chars": 199,
"preview": "# TabNet\n* Code: [https://github.com/dreamquark-ai/tabnet](https://github.com/dreamquark-ai/tabnet)\n* Paper: [TabNet: At"
},
{
"path": "examples/benchmarks/TabNet/requirements.txt",
"chars": 61,
"preview": "pandas==1.1.2\nnumpy==1.21.0\nscikit_learn==0.23.2\ntorch==1.7.0"
},
{
"path": "examples/benchmarks/TabNet/workflow_config_TabNet_Alpha158.yaml",
"chars": 2419,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/TabNet/workflow_config_TabNet_Alpha360.yaml",
"chars": 2419,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Transformer/README.md",
"chars": 242,
"preview": "# Transformer\n* Code: [https://github.com/tensorflow/tensor2tensor](https://github.com/tensorflow/tensor2tensor)\n* Paper"
},
{
"path": "examples/benchmarks/Transformer/requirements.txt",
"chars": 42,
"preview": "numpy==1.21.0\r\npandas==1.1.2\r\ntorch==1.2.0"
},
{
"path": "examples/benchmarks/Transformer/workflow_config_transformer_Alpha158.yaml",
"chars": 2694,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/Transformer/workflow_config_transformer_Alpha360.yaml",
"chars": 2285,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/XGBoost/README.md",
"chars": 241,
"preview": "# XGBoost\n* Code: [https://github.com/dmlc/xgboost](https://github.com/dmlc/xgboost)\n* Paper: XGBoost: A Scalable Tree B"
},
{
"path": "examples/benchmarks/XGBoost/requirements.txt",
"chars": 42,
"preview": "numpy==1.21.0\npandas==1.1.2\nxgboost==1.2.1"
},
{
"path": "examples/benchmarks/XGBoost/workflow_config_xgboost_Alpha158.yaml",
"chars": 2018,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
},
{
"path": "examples/benchmarks/XGBoost/workflow_config_xgboost_Alpha360.yaml",
"chars": 2227,
"preview": "qlib_init:\n provider_uri: \"~/.qlib/qlib_data/cn_data\"\n region: cn\nmarket: &market csi300\nbenchmark: &benchmark SH0"
}
]
// ... and 371 more files (download for full content)
About this extraction
This page contains the full source code of the microsoft/qlib GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 571 files (3.1 MB), approximately 845.0k tokens, and a symbol index with 4030 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.