microsoft / microsoft/qlib

分钟频数据回测问题

Open
#1,741 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

❓ Questions and Help

在实例examples/highfreq的yaml文件中没有回测部分的配置

我进行了简单的配置,用自己的因子数据进行训练,采用TopNDropout策略

回测出来发现无费收益跑赢了benchmark(沪深300 ),但如果算上手续费差异非常大,不应该如此离谱,然后对持仓进行了分析,发现它每分钟都会进行交易,前一分钟买入的股票,下一分钟可能就卖出了,这显然是不合理的,因为不符合A股的交易规则。如下图
image

我最终定位到qlib的持仓设计上 qlib\backtest\position.py::Position。对于A股来说,持仓需要考虑到三个概念,昨日持仓,总持仓,可卖持仓,但是qlib中仅仅只有一个amount市值。那么在回测时,就必然会出现把今天买入的持仓今日卖出,这是严格意义上的T0交易。
在Strategy和Executor、Exchange的实现上,也并没有发现阻止这种情况发生的代码。

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 with qlib/backtest/position.py::Position, then trace how Strategy, Executor, and Exchange update holdings during the examples/highfreq workflow. Verify the current handling of amount and transaction fees, and define the behavior needed for yesterday holdings, total holdings, and sellable holdings. Done means the backtest respects A-share T+1 rules and prevents a position bought today from being sold today.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
fintech-quant
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.