Skip to content
All library documents

Qlib Configuration for TCTS Alpha360 Stock Prediction and Top-K Backtesting

Code Qlib

Summary

This configuration describes a Qlib workflow for training a TCTS model on the CSI 300 universe using Alpha360 features. The data span 2008 to 2020, with training through 2014, validation over 2015–2016, and testing from 2017 to mid-2020. Feature processing applies robust z-score normalization and fills missing values; labels are cross-sectionally rank-normalized after missing labels are dropped. The model is set up to predict three forward-return labels, with mean squared error and Adam optimizers.

For portfolio analysis, the configuration uses a top-k dropout strategy that holds 50 names and allows five drops, with the Shanghai Composite 300 as benchmark. The backtest uses closing prices and specifies trading costs, a minimum fee, and a limit threshold. It also records signal analysis and portfolio analysis. This is an experimental setup rather than a report of findings: it contains no performance results, and the outcome depends on data quality, implementation details, and the assumptions encoded in the backtest.

Key ideas

  • The workflow trains a TCTS model on Alpha360 data for the CSI 300 universe.
  • Training, validation, and test periods are specified separately.
  • The model targets three forward-return labels and uses mean squared error.
  • Portfolio analysis applies a top-k dropout strategy with 50 holdings and five permitted drops.
  • The configuration includes transaction costs and closing-price execution assumptions but reports no results.

Tags

Full text
# workflow_config_tcts_Alpha360.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: RobustZScoreNorm
          kwargs:
              fields_group: feature
              clip_outlier: true
        - class: Fillna
          kwargs:
              fields_group: feature
    learn_processors:
        - class: DropnaLabel
        - class: CSRankNorm
          kwargs:
              fields_group: label
    label: ["Ref($close, -2) / Ref($close, -1) - 1", 
            "Ref($close, -3) / Ref($close, -1) - 1", 
            "Ref($close, -4) / Ref($close, -1) - 1"]
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: TCTS
        module_path: qlib.contrib.model.pytorch_tcts
        kwargs:
            d_feat: 6
            hidden_size: 64
            num_layers: 2
            dropout: 0.3
            n_epochs: 200
            early_stop: 20
            batch_size: 800
            metric: loss
            loss: mse
            GPU: 0
            fore_optimizer: adam
            weight_optimizer: adam
            output_dim: 3
            fore_lr: 2e-3
            weight_lr: 2e-3
            steps: 3
            target_label: 0
            lowest_valid_performance: 0.993
    dataset:
        class: DatasetH
        module_path: qlib.data.dataset
        kwargs:
            handler:
                class: Alpha360
                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.