Skip to content
All library documents

Qlib Localformer Alpha158 Workflow for CSI 300 Forecasting

Code Qlib

Summary

This configuration defines a Qlib equity forecasting workflow using the CSI 300 universe and the Shanghai CSI 300 index as benchmark. It sets a data window from 2008 through 2020, with training through 2014, validation over 2015–2016, and testing over 2017–2020. The dataset uses Alpha158 features, a 20-step sequence, and a forward close-price return label spanning the next two sessions relative to the next session.

The feature pipeline filters a specified subset of Alpha158 fields, applies robust cross-sectional normalization with outlier clipping, and fills missing values; labels are filtered and cross-sectionally rank-normalized. A Localformer model is specified, with signal analysis and portfolio backtesting records. The portfolio strategy selects the top 50 names and drops five each rebalance, with transaction costs and a price limit configured. This is an experiment recipe, not a report of results: it provides no metrics, and its findings would depend on data quality, model implementation, rebalancing assumptions, and trading costs.

Key ideas

  • The workflow trains a Localformer model on CSI 300 stocks using Alpha158 features.
  • The target is a short-horizon forward close-price return.
  • Feature preprocessing includes robust normalization, outlier clipping, and missing-value filling.
  • The portfolio simulation holds up to 50 top-ranked stocks and drops five positions at a time.
  • The configuration specifies a test period and trading assumptions but reports no performance results.

Tags

Full text
# workflow_config_localformer_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: FilterCol
          kwargs:
              fields_group: feature
              col_list: ["RESI5", "WVMA5", "RSQR5", "KLEN", "RSQR10", "CORR5", "CORD5", "CORR10", 
                            "ROC60", "RESI10", "VSTD5", "RSQR60", "CORR60", "WVMA60", "STD5", 
                            "RSQR20", "CORD60", "CORD10", "CORR20", "KLOW"
                        ]
        - 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"] 

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: LocalformerModel
        module_path: qlib.contrib.model.pytorch_localformer_ts
        kwargs:
            seed: 0
            n_jobs: 20
    dataset:
        class: TSDatasetH
        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]
            step_len: 20
    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.