microsoft / microsoft/qlib

回测模块支持对资产进行卖空

Open
#1,963 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
48.7k
Forks
7.7k
PR merge metrics
No merged PRs in 30d

Description

🌟 Feature Description

目前的回测实现中,Postion类是不支持卖空的。在不持有股票的时候,无法发起卖单。
虽然代码中添加了 InfPostion类,接触了这个限制。但是各种update逻辑基本没有实现。

但是,在实际上的股票/期权等金融资产交易中,卖空是最常见的实现中性策略的手段之一。不知道为什么团队在早期实现回测模块的时候,只考虑到了买多这种情况。

Motivation

希望团队增加对卖空的支持,大大增加Qlib的实用性。
很多成熟的回测框架都支持,这里不再一一列举。

当然可以让每个用户都进行改造,只用Qlib来做模型的预测部分,不使用Qlib的回测。
但是这就意味着,用户只用数据和模型这边部分,从策略的实现(因为一般都跟回测/实盘交易引擎绑定),回测,结果分析都使用其他框架。
如果这样的话,Qlib的价值会大打折扣。

🌟 Feature Description
In the current backtesting implementation, the Postion class does not support short selling. When you do not hold a stock, you cannot place a sell order.
Although the code added the InfPostion class to lift this restriction, various update logics have not been implemented.
However, in actual stock/option and other financial asset trading, short selling is one of the most common means to achieve a neutral strategy. It is unknown why the team only considered the long position scenario when implementing the backtesting module in the early stage.
Motivation
We hope the team can add support for short selling and greatly enhance the实用性 of Qlib.
Many mature backtesting frameworks support this, and we will not list them one by one here.
Of course, we can ask each user to make transformations and only use Qlib for model prediction. But this means that users only use the data and model parts of Qlib, and use other frameworks for strategy implementation (as it is generally bound to the backtesting and real trading engine), backtesting and result analysis. If this is the case, the value of Qlib will be greatly reduced.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Position and InfPosition classes in the backtesting implementation and read their existing update logic. Trace how sell orders are handled when no long position exists, then define the required short-position behavior and add coverage for the relevant backtesting flows. Done means short selling works consistently across position updates and order execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
fintech-quant
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.