퀀트 투자/Qlib
[Qlib] CH3. 플랫폼 구성-(1)Data
SKY-STONE
2024. 1. 9. 19:55
Contents
- Installation
- Framework Overview
- Main Component
- Data
- Train
- Backtest
- Examples
CH3. Main Components - (1)Data
Introduction
- Qlib Framework의 구성들은 Quant Research에 용이하도록 제작하는 것이 제일 중요한 제작 의도임
- 이에 Configuration 정의와 qrun 이라는 실행 명령어로만 쉽게 동작하게 UI에 많은 신경을 씀
- 이번 장에서는 기본적인 Configuration 정의 방법과 구성 방법을 알아보고자 함
Workflow: Workflow Management — QLib 0.9.3.99 documentation
Before getting into details, here is a complete example of qrun, which defines the workflow in typical Quant research. Below is a typical config file of qrun. After saving the config into configuration.yaml, users could start the workflow and test their id
qlib.readthedocs.io
1. Inititialization Section
provider_uri: "~/.qlib/qlib_data/cn_data"
region: cn
- provider_uri
- The URI of the Qlib data. For example, it could be the location where the data loaded by get_data.py are stored.
- region
- If region == “us”, Qlib will be initialized in US-stock mode.
- If region == “cn”, Qlib will be initialized in China-stock mode.
2. Data Section
data_handler_config: &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
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]
- data_handler_config: Data handler support user-customized processors to process data
- dataset: Dataset is responsible to prepare model-specific dataset from the processed data of Data Handler
3. Model Section
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
- model: model is designed to make the prediction score about stocks
4. Analysis Section
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
module_path: qlib.contrib.strategy.strategy
kwargs:
topk: 50
n_drop: 5
signal: <PRED>
backtest:
limit_threshold: 0.095
account: 100000000
benchmark: *benchmark
deal_price: close
open_cost: 0.0005
close_cost: 0.0015
min_cost: 5
record:
- class: SignalRecord
module_path: qlib.workflow.record_temp
kwargs: {}
- class: PortAnaRecord
module_path: qlib.workflow.record_temp
kwargs:
config: *port_analysis_config
- port_analysis_config
- strategy: Portfolio Strategy is designed to adopt different portfolio strategies, which means that users can adopt different algorithms to generate investment portfolios based on the prediction scores of the Forecast Model.
- backtest: After users specifying the models(forecasting signals) and strategies, running backtest will help users to check the performance of a custom model(forecasting signals)/strategy.
- record: Qlib contains an experiment management system named QlibRecorder, which is designed to help users handle experiment and analyse results in an efficient way