.. _report: ======================================= 分析:评估与结果分析 ======================================= 简介 ============ ``Analysis`` 模块旨在展示 ``日内交易`` 的图形化报告,帮助用户直观评估和分析投资组合。以下是可查看的部分图表: - analysis_position - report_graph - score_ic_graph - cumulative_return_graph - risk_analysis_graph - rank_label_graph - analysis_model - model_performance_graph Qlib 中所有累计利润指标(如收益率、最大回撤)均通过累加方式计算。 这避免了指标或图表随时间呈指数级扭曲的情况。 图形化报告 ================= 用户可运行以下代码获取所有支持的报告。 .. code-block:: python >> import qlib.contrib.report as qcr >> print(qcr.GRAPH_NAME_LIST) ['analysis_position.report_graph', 'analysis_position.score_ic_graph', 'analysis_position.cumulative_return_graph', 'analysis_position.risk_analysis_graph', 'analysis_position.rank_label_graph', 'analysis_model.model_performance_graph'] .. note:: 更多细节请参考函数文档:类似于 ``help(qcr.analysis_position.report_graph)`` 使用与示例 =============== `analysis_position.report` 的使用方法 ----------------------------------- API ~~~ .. automodule:: qlib.contrib.report.analysis_position.report :members: :noindex: 图形化结果 ~~~~~~~~~~~~~~~~ .. note:: - X轴: 交易日 - Y轴: - `cum bench` 基准组合的累计收益序列 - `cum return wo cost` 无交易成本的组合累计收益序列 - `cum return w cost` 含交易成本的组合累计收益序列 - `return wo mdd` 无成本累计收益的最大回撤序列 - `return w cost mdd`: 含成本累计收益的最大回撤序列 - `cum ex return wo cost` 相比基准的无成本组合 `CAR` (累计超额收益) 序列 - `cum ex return w cost` 相比基准的含成本组合 `CAR` (累计超额收益) 序列 - `turnover` 换手率序列 - `cum ex return wo cost mdd` 无成本 `CAR` (累计超额收益) 的回撤序列 - `cum ex return w cost mdd` 含成本 `CAR` (累计超额收益) 的回撤序列 - 上方阴影部分: 对应 `cum return wo cost` 的最大回撤 - 下方阴影部分: 对应 `cum ex return wo cost` 的最大回撤 .. image:: ../_static/img/analysis/report.png `analysis_position.score_ic` 的使用方法 ------------------------------------- API ~~~ .. automodule:: qlib.contrib.report.analysis_position.score_ic :members: :noindex: 图形化结果 ~~~~~~~~~~~~~~~~ .. note:: - X轴: 交易日 - Y轴: - `ic` `标签`与`预测分数`之间的`皮尔逊相关系数`序列。 在上例中,`标签`计算公式为 `Ref($close, -2)/Ref($close, -1)-1`。更多细节请参阅 `数据特征 `_。 - `rank_ic` `标签`与`预测分数`之间的`斯皮尔曼等级相关系数`序列。 .. image:: ../_static/img/analysis/score_ic.png .. `analysis_position.cumulative_return` 的使用方法 .. ---------------------------------------------- .. .. API .. ~~~~~~~~~~~~~~~~ .. .. .. automodule:: qlib.contrib.report.analysis_position.cumulative_return .. :members: .. .. 图形化结果 .. ~~~~~~~~~~~~~~~~~ .. .. .. note:: .. .. - X轴: 交易日 .. - Y轴: .. - Y轴上方: `(((Ref($close, -1)/$close - 1) * weight).sum() / weight.sum()).cumsum()` .. - Y轴下方: 日权重总和 .. - 在**卖出**图表中,`y < 0`表示盈利;其他情况下,`y > 0`表示盈利。 .. - 在 **buy_minus_sell** 图表中,底部 **weight** 图表的 **y** 值为 `buy_weight + sell_weight`。 .. - 在每个图表中,右侧直方图中的 **红线** 表示平均值。 .. .. .. image:: ../_static/img/analysis/cumulative_return_buy.png .. .. .. image:: ../_static/img/analysis/cumulative_return_sell.png .. .. .. image:: ../_static/img/analysis/cumulative_return_buy_minus_sell.png .. .. .. image:: ../_static/img/analysis/cumulative_return_hold.png `analysis_position.risk_analysis` 的使用方法 ------------------------------------------ API ~~~ .. automodule:: qlib.contrib.report.analysis_position.risk_analysis :members: :noindex: 图形化结果 ~~~~~~~~~~~~~~~~ .. note:: - 通用图形 - `std` - `excess_return_without_cost` 无成本情况下 `CAR` (累计异常收益) 的 `标准差`。 - `excess_return_with_cost` 含成本情况下 `CAR` (累计异常收益) 的 `标准差`。 - `annualized_return` - `excess_return_without_cost` 无成本情况下 `CAR` (累计异常收益) 的 `年化率`。 - `excess_return_with_cost` 含成本情况下 `CAR` (累计异常收益) 的 `年化率`。 - `information_ratio` - `excess_return_without_cost` 无成本情况下的 `信息比率`。 - `excess_return_with_cost` 含成本情况下的 `信息比率`。 了解更多关于 `信息比率` 的信息,请参阅 `信息比率 – IR `_。 - `max_drawdown` - `excess_return_without_cost` 无成本情况下 `CAR` (累计异常收益) 的 `最大回撤`。 - `excess_return_with_cost` 含成本情况下 `CAR` (累计异常收益) 的 `最大回撤`。 .. image:: ../_static/img/analysisrisk_analysis_bar.png :align: center .. note:: - 年化收益/最大回撤/信息比率/标准差 图表 - X轴:按月份分组的交易日 - Y轴: - 年化收益图表 - `excess_return_without_cost_annualized_return` 无成本的月度`CAR`(累计超额收益)的`年化收益率`序列 - `excess_return_with_cost_annualized_return` 包含成本的月度`CAR`(累计超额收益)的`年化收益率`序列 - 最大回撤图表 - `excess_return_without_cost_max_drawdown` 无成本的月度`CAR`(累计超额收益)的`最大回撤`序列 - `excess_return_with_cost_max_drawdown` 包含成本的月度`CAR`(累计超额收益)的`最大回撤`序列 - 信息比率图表 - `excess_return_without_cost_information_ratio` 无成本的月度`CAR`(累计超额收益)的`信息比率`序列 - `excess_return_with_cost_information_ratio` 包含成本的月度`CAR`(累计超额收益)的`信息比率`序列 - 标准差图表 - `excess_return_without_cost_max_drawdown` 无成本的月度`CAR`(累计超额收益)的`标准差`序列 - `excess_return_with_cost_max_drawdown` 包含成本的月度`CAR`(累计超额收益)的`标准差`序列 .. image:: ../_static/img/analysis/risk_analysis_annualized_return.png :align: center .. image:: ../_static/img/analysis/risk_analysis_max_drawdown.png :align: center .. image:: ../_static/img/analysis/risk_analysis_information_ratio.png :align: center .. image:: ../_static/img/analysis/risk_analysis_std.png :align: center .. .. `analysis_position.rank_label` 的使用方法 .. --------------------------------------- .. .. API .. ~~~ .. .. .. automodule:: qlib.contrib.report.analysis_position.rank_label .. :members: .. .. .. 图形化结果 .. ~~~~~~~~~~~~~~~~ .. .. .. note:: .. .. - 持仓/卖出/买入图表: .. - X轴: 交易日 .. - Y轴: .. 交易日内被持仓/卖出/买入股票的平均 `ranking ratio` 的 `label` 值。 .. .. 在上述示例中,`label` 被定义为 `Ref($close, -1)/$close - 1`。`ranking ratio` 可按如下方式定义。 .. .. math:: .. .. ranking\ ratio = \frac{Ascending\ Ranking\ of\ label}{Number\ of\ Stocks\ in\ the\ Portfolio} .. .. .. image:: ../_static/img/analysis/rank_label_hold.png .. :align: center .. .. .. image:: ../_static/img/analysis/rank_label_buy.png .. :align: center .. .. .. image:: ../_static/img/analysis/rank_label_sell.png .. :align: center .. .. `analysis_model.analysis_model_performance` 的使用方法 ---------------------------------------------------- API ~~~ .. automodule:: qlib.contrib.report.analysis_model.analysis_model_performance :members: :noindex: 图形化结果 ~~~~~~~~~~~~~~~~~ .. note:: - 累计收益图形 - `Group1`: 标签 (`ranking ratio` <= 20%) 股票组的 `Cumulative Return` 序列 - `Group2`: 标签 (20% < `ranking ratio` <= 40%) 股票组的 `Cumulative Return` 序列 - `Group3`: 标签 (40% < `ranking ratio` <= 60%) 股票组的 `Cumulative Return` 序列 - `Group4`: 标签 (60% < `ranking ratio` <= 80%) 股票组的 `Cumulative Return` 序列 - `Group5`: 标签 (80% < `ranking ratio`) 股票组的 `Cumulative Return` 序列 - `long-short`: `Group1` 和 `Group5` 的 `Cumulative Return` 差异序列 - `long-average` `Group1` 与所有股票平均 `Cumulative Return` 的差异序列 `ranking ratio` 的计算公式如下 .. math:: ranking\ ratio = \frac{Ascending\ Ranking\ of\ label}{Number\ of\ Stocks\ in\ the\ Portfolio} .. image:: ../_static/img/analysis/analysis_model_cumulative_return.png :align: center .. note:: - 多空/多头-平均 每个交易日多空/多头-平均收益的分布情况 .. image:: ../_static/img/analysis/analysis_model_long_short.png :align: center .. TODO: 向小杨询问详情 .. note:: - 信息系数 - 投资组合中股票`标签`与`预测分数`之间的`皮尔逊相关系数`序列。 - 该图表报告可用于评估`预测分数`。 .. image:: ../_static/img/analysis/analysis_model_IC.png :align: center .. note:: - 月度IC 月度平均的 `信息系数` .. image:: ../_static/img/analysis/analysis_model_monthly_IC.png :align: center .. note:: - IC 每个交易日的 `信息系数` 分布。 - IC正态分布Q-Q图 `分位数-分位数图` 用于展示每个交易日 `信息系数` 的正态分布情况。 .. image:: ../_static/img/analysis/analysis_model_NDQ.png :align: center .. note:: - 自相关性 - 投资组合中股票在每个交易日的最新`预测分数`与`滞后`天的`预测分数`之间的`皮尔逊相关系数`序列。 - 该图形报告可用于估算换手率。 .. image:: ../_static/img/analysis/analysis_model_auto_correlation.png :align: center