연구 환경에서의 돈치안 채널 전략 분석

저자:리디아, 창작: 2022-12-26 09:19:00, 업데이트: 2023-09-20 10:43:17

img

연구 환경에서의 돈치안 채널 전략 분석

전략 도입

많은 거래 전략들 중에서, 돈치안 채널 전략은 가장 고전적인 돌파구 전략 중 하나가 되어야 한다. 1970년 초에 이미 유명했다. 그 당시, 외국 회사가 주류 프로그램 거래 전략에 대한 시뮬레이션 테스트와 연구를 실시했다. 결과는 돈치안 채널 전략이 모든 전략 테스트에서 가장 성공적이었다는 것을 보여주었다.

나중에, 무역 역사상 가장 유명한 거북 트레이더 훈련은 미국에서 이루어졌으며, 큰 성공을 거두었습니다. 그 당시, 거북의 거래 방법은 기밀이었지만, 10 년 이상 후에, 거북 거래 규칙이 대중에게 공개되었으며, 사람들은 거북이 치안 채널 전략의 개선 된 버전을 사용한다는 것을 발견했습니다.

돌파구 거래 전략은 상대적으로 부드러운 트렌드를 가진 거래 품종에 적합합니다. 가장 일반적인 돌파구 거래 방법은 특정 거래 지점을 판단하기 위해 가격, 지원 및 저항 사이의 상대적 위치 관계를 사용하는 것입니다. 이 문서의 돈치안 채널 전략도이 원칙에 기반합니다.

치안 채널 전략 규칙

돈치안 채널은 트렌드 지표이며, 그 외관과 신호는 볼링거 밴드 지표와 다소 유사합니다. 그러나 돈치안 가격 채널은 특정 기간 내 가장 높은 가격과 가장 낮은 가격에 따라 구성됩니다. 예를 들어, 최신 50 K 라인의 가장 높은 가격의 최대 값은 상위 트랙을 형성하기 위해 계산됩니다. 최신 50 K 라인의 최저 가격의 최소 값을 계산하여 하위 트랙을 형성합니다.

img

위 그림에서 보듯이, 이 지표는 다른 색상의 세 개의 곡선으로 구성되어 있습니다. 기본적으로, 20 기간 내의 가장 높고 가장 낮은 가격은 시장 가격의 변동성을 보여주기 위해 사용됩니다. 채널이 좁으면 시장 변동성이 작다는 것을 의미합니다. 반대로 채널이 넓으면 시장 변동성이 크다는 것을 의미합니다.

가격이 상위 트랙 이상으로 상승하면 구매 신호입니다. 반대로 가격이 하위 트랙 아래로 떨어지면 판매 신호입니다. 상위 및 하위 트랙이 가장 높고 가장 낮은 가격으로 계산되기 때문에 일반적으로 가격은 드물게 상위 및 하위 채널 라인을 동시에 상승 및 하락합니다. 대부분의 경우 가격은 상위 또는 하위 트랙을 따라 일방적으로 또는 상위 및 하위 트랙 사이에 움직입니다.

전략 논리

돈치안 채널을 사용하는 방법은 여러 가지가 있으며, 단독으로 사용하거나 다른 지표와 결합하여 사용할 수 있습니다. 이 강의에서는 가장 간단한 방법을 사용하겠습니다. 즉, 가격이 아래에서 위로 상단 트랙을 뚫고, 즉 압력선 위에있을 때, 많은 당사자의 힘이 증가하고 있다고 믿고, 상승 시장의 파도가 형성되어, 구매 오픈 포지션 신호가 생성되었습니다. 가격이 위에서 아래로 하단 트랙 아래로 떨어지면, 즉 지원 라인 아래로 떨어지면, 짧은 포지션 쪽이 강화되고, 하락 트렌드 파도가 형성되어, 판매 오픈 포지션 신호가 생성되었습니다.

만약 가격이 포지션을 오픈하기 위해 구매한 후 돈치안 채널의 중간 트랙으로 다시 떨어지면, 우리는 멀티파티 파워가 약화되고, 또는 쇼트 포지션 파티 파워가 강화되고, 판매 및 포지션 종료 신호가 생성됩니다.

