Wang's blog

其它 - 建立公式化alpha

Published on

简介

在量化交易实践中,设计能够解释并预测未来资产回报率的新因子对于策略的盈利能力是至关重要的。这些因子通常称为alpha因子或简称为alpha。公式化alpha,顾名思义,是指能够表示为公式或数学表达式的alpha。

例子

在Qlib中,用户可以方便地建立公式化alpha。例如,用户可以使用数据处理器建立MACD这一常用公式化alpha:

>> from qlib.data.dataset.loader import QlibDataLoader
>> MACD_EXP = '(EMA($close, 12) - EMA($close, 26))/$close - EMA((EMA($close, 12) - EMA($close, 26))/$close, 9)/$close'
>> fields = [MACD_EXP] # MACD
>> names = ['MACD']
>> labels = ['Ref($close, -2)/Ref($close, -1) - 1'] # 标签
>> 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.011547 -0.019672
           SH600004    0.002745 -0.014721
           SH600006    0.010133  0.002911
           SH600008   -0.001113  0.009818
           SH600009    0.025878 -0.017758
...                         ...       ...
2017-12-29 SZ300124    0.007306 -0.005074
           SZ300136   -0.013492  0.056352
           SZ300144   -0.000966  0.011853
           SZ300251    0.004383  0.021739
           SZ300315   -0.030557  0.012455