반자동화 양적 거래 도구를 신속하게 구현합니다.

저자:선함, 2020-08-30 10:11:02, 업데이트: 2023-10-08 19:54:06

img

반자동화 양적 거래 도구를 신속하게 구현합니다.

재화 선물 거래에서, 임시 중재는 일반적인 거래 방법이다. 이 유형의 중재는 위험하지 않습니다. 스프레드의 일방적인 방향이 계속 확장되면 중재 지위는 부동 손실 상태에있을 것입니다. 그러나 중재 지위가 적절히 제어되는 한, 그것은 여전히 매우 운영되고 실행 가능합니다.

이 기사에서는, 우리는 완전히 자동화된 거래 전략을 구축하는 대신 다른 거래 전략으로 전환하려고 노력합니다.

개발 플랫폼은 FMZ 퀀트 플랫폼을 사용할 것입니다. 이 문서의 초점은 상호 작용 함수와 반 자동 전략을 구축하는 방법에 있습니다.

시간 간 중재는 매우 간단한 개념입니다.

시간 간 중재 개념

  • 위키백과에서 인용

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 퀀트 플랫폼 내장 라인 드로잉 라이브러리를 사용하여 차이를 그려 볼 수 있습니다.

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

관련

더 많은