Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the reasons and solutions for not stopping hanging orders after VNPY restart?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you the reasons for not stopping hanging orders after VNPY restart and what is the solution. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Previously, in this link, it was mentioned that after vnpy restart, such as starting before opening, even if the conditions for hanging orders are met, there are no problems with hanging orders, which gives a more troublesome method.

Later, when I studied the code, I found that the reason should be:

The program initializes playback data with onInit (self), but when self.trading is false, no stop order will be issued; when onStart is started, there will be no playback start, and there will be no hanging order, so the K line does not stop at the first time of restart.

As the historical backtest is a continuous K-line, this makes a big difference between the backtest and the real offer.

Before the link solution is more complex, the simple solution is to play back the last bar in the onStart to run, at this time the self.trading is True, allowing hanging orders.

1. Modify the onInit (self) of the policy. Playback does not include the last bar.

Def onInit (self): "" initialization policy (must be inherited by the user) "" self.writeCtaLog (uplink% s policy initialization'% self.name) # loads historical data, and initializes the policy value initData = self.loadBar (self.initDays) for bar in initData [:-1]: self.onBar (bar) self.putEvent () by playback calculation

two。 Add the last bar playback to onStart

Def onStart (self): "" launch policy (must be inherited by the user) "" initData = self.loadBar (1) bar = initData [- 1] self.onBar (bar) self.writeCtaLog (ugg% s policy launch'% self.name) self.putEvent () the above is the reason why VNPY did not stop hanging orders after restart and what is the solution? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report