半自動量的な取引ツールを迅速に導入する

作者: リン・ハーン優しさ, 作成日:2020-08-30 10:11:02, 更新日:2023-10-08 19:54:06

img

半自動量的な取引ツールを迅速に導入する

商品先物取引では,間間仲介は一般的な取引方法である.この種の仲介はリスクフリーではない.一方的なスプレッドの方向性が拡大し続けると,仲介ポジションは浮動損失状態になる.しかし,仲介ポジションが適切に制御されている限り,それは依然として非常に運用可能であり実行可能である.

この記事では,完全に自動化された取引戦略を構築する代わりに,他の取引戦略に切り替えるように試みます. 商品先物取引における間期間仲介を容易にするために,インタラクティブな半自動量的な取引ツールを実現しました.

開発プラットフォームは,FMZ Quantプラットフォームを使用します.この記事の焦点は,インタラクティブな機能を持つ半自動戦略を構築する方法です.

インターテンポラル・アービタージは とてもシンプルな概念です

インターテンポラル・アービタージの概念

  • ウィキペディアからの引用

In economics and finance, arbitrage is the practice of taking advantage of a price difference between two or more markets: striking a combination of matching deals that capitalize upon the imbalance, the profit being the difference between the market prices at which the unit is traded. When used by academics, an arbitrage is a transaction that involves no negative cash flow at any probabilistic or temporal state and a positive cash flow in at least one state; in simple terms, it is the possibility of a risk-free profit after transaction costs. For example, an arbitrage opportunity is present when there is the opportunity to instantaneously buy something for a low price and sell it for a higher price.

戦略設計

戦略の枠組みは以下のとおりです

Function main(){
     While(true){
         If(exchange.IO("status")){ // Determine the connection status of the CTP protocol.
             LogStatus(_D(), "Already connected to CTP !") // Market Opening time, login connection is normal.
         } else {
             LogStatus(_D(), "CTP not connected!") // Not logged in to the trading front end.
         }
     }
}

CTP プロトコルが正しく接続されている場合,取引契約を設定し,市場引金を取得する必要があります.引金を取得した後, FMZ Quant プラットフォームの組み込み line drawing ライブラリを使用して差を引くことができます.

Function main(){
     While(true){
         If(exchange.IO("status")){ // Determine the connection status of the CTP protocol.
             exchange.SetContractType("rb2001") // Set the far month contract
             Var tickerA = exchange.GetTicker() // far-month contract quote data
            
             exchange.SetContractType("rb1910") // Set the near month contract
             Var tickerB = exchange.GetTicker() // near-month contract quote data
            
             Var diff = tickerA.Last - tickerB.Last
             $.PlotLine("diff", diff)

             LogStatus(_D(), "Already connected to CTP !") // Market Opening time, login connection is normal.
         } else {
             LogStatus(_D(), "CTP not connected!") // Not logged in to the trading front end.
         }
     }
}

価格の差の最近の変動を反映させてください 価格の差の最近の変動を反映させてください 線図書室の関数を使用する$.PlotLine

img

インタラクティブな部分

戦略編集ページでは,戦略に直接インタラクティブなコントロールを追加できます.

img

この関数を使うGetCommand上記の戦略制御が起動した後 ロボットに送られたコマンドを捕捉するために 戦略コードに

コマンドがキャプチャされた後,異なるコマンドは異なる方法で処理できます.

商品先物取引クラスライブラリの関数を使用してパッケージ化できます.var q = $.NewTaskQueue()トランザクション制御オブジェクトを生成するq(総変数として宣言される)

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()

関連性

もっと