Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分钟频数据回测问题 #1741

Open
hanson-young opened this issue Jan 25, 2024 · 7 comments
Open

分钟频数据回测问题 #1741

hanson-young opened this issue Jan 25, 2024 · 7 comments
Labels
question Further information is requested

Comments

@hanson-young
Copy link

❓ Questions and Help

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

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

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

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

@hanson-young hanson-young added the question Further information is requested label Jan 25, 2024
@hanson-young
Copy link
Author

还是没人回复吗?我自己实现了一个HighFreqTopkDropoutStragegy解决了这个问题......

@quant2008
Copy link

其实你可以得到预测结果文件后,拿到其他回测平台去回测,比如放到backtrader去回测,这样可以完全自己控制t0问题。qlib系列二教程里有怎样在backtrader中拿到qlib预测结果文件,执行定制回测策略的例子。

@shijie2016
Copy link

还是没人回复吗?我自己实现了一个HighFreqTopkDropoutStragegy解决了这个问题......

请问你可以分享你实现的HighFreqTopkDropoutStragegy吗?下面卖课的真的是。

@Tsuruko04
Copy link

How to get the transaction detail in your picture in non_highfreq mode?

@Imbernoulli
Copy link

To get the transaction details, you can also refer to #1655, where we discussed more detailed. In sort, change the yaml to this:

---
qlib_init:
  ...
task:
  model:
    ...
  dataset:
    ...
  record:
    - class: SignalRecord
      module_path: qlib.workflow.record_temp
      kwargs:
        ...
    - class: PortAnaRecord
      module_path: qlib.workflow.record_temp
      kwargs:
        config:
          executor:
            class: SimulatorExecutor
            module_path: qlib.backtest.executor
            kwargs:
              time_per_step: day
              generate_portfolio_metrics: True
              verbose: True
          strategy:
            ...
          backtest:
            ...

I add

executor: 
class: SimulatorExecutor
module_path: qlib.backtest.executor
kwargs: 
time_per_step: day 
generate_portfolio_metrics: True 
verbose: True

to port_analysis_config: &port_analysis_config and it works.

(It it not to the initial question)

@l0ngc
Copy link

l0ngc commented Mar 27, 2024

还是没人回复吗?我自己实现了一个HighFreqTopkDropoutStragegy解决了这个问题......

您好,请问您方便一下您写的这个策略学习一下吗?感觉逻辑像是添加一个$buyDate然后判断$buyDate需要和¥today不等于才能进行交易?

@hanson-young
Copy link
Author

@l0ngc 其实逻辑都差不多,就是对每一份买卖标注下日期

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants