和顺 / 衡律 返回所属 Agent
10.7

因子中性化与投影条件

原能力

按规定执行中性化及投影,处理未知分类、零尺度和秩不足。(合同附件 R7 10.7)

首选项目

CVXPY(Apache-2.0)。 CVXPY

接入说明

CVXPY 表达明确的投影约束。Qlib 标准化是相邻对照,权重中性化和退化分支需按 R7 实现。

匹配范围

横截面候选变换和投影约束基元。

源码

CVXPY · def quad_form(

cvxpy/atoms/quad_form.py · 290–303 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
def quad_form(x, P, assume_PSD: bool = False) -> Expression:
    """Alias for :math:`x^T P x`.

    Parameters
    ----------
    x : vector argument.
    P : matrix argument.
    assume_PSD : P is assumed to be PSD without checking.

    Notes
    -----
    When ``P`` is a ``Parameter`` declared PSD or NSD and the solver supports
    quadratic objectives, ``quad_form(x, P)`` can participate in a DPP solve,
    so repeated solves can reuse cached compilation data.
  • Copyright 2013 Steven Diamond, 2017 Robin Verschueren

Qlib · class CSZScoreNorm

qlib/data/dataset/processor.py · 300–313 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
class CSZScoreNorm(Processor):
    """Cross Sectional ZScore Normalization"""

    def __init__(self, fields_group=None, method="zscore"):
        self.fields_group = fields_group
        if method == "zscore":
            self.zscore_func = zscore
        elif method == "robust":
            self.zscore_func = robust_zscore
        else:
            raise NotImplementedError(f"This type of input is not supported")

    def __call__(self, df):
        # try not modify original dataframe
  • # Copyright (c) Microsoft Corporation.

实现与验收要点

中性化原矩阵、可用列、秩亏、残差与条件。