Skip to content
All library documents

Qlib Alpha158 DNN Workflow for CSI 300 Portfolio Backtesting

Code Qlib

Summary

This configuration describes a Qlib workflow that trains a PyTorch deep neural network on Alpha158 features for CSI 300 stocks, using the Shanghai 300 index as its benchmark. It defines training, validation, and test periods, drops the VWAP feature, fills missing feature values for inference, and applies missing-data handling and label normalization during learning.

The portfolio simulation uses a TopkDropout strategy that targets 50 holdings and replaces five positions, with transaction costs, minimum fees, a price limit threshold, and closing prices specified. The model uses mean squared error with Adam and a defined learning rate, batch size, training steps, weight decay, and GPU setting. The configuration shows intended setup rather than results: it gives no reported returns, risk statistics, or evidence of out-of-sample performance. Its historical sample and assumptions also limit conclusions about current conditions or live trading.

Key ideas

  • The workflow trains a PyTorch DNN on Alpha158 features for CSI 300 instruments.
  • The data is divided into training, validation, and test segments, with fitting limited to the training period.
  • The portfolio strategy targets 50 holdings and rotates five positions at a time.
  • The backtest specifies transaction costs, minimum fees, a price threshold, and closing-price execution.
  • The configuration contains no performance results, so it cannot establish strategy effectiveness.

Tags

Full text
# workflow_config_mlp_Alpha158.yaml


```yaml
qlib_init:
    provider_uri: "~/.qlib/qlib_data/cn_data"
    region: cn
market: &market csi300
benchmark: &benchmark SH000300
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
    infer_processors: [
        {
            "class" : "DropCol", 
            "kwargs":{"col_list": ["VWAP0"]}
        },
        {
             "class" : "CSZFillna", 
             "kwargs":{"fields_group": "feature"}
        }
    ]
    learn_processors: [
        {
            "class" : "DropCol", 
            "kwargs":{"col_list": ["VWAP0"]}
        },
        {
            "class" : "DropnaProcessor", 
            "kwargs":{"fields_group": "feature"}
        },
        "DropnaLabel",
        {
            "class": "CSZScoreNorm", 
            "kwargs": {"fields_group": "label"}
        }
    ]
    process_type: "independent"

port_analysis_config: &port_analysis_config
    strategy:
        class: TopkDropoutStrategy
        module_path: qlib.contrib.strategy
        kwargs:
            signal: <PRED>
            topk: 50
            n_drop: 5
    backtest:
        start_time: 2017-01-01
        end_time: 2020-08-01
        account: 100000000
        benchmark: *benchmark
        exchange_kwargs:
            limit_threshold: 0.095
            deal_price: close
            open_cost: 0.0005
            close_cost: 0.0015
            min_cost: 5
task:
    model:
        class: DNNModelPytorch
        module_path: qlib.contrib.model.pytorch_nn
        kwargs:
            loss: mse
            lr: 0.002
            optimizer: adam
            max_steps: 8000
            batch_size: 8192
            GPU: 0
            weight_decay: 0.0002
            pt_model_kwargs:
              input_dim: 157
    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]
    record: 
        - class: SignalRecord
          module_path: qlib.workflow.record_temp
          kwargs: 
            model: <MODEL>
            dataset: <DATASET>
        - class: SigAnaRecord
          module_path: qlib.workflow.record_temp
          kwargs: 
            ana_long_short: False
            ann_scaler: 252
        - class: PortAnaRecord
          module_path: qlib.workflow.record_temp
          kwargs: 
            config: *port_analysis_config

```

Shown in full with attribution under the source's licence. Licence: MIT

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.