구매 및 판매 조건

  • 롱 오프닝 포지션: 포지션이 존재하지 않고 닫기 가격이 상위 트랙보다 높으면.
  • 코트 오프닝 포지션: 포지션이 없는 경우, 그리고 종료 가격은 하위 트랙보다 낮습니다.
  • 긴 포지션 폐쇄: 당신이 긴 포지션을 보유하고 있고 닫기 가격은 중간 트랙보다 낮다면.
  • 마감 포지션: 마감 가격이 중간 트래크보다 높을 때 마감 포지션을 보유합니다.

전략 코드 실행

다음으로, 우리는 FMZ 퀀트 플랫폼의 연구 환경에서 이 전략을 하나씩 이해합니다.

아래와 같이 FMZ Quant 플랫폼의 연구 환경을 입력합니다.

img

파이썬 버전.ipynb에서 돈치안 채널 전략 [1]에서:

from fmz import *
task = VCtx('''backtest
start: 2019-08-01 09:00:00
end: 2019-10-10 15:00:00
period: 5m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
''')
# Create a Backtesting Environment
# The example format of the backtest information in red above can be obtained by clicking "Save settings" on the strategy edting page of the FMZ Quant platform.

[2]에서:

# First, we need to get the position information, and we define a mp() function to do this.

def mp():
    positions = exchange.GetPosition() # Get position array
    if len(positions) == 0: # If the length of the position array is 0
        return 0 # Prove a short position, return 0
    for i in range(len(positions)): # Iterate through the positions array
        if (positions[i]['Type'] == PD_LONG) or (positions[i]['Type'] == PD_LONG_YD):
            return 1 # If there are long position orders, return 1
        elif (positions[i]['Type'] == PD_SHORT) or (positions[i]['Type'] == PD_SHORT_YD):
            return -1 # If there are short position orders, return -1
        
    print(positions)
    
mp() # Next, we execute this function to get the position information, and we can see that the result is 0, which means that the current position is short.

아웃[2]:0

[3]에서:

# Let's start testing this strategy using the current main rebar contract as an example.

exchange.SetContractType("rb888") # Set the variety code, the main contract is the contract code followed by the number 888.

아웃[3]: {통합형: 0 CreateDate: 0, 배포월: 9, 수급 연간: 0, 결제일: 0, 교환 ID: SHFE, ExchangeInstID: rb888, 만료일: 0 인스트라이프페이지: 49, 기기 ID: rb888, 기기명: rb 연속성, 이거래: 1, 롱마진비율: 0.06, 최대 제한 주문량: 500, 최대변경알고리즘: 49, 마크스마켓 오더 볼륨: 30, 최소한 주문량: 1, MinMarketOrderVolume: 1, OpenDate: 0 옵션 타입: 48, 직장 날짜 타입: 49, 직업 유형: 50, PriceTick: 1, 제품급: 49, 프로덕트 아이디: rb, 코트 마진 비율: 0.06 제품 시작 날짜: 0, 스트라이크 프라이스: 0, 그라운드인스트리드: rb, 아래의 복수: 1, VolumeMultiple: 10}

다음으로, 우리는 K-라인 배열을 얻습니다. 전략적 논리에 따르면 시장이 일정 기간 동안 실행되고 논리적 판단을 내릴 필요가 있기 때문에 전략적 논리가 시장에 더 잘 적응 할 수 있습니다. 여기서 우리는 일시적으로 50 K 라인을 시작 요구 사항으로 취할 것입니다. FMZ Quant의 K-라인 정보는 가장 높은 가격, 가장 낮은 가격, 개척 가격, 폐쇄 가격, 거래량 및 기타 정보를 포함하는 배열의 형태로 저장됩니다. 이 부분의 내용에 대해서는 FMZ Quant 플랫폼의 공식 API 문서를 참조하십시오.https://www.fmz.com/api

[4]:

# Next we define a variable to store the K-line array.

records = exchange.GetRecords() # Get the K-line array

[5]에서:

# According to the strategy logic description, we use the closing price as the price to open a position, so we need to calculate the closing price of the latest K-line.

close = records[len(records) - 1].Close # Get the latest K-line closing price
close

외출[5]: 3846.0

그 다음, 우리는 50K 라인의 최상위 가격의 최대 값과 최저 가격의 최소 값을 계산해야 합니다.

[6]에서:

upper = TA.Highest(records, 50, 'High') # Get the maximum value of the 50-period maximum price
upper

외출[6]: 3903.0

[7]에서:

lower = TA.Lowest(records, 50, 'Low') # Get the minimum value of the 50-period minimum price
lower

아웃[7]: 3856.0

다음으로 이 채널의 상부와 하부 트랙의 평균 값을 계산해야 합니다.

[8]에서:

middle = (upper + lower) / 2 # Calculate the average value of the upper and lower tracks.
middle

아웃[8]: 3879.5

위에, 우리는 이 전략에 필요한 모든 계산을 완료했다. 다음, 우리는 논리적으로 개척 조건을 판단하기 시작 하 고 논리적인 판단의 결과에 따라 실제 개척 위치 동작을 수행 합니다. 여기서 우리는 FMZ 양자 플랫폼의 국내 재화 선물 템플릿을 사용 해야 합니다. 현재 연구 환경이 이 템플릿을 지원 할 수 없기 때문에, 우리는 일시적으로 작성할 것입니다, 하지만 작업은 오류를 보고, 실제 코딩을 위해 FMZ 양자 플랫폼 전략 작성 페이지에, 이 템플릿을 아무 문제 없이 수입, 템플릿 주소는:https://www.fmz.com/strategy/24288. FMZ 퀀트 플랫폼 전략 편집 페이지에서 코드를 작성할 때, 먼저 이 템플릿을 자신의 전략 라이브러리에 복사하고,

[ ]에서:

obj = ext.NewPositionManager() # When using the FMZ Quant trading class library, errors will be reported at runtime, which can be ignored. Now it is the research environment,
                               # This problem does not occur during the actual coding process, and the following is the same without further comment.

다음 단계는 전략의 논리를 결정하고 논리에 따라 포지션을 열고 닫는 것입니다.

[ ]에서:

if positions > 0 and close < middle: # If you hold a long position order and the closing price falls below the middle track
            obj.CoverAll() # Close all positions
        if positions < 0 and close > middle: # If you hold a short position order and the closing price rises above the middle track
            obj.CoverAll() # Close all positions
        if positions == 0: # If it's a short position
            if close > upper: # If the closing price rises above the upper track
                obj.OpenLong("rb888", 1) # Buy opening positions
            elif close < lower: # If the closing price falls below the lower track
                obj.OpenShort("rb888", 1) # Sell opening positions

[ ]에서:

# Complete strategy code:
def mp():
    positions = exchange.GetPosition() # Get the position array
    if len(positions) == 0: # If the length of the position array is 0
        return 0 # It proved a short position, return 0
    for i in range(len(positions)): # Iterate through the positions array
        if (positions[i]['Type'] == PD_LONG) or (positions[i]['Type'] == PD_LONG_YD):
            return 1 # If there are long position orders, return 1
        elif (positions[i]['Type'] == PD_SHORT) or (positions[i]['Type'] == PD_SHORT_YD):
            return -1 # If there are short position orders, return -1

def main(): # Main function
    exchange.SetContractType("rb888") # Set the variety code, the main contract is the contract code followed by the number 888
    while True: # Enter the loop
        records = exchange.GetRecords() # Get the K-line array
        if len(records) < 50: continue # If there are less than 50 K-lines, skip the loop
        close = records[len(records) - 1].Close # Get the latest K-line closing price
        positions = mp() # Get position information function
        upper = TA.Highest(records, 50, 'High') # Get the maximum value of the 50-period maximum price
        lower = TA.Lowest(records, 50, 'Low') # Get the minimum value of the 50-period minimum price
        middle = (upper + lower) / 2 # Calculate the average value of the upper and lower tracks
        obj = ext.NewPositionManager() # Use the Trading Library
        if positions > 0 and close < middle: # If you hold a long position order and the closing price falls below the middle track
            obj.CoverAll() # Close all positions
        if positions < 0 and close > middle: # If you hold a short position order and the closing price rises above the middle track
            obj.CoverAll() # Close all positions
        if positions == 0: # If it's a short position
            if close > upper: # If the closing price rises above the upper track
                obj.OpenLong("rb888", 1) # Buy opening positions
            elif close < lower: # If the closing price falls below the lower track
                obj.OpenShort("rb888", 1) # Sell opening positions

관련

더 많은