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

How to quickly realize a semi-automatic quantitative transaction tool in Go language

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article Xiaobian for you to introduce in detail "Go language how to quickly achieve a semi-automatic quantitative trading tool", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "Go language how to quickly achieve a semi-automatic quantitative trading tool" can help you solve your doubts.

The concept of intertemporal arbitrage

Intertemporal arbitrage is to establish an equal number of trading positions in different contract months of the same futures variety in the opposite direction by observing the fluctuation of the price difference of each futures contract for the purpose of earning the price difference. a mode of operation in which trading is terminated by hedging or delivery. When the market is positive, the price difference is negative, which is shown as rising water in the distant month, while in the reverse market, the price difference is positive, which is shown as rising water in recent months. Generally speaking, the spread (absolute value) consists of holding costs (or holding fees), that is, storage fees, insurance premiums and interest paid for owning or retaining a warehouse receipt or position.

Strategy design

The policy framework is as follows:

Function main () {while (true) {if (exchange.IO ("status")) {/ / determines the CTP protocol connection status. LogStatus (_ D (), "CTP connected!") / / during the opening time, the login connection is normal. } else {LogStatus (_ D (), "not connected to CTP!") / / not logged in to the transaction front machine. }}}

If the CTP protocol connection is normal, then we need to set up the contract and get the market price. After obtaining the market, we can use the "line drawing class library" encapsulated by the inventor's quantitative trading platform to draw the price difference.

Function main () {while (true) {if (exchange.IO ("status")) {/ / determines the CTP protocol connection status. Exchange.SetContractType ("rb2001") / / set far-month contract var tickerA = exchange.GetTicker () / / far-month contract market data exchange.SetContractType ("rb1910") / / set near-month contract var tickerB = exchange.GetTicker () / / recent-month contract market data Var diff = tickerA.Last-tickerB.Last $.PlotLine ("diff" Diff) LogStatus (_ D (), "CTP connected!") / / during the opening time, the login connection is normal. } else {LogStatus (_ D (), "not connected to CTP!") / / not logged in to the transaction front machine. }}}

Get the market data, calculate the price difference, and draw a record to simply reflect the recent fluctuation of the price difference.

Use the function $. PlotLine of the linework class library

Interactive part

You can add interactive controls to the policy directly on the policy editing page:

The GetCommand function is used in the policy code to capture the command sent to the robot after the above policy control is triggered.

After capturing the command, you can do different processing for different commands.

The trading code can use the encapsulated function of the Commodity Futures Trading Class Library. First, use var Q = $.NewTaskQueue () to generate the transaction control object Q (declared as a global variable).

Var cmd = GetCommand () if (cmd) {if (cmd = = "plusHedge") {q.pushTask (exchange, "rb2001", "sell", 1, function (task, ret) {Log (task.desc, ret) if (ret) {q.pushTask (exchange, "rb1910", "buy", 1,123, function (task, ret) {Log ("Q") Task.desc, ret, task.arg)})} else if (cmd = = "minusHedge") {q.pushTask (exchange, "rb2001", "buy", 1, function (task, ret) {Log (task.desc, ret) if (ret) {q.pushTask (exchange, "rb1910", "sell", 1,123) Function (task, ret) {Log ("Q", task.desc, ret, task.arg)}})} else if (cmd = = "coverPlus") {q.pushTask (exchange, "rb2001", "closesell", 1, function (task, ret) {Log (task.desc) Ret) if (ret) {q.pushTask (exchange, "rb1910", "closebuy", 1,123, function (task, ret) {Log ("Q", task.desc, ret, task.arg)}})} else if (cmd = = "coverMinus") {q.pushTask (exchange, "rb2001") "closebuy", 1, function (task, ret) {Log (task.desc, ret) if (ret) {q.pushTask (exchange, "rb1910", "closesell", 1,123, function (task, ret) {Log ("Q", task.desc, ret) Task.arg)})}})}} q.poll () read here This article "how to quickly realize a semi-automatic quantitative trading tool in Go language" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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: 275

*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

Internet Technology

Wechat

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

12
Report