[Backtest] Cryptocurrency Trend Following Backtest


개요

암호화폐 추세 추종 트레이딩 전략 백테스트를 해 봅니다.

대한민국에서는 암호화폐 투자 열풍이 매우 뜨겁습니다. 암호화폐는 굉장히 변동성이 높고 규제라는 위험성이 있는 자산입니다. 그러나, 포트폴리오에서 낮은 비중으로 암호화폐 투자를 한다면 잃을 경우 비중이 낮았으니 큰 문제는 아니고, 이익을 낼 경우 포트폴리오 전체의 수익에 꽤 도움이 될 수 있습니다.

암호화폐는 주식처럼 이익이나 회계 데이터 같은 펀더멘탈 요소가 없고, 거시 경제 흐름이 직접적인 영향을 주지도 않습니다. 정부 규제, 가격, 거래량, 수급 정도가 유의미한 영향을 준다고 할 수 있는데, 정부 규제는 개인 투자자가 어쩔 방법이 없습니다. 수급 또한 24시간 활발한 거래가 이루어지기 때문에 후행 지표인 수급을 보고 움직이면 별 도움이 안 될 가능성이 높습니다. 그러면 남는 것은 가격과 거래량입니다.

암호화폐 시장은 예전보다는 기관들이 많이 뛰어들고 있지만, 아직은 개인들이 더 많다고 보여집니다. 위에서 이야기한 암호화폐의 특성과 시장 참여자 구성을 생각할 때, 저는 암호화폐 시장이 그렇게 효율적이지 않을 가능성이 높다고 생각했습니다. 효율적이지 않은 시장은 정보의 반영이 빠르지 않고 시장 참여자들의 비이성적 행태에 영향을 많이 받습니다. 이러한 비효율적인 시장에서는 한 번 오르기 시작하면 상승 추세가 지속되고, 내리기 시작하면 하락 추세가 지속되는 경향이 있습니다. 이런 상황은 1970~1980년대 선물 시장에서 활약하던 트레이더들을 떠오르게 합니다. 당시 시장을 휩쓸던 사람들은 윌리엄 에크하르트와 리처드 데니스, 그들의 제자들로 이루어진 터틀이라는 그룹이었고, 그들의 전략은 추세 추종을 기반으로 한 시스템 트레이딩입니다. 터틀 트레이딩의 뼈대는 특정 기간 동안의 고점 돌파 시 long position을 취하고, 특정 기간 동안의 저점 돌파 시 long position을 청산하는 것입니다. Short position으로도 비슷하게 진입합니다.

백테스트 및 거래는 Upbit 거래소에서 진행합니다. Upbit 거래소는 선물이나 파생상품을 지원하지 않아 short position 진입이 불가능합니다. 그래서, Long position으로만 진행할 것이고, 터틀 트레이딩의 고가 - 저가 돌파는 거래 신호가 다소 늦게 나오고 거래 횟수가 줄어들 수 있습니다. 저는 고가와 저가 대신 특정 기간 동안의 고가와 저가 채널에서 상하단 20% 지점을 돌파 기준선으로 정했습니다. 일종의 stochastic pop 전략입니다.

기준이 되는 캔들은 4시간봉입니다. 오전 9시에서 오후 3시 30분까지 6시간 30분 동안 열리는 주식 시장과 달리 암호화폐 시장은 24시간 열리니 일봉보다는 time frame이 짧아야 합니다. 그렇다고 너무 짧은 time frame을 사용하면 큰 추세를 놓칠 가능성이 있어 Upbit API가 제공하는 일봉 미만의 캔들 중 가장 긴 4시간봉을 사용합니다.

거래 대상은 Bitcoin (KRW-BTC), Ethereum (KRW-ETH), Bitcoin Cash (KRW-BCH), EOS (KRW-EOS), Ripple (KRW-XRP) 입니다. BTC, ETH는 특수한 암호화폐들을 제외하면 시가총액 1, 2위이니 당연히 포함합니다. 그 외에는 거래량 상위에 있는 암호화폐들인 BCH, EOS, XRP를 추가합니다.

필요한 파이썬 라이브러리들을 가져옵니다.

import pyupbit
import pandas as pd
import pandas_datareader.data as web
import datetime
import numpy as np
import math
import time as timelibrary
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams["figure.figsize"] = (10, 6) # (w, h)

backtester 함수의 입력으로 테스트할 암호화폐의 티커, 캔들 종류, 거래 신호 생성 시 사용할 캔들 수, 채널 상하단 범위, 테스트 시작 시점과 끝 시점을 받습니다. Upbit API가 200개의 캔들까지 주기 때문에, 그것을 고려해 테스트 기간에 따라 조절해 가면서 데이터를 가져올 수 있도록 했습니다.

만들어진 가격 데이터에서 num_candle 동안의 고가와 저가를 구하고, 채널 상하단을 계산합니다. 그리고, 거래 상황을 표시할 변수들을 생성하고, 수익 곡선을 그리기 위한 리스트를 만듭니다.

전체 데이터에서 맨 앞의 num_candle 개수만큼은 num_candle 동안의 고가와 저가를 완전히 구할 수 없으니 제외합니다. 실제 거래에서는 현재가를 받아온 후 채널 상단을 돌파하는지, 하단을 돌파하는지 체크할 것이지만, 백테스트에서는 특정 캔들 데이터로 테스트하기 때문에 그 캔들의 고가와 저가 사이에 거래 신호에 해당하는 가격이 들어 있으면 거래하는 것으로 간주합니다. 체결가는 거래 신호 가격으로 하고, 슬리피지를 보수적으로 1%로 설정합니다. 실거래에서는 거래 비용 등을 포함해도 슬리피지가 1%나 발생하지는 않습니다. 손절은 실거래를 5개 암호화폐로 진행할 것이기 때문에, 단일 거래에서 자금의 2% 이상을 잃지 않도록 하라는 전통적인 자금 관리 기법을 차용해 각 암호화폐에 자금의 1/5 정도가 할당되도록 하고, 진입가 대비 -10% 손절선을 잡습니다. 암호화폐 시장은 변동성이 매우 커 10% 변동도 충분히 나올 수 있습니다. 거래 로그, 수익 곡선, 누적 수익률, 거래 횟수, 승률, 손익비를 출력하도록 합니다.

# crypto: 암호화폐 티커
# interval: 캔들 종류
# num_candle: 거래 시그널 만들 때 사용할 캔들 수
# range_up: 채널 상단 범위
# range_down: 채널 하단 범위
# begin: 시작 시간
# end: 끝 시간

def backtester(crypto, interval, num_candle, range_up, range_down, begin, end):
    # 2017-09-26 17:00:00 -> 1506412800
    starttime = int(timelibrary.mktime(datetime.datetime.strptime(begin, '%Y-%m-%d %H:%M:%S').timetuple()))
    # 2021-04-08 01:00:00 -> 1617811200
    endtime = int(timelibrary.mktime(datetime.datetime.strptime(end, '%Y-%m-%d %H:%M:%S').timetuple()))
    # 봉 총 개수
    total_candle = (endtime - starttime) / 14400
    
    df_total = pd.DataFrame(columns=['open', 'high', 'low', 'close', 'volume'])
    
    # 봉 200개씩 가져올 수 있음 -> total_candle // 200 + 1
    num_chunk = int(total_candle // 200)
    
    for i in range(num_chunk + 1):
        df = pyupbit.get_ohlcv(crypto, interval=interval, to=datetime.datetime.fromtimestamp(starttime + (i+1) * 200 * 14400).strftime('%Y-%m-%d %H:%M:%S'))
        df_total = pd.concat([df_total, df])
    
    df_total['high_candle'] = df_total['high'].shift(1).rolling(window=num_candle).max()
    df_total['low_candle'] = df_total['low'].shift(1).rolling(window=num_candle).min()
    
    df_total['high_low_up'] = df_total['low_candle'] + range_up * (df_total['high_candle'] - df_total['low_candle'])
    df_total['high_low_down'] = df_total['low_candle'] + range_down * (df_total['high_candle'] - df_total['low_candle'])
    
    long = 0
    entry_price = 0
    exit_price = 0
    stop_loss_price = 0
    budget = 1000000
    position_size = 0
    win = 0
    lose = 0
    gross_profit = 0
    gross_loss = 0
    timestamp_budget = []
    labels = ['Date', 'Budget']
    
    # start point for graph
    timestamp_budget.append([df_total.index[num_candle], budget])
    
    for i in range(len(df_total)):
        if i >= num_candle:
            # long
            # low < high_low_up < high -> enter long position
            if df_total.iloc[i,7] < df_total.iloc[i,1] and df_total.iloc[i,7] > df_total.iloc[i,2]:
                # long signal on, no long position yet
                # long position activated and long signal on -> pass
                if long == 0:
                    # long state activate
                    long = 1
                    entry_price = df_total.iloc[i,7]
                    # 손절선 조절 가능
                    # 실거래를 5개 암호화폐 동일 비중으로 할 생각이라 1회 거래에서 총 자금의 2% 이상 잃지 않도록 10% 손절선 설정
                    stop_loss_price = entry_price * (1 - 0.1)
                    position_size = budget / entry_price
                    print("Date: ", df_total.index[i], "Long Entry: ", entry_price, "Size: ", position_size)
                    
            # stop loss on
            if long == 1 and stop_loss_price < df_total.iloc[i,1] and stop_loss_price > df_total.iloc[i,2]:
                exit_price = stop_loss_price
                # 슬리피지 1% 가정 (실제보다 보수적으로)
                pnl = (exit_price - entry_price) * position_size * (1 + 0.01)
                budget += pnl
                # graph point
                timestamp_budget.append([df_total.index[i], budget])
                gross_loss += pnl
                lose += 1
                print("Date: ", df_total.index[i], "Long stop loss ", "Profit or Loss: ", pnl)
                long = 0
                exit_price = 0
                entry_price = 0
                stop_loss_price = 0
                position_size = 0    
            
            # long position close rule on
            # low < high_low_down < high --> close long position
            if long == 1 and df_total.iloc[i,8] < df_total.iloc[i,1] and df_total.iloc[i,8] > df_total.iloc[i,2]:
                exit_price = df_total.iloc[i,8]
                # 슬리피지 1% 가정 (실제보다 보수적으로)
                pnl = (exit_price - entry_price) * position_size * (1 - 0.01)
                budget += pnl
                # graph point
                timestamp_budget.append([df_total.index[i], budget])
                
                if pnl > 0:
                    gross_profit += pnl
                    win += 1
                if pnl < 0:
                    gross_loss += pnl
                    lose += 1
                
                print("Date: ", df_total.index[i], "Long close ", "Profit or Loss: ", pnl)
                long = 0
                exit_price = 0
                entry_price = 0
                stop_loss_price = 0
                position_size = 0
                
    df_timestamp_budget = pd.DataFrame.from_records(timestamp_budget, columns=labels)
    df_timestamp_budget = df_timestamp_budget.set_index('Date')
    
    df_timestamp_budget.plot(title='Trend Following Strategy')
    
    return budget, (str(budget/1000000 * 100) + str('%')), win+lose, win/(win+lose), (gross_profit/win)/abs(gross_loss/lose)

테스트 출력 예시입니다. KRW-ETH (원화 마켓, 이더리움) 대상으로 4시간봉 20개를 사용하고, 채널 상하단은 80 - 20, 2017년 9월 26일 오후 5시부터 2021년 4월 8일 오전 1시까지입니다.

Date:  2017-10-01 01:00:00 Long Entry:  339700.0 Size:  2.943773918163085
Date:  2017-10-03 17:00:00 Long close  Profit or Loss:  -25937.59199293494
Date:  2017-10-04 17:00:00 Long Entry:  341600.0 Size:  2.8514707494352023
Date:  2017-10-10 01:00:00 Long close  Profit or Loss:  -3387.5472503290202
Date:  2017-10-11 13:00:00 Long Entry:  352400.0 Size:  2.7544689578795007
Date:  2017-10-17 09:00:00 Long close  Profit or Loss:  48266.559548922494
Date:  2017-10-24 21:00:00 Long Entry:  362500.0 Size:  2.8108728836018164
Date:  2017-10-25 09:00:00 Long close  Profit or Loss:  -60942.534989370986
Date:  2017-10-29 17:00:00 Long Entry:  346900.0 Size:  2.7615995540971103
Date:  2017-10-29 13:00:00 Long close  Profit or Loss:  -15583.706283769992
Date:  2017-10-29 21:00:00 Long Entry:  355300.0 Size:  2.652449138847502
Date:  2017-10-30 05:00:00 Long close  Profit or Loss:  -31773.688234254227
Date:  2017-10-31 09:00:00 Long Entry:  355300.0 Size:  2.563021364475832
Date:  2017-11-01 09:00:00 Long close  Profit or Loss:  -16239.303365318872
Date:  2017-11-06 21:00:00 Long Entry:  346700.0 Size:  2.579758256224241
Date:  2017-11-06 21:00:00 Long stop loss  Profit or Loss:  -90334.62093072738
Date:  2017-11-07 13:00:00 Long Entry:  341060.0 Size:  2.3575545842438776
Date:  2017-11-11 01:00:00 Long close  Profit or Loss:  -163.3785326881007
Date:  2017-11-13 01:00:00 Long Entry:  365760.0 Size:  2.1979007763821325
Date:  2017-11-16 17:00:00 Long close  Profit or Loss:  261.11061223419733
Date:  2017-11-19 05:00:00 Long Entry:  377530.0 Size:  2.1300699244610044
Date:  2017-11-30 05:00:00 Long close  Profit or Loss:  329537.3668245659
Date:  2017-12-04 05:00:00 Long Entry:  535290.0 Size:  2.117922369942142
Date:  2017-12-07 01:00:00 Long close  Profit or Loss:  16459.433698005356
Date:  2017-12-07 05:00:00 Long Entry:  561480.0 Size:  2.0484471381070284
Date:  2017-12-08 17:00:00 Long close  Profit or Loss:  -79252.78101565044
Date:  2017-12-08 21:00:00 Long Entry:  580600.0 Size:  1.8444872857194006
Date:  2017-12-10 01:00:00 Long stop loss  Profit or Loss:  -108161.84112695708
Date:  2017-12-12 05:00:00 Long Entry:  566080.0 Size:  1.7007268883580535
Date:  2017-12-22 13:00:00 Long close  Profit or Loss:  634324.529440813
Date:  2017-12-26 17:00:00 Long Entry:  1031560.0 Size:  1.548210483541956
Date:  2017-12-28 09:00:00 Long stop loss  Profit or Loss:  -161304.27264665655
Date:  2017-12-30 21:00:00 Long Entry:  1018000.0 Size:  1.4103808779527343
Date:  2018-01-11 05:00:00 Long close  Profit or Loss:  1122327.5082014238
Date:  2018-01-14 09:00:00 Long Entry:  1950000.0 Size:  1.3118437138242602
Date:  2018-01-16 05:00:00 Long close  Profit or Loss:  -169613.5211351939
Date:  2018-01-20 09:00:00 Long Entry:  1399800.0 Size:  1.7063021294628615
Date:  2018-01-21 13:00:00 Long stop loss  Profit or Loss:  -241236.65380303346
Date:  2018-01-25 09:00:00 Long Entry:  1304700.0 Size:  1.6457768582962216
Date:  2018-01-26 17:00:00 Long stop loss  Profit or Loss:  -216871.7517689271
Date:  2018-01-27 01:00:00 Long Entry:  1268000.0 Size:  1.5223764315852943
Date:  2018-01-31 01:00:00 Long close  Profit or Loss:  -53654.63495479212
Date:  2018-02-08 09:00:00 Long Entry:  884820.0 Size:  2.1210174728140876
Date:  2018-02-18 17:00:00 Long close  Profit or Loss:  302960.19696784037
Date:  2018-02-20 13:00:00 Long Entry:  1099600.0 Size:  1.982247069173519
Date:  2018-02-21 09:00:00 Long close  Profit or Loss:  -117156.74852936249
Date:  2018-02-28 09:00:00 Long Entry:  991880.0 Size:  2.0794069128663133
Date:  2018-03-01 09:00:00 Long close  Profit or Loss:  -48336.22957096002
Date:  2018-03-12 17:00:00 Long Entry:  813120.0 Size:  2.477107805936244
Date:  2018-03-13 05:00:00 Long close  Profit or Loss:  -111188.94724193781
Date:  2018-03-21 05:00:00 Long Entry:  626480.0 Size:  3.037602081344881
Date:  2018-03-22 21:00:00 Long close  Profit or Loss:  -115778.20333046015
Date:  2018-04-03 21:00:00 Long Entry:  443330.0 Size:  4.031350796450682
Date:  2018-04-05 09:00:00 Long close  Profit or Loss:  -137171.95160526986
Date:  2018-04-08 05:00:00 Long Entry:  423520.0 Size:  3.896030404668519
Date:  2018-04-25 17:00:00 Long close  Profit or Loss:  947450.6995167471
Date:  2018-04-29 17:00:00 Long Entry:  731540.0 Size:  3.550725177709979
Date:  2018-05-01 09:00:00 Long close  Profit or Loss:  -42955.96305489979
Date:  2018-05-03 09:00:00 Long Entry:  767600.0 Size:  3.3279592671274862
Date:  2018-05-07 09:00:00 Long close  Profit or Loss:  237875.87249573847
Date:  2018-05-13 21:00:00 Long Entry:  817400.0 Size:  3.4162189943024184
Date:  2018-05-16 09:00:00 Long close  Profit or Loss:  -212663.7318581187
Date:  2018-05-19 17:00:00 Long Entry:  786560.0 Size:  3.279792608427428
Date:  2018-05-22 13:00:00 Long close  Profit or Loss:  -64095.67502945386
Date:  2018-05-30 09:00:00 Long Entry:  646720.0 Size:  3.8898719678612443
Date:  2018-06-05 13:00:00 Long close  Profit or Loss:  -37123.382112480576
Date:  2018-06-06 01:00:00 Long Entry:  673560.0 Size:  3.6797532765347456
Date:  2018-06-09 21:00:00 Long close  Profit or Loss:  -70746.20054400171
Date:  2018-06-19 01:00:00 Long Entry:  564640.0 Size:  4.264289487813016
Date:  2018-06-20 09:00:00 Long close  Profit or Loss:  -23303.489193000572
Date:  2018-06-20 21:00:00 Long Entry:  601880.0 Size:  3.961728130533896
Date:  2018-06-22 13:00:00 Long close  Profit or Loss:  -139784.03066650577
Date:  2018-06-30 09:00:00 Long Entry:  499400.0 Size:  4.4947955477357535
Date:  2018-07-04 09:00:00 Long close  Profit or Loss:  26343.097746169704
Date:  2018-07-04 21:00:00 Long Entry:  530350.0 Size:  4.2821608264078534
Date:  2018-07-10 09:00:00 Long close  Profit or Loss:  -15558.374930587654
Date:  2018-07-14 01:00:00 Long Entry:  499600.0 Size:  4.514582905033662
Date:  2018-07-20 05:00:00 Long close  Profit or Loss:  137837.43942332573
Date:  2018-07-24 13:00:00 Long Entry:  526420.0 Size:  4.54641362178136
Date:  2018-07-27 13:00:00 Long close  Profit or Loss:  -53021.18493993858
Date:  2018-08-17 09:00:00 Long Entry:  344440.0 Size:  6.794512466142739
Date:  2018-08-18 21:00:00 Long close  Profit or Loss:  -79777.08866996835
Date:  2018-08-28 05:00:00 Long Entry:  317180.0 Size:  7.126946166745181
Date:  2018-08-30 17:00:00 Long close  Profit or Loss:  -43180.7414350757
Date:  2018-09-01 21:00:00 Long Entry:  325740.0 Size:  6.807097819528338
Date:  2018-09-04 13:00:00 Long close  Profit or Loss:  -46903.62681567806
Date:  2018-09-13 21:00:00 Long Entry:  223170.0 Size:  9.725502607507652
Date:  2018-09-17 21:00:00 Long close  Profit or Loss:  118138.5978241777
Date:  2018-09-21 05:00:00 Long Entry:  242920.0 Size:  9.42112224082686
Date:  2018-09-25 05:00:00 Long close  Profit or Loss:  140276.7417170156
Date:  2018-09-28 05:00:00 Long Entry:  259680.0 Size:  9.353264619757686
Date:  2018-10-03 09:00:00 Long close  Profit or Loss:  -58614.103392635494
Date:  2018-10-06 05:00:00 Long Entry:  254920.0 Size:  9.297982320202575
Date:  2018-10-10 13:00:00 Long close  Profit or Loss:  -6903.751872750412
Date:  2018-10-15 13:00:00 Long Entry:  229020.0 Size:  10.319351590224828
Date:  2018-10-19 05:00:00 Long close  Profit or Loss:  5108.07903716129
Date:  2018-10-21 09:00:00 Long Entry:  232030.0 Size:  10.207498945095251
Date:  2018-10-22 21:00:00 Long close  Profit or Loss:  -41129.075499472296
Date:  2018-10-26 17:00:00 Long Entry:  229170.0 Size:  10.155416960033945
Date:  2018-10-26 17:00:00 Long close  Profit or Loss:  -31066.43602243984
Date:  2018-11-02 09:00:00 Long Entry:  224520.0 Size:  10.227376040925257
Date:  2018-11-04 09:00:00 Long close  Profit or Loss:  -10125.102280516005
Date:  2018-11-04 13:00:00 Long Entry:  226880.0 Size:  10.07636356852972
Date:  2018-11-04 13:00:00 Long close  Profit or Loss:  -33518.01577435726
Date:  2018-11-04 21:00:00 Long Entry:  226940.0 Size:  9.926004012750797
Date:  2018-11-09 21:00:00 Long close  Profit or Loss:  94140.2072577311
Date:  2018-11-28 21:00:00 Long Entry:  133490.0 Size:  17.579950242800184
Date:  2018-12-01 13:00:00 Long close  Profit or Loss:  -133489.83617865463
Date:  2018-12-17 21:00:00 Long Entry:  97426.0 Size:  22.717321061449116
Date:  2018-12-26 21:00:00 Long close  Profit or Loss:  1070845.8997696398
Date:  2018-12-29 01:00:00 Long Entry:  148300.0 Size:  22.14500081930129
Date:  2019-01-01 09:00:00 Long close  Profit or Loss:  -7892.47829199898
Date:  2019-01-02 13:00:00 Long Entry:  160790.0 Size:  20.375714554452284
Date:  2019-01-08 05:00:00 Long close  Profit or Loss:  169646.16180891427
Date:  2019-01-14 21:00:00 Long Entry:  142370.0 Size:  24.203535190133433
Date:  2019-01-14 21:00:00 Long close  Profit or Loss:  -253752.28328687794
Date:  2019-01-15 01:00:00 Long Entry:  142370.0 Size:  22.421191414851574
Date:  2019-01-17 17:00:00 Long close  Profit or Loss:  -200882.66448136268
Date:  2019-02-03 05:00:00 Long Entry:  120330.0 Size:  24.858492123751816
Date:  2019-02-06 05:00:00 Long close  Profit or Loss:  -52173.00326933031
Date:  2019-02-08 17:00:00 Long Entry:  118340.0 Size:  24.835637603360876
Date:  2019-02-24 21:00:00 Long close  Profit or Loss:  1071759.5886991955
Date:  2019-02-28 21:00:00 Long Entry:  153690.0 Size:  26.09674632494581
Date:  2019-03-02 17:00:00 Long close  Profit or Loss:  -222962.7715764395
Date:  2019-03-05 21:00:00 Long Entry:  148060.0 Size:  25.58318364922654
Date:  2019-03-09 05:00:00 Long close  Profit or Loss:  -74462.41432943876
Date:  2019-03-09 13:00:00 Long Entry:  152520.0 Size:  24.34686439008027
Date:  2019-03-11 21:00:00 Long close  Profit or Loss:  -137148.32179576115
Date:  2019-03-13 21:00:00 Long Entry:  149570.0 Size:  23.91011188727206
Date:  2019-03-14 21:00:00 Long close  Profit or Loss:  -101548.63619643317
Date:  2019-03-15 17:00:00 Long Entry:  149690.0 Size:  23.212551264498956
Date:  2019-03-20 09:00:00 Long close  Profit or Loss:  86176.59656945238
Date:  2019-03-21 21:00:00 Long Entry:  156050.0 Size:  22.818733709402764
Date:  2019-03-21 21:00:00 Long close  Profit or Loss:  -57605.89324938728
Date:  2019-03-23 09:00:00 Long Entry:  155430.0 Size:  22.539133385465572
Date:  2019-03-25 21:00:00 Long close  Profit or Loss:  -59354.553857285035
Date:  2019-03-27 09:00:00 Long Entry:  154640.0 Size:  22.27045362290241
Date:  2019-04-02 05:00:00 Long close  Profit or Loss:  104947.28565256532
Date:  2019-04-02 13:00:00 Long Entry:  163600.0 Size:  21.692238593509742
Date:  2019-04-11 13:00:00 Long close  Profit or Loss:  712550.9917673267
Date:  2019-04-15 05:00:00 Long Entry:  191840.0 Size:  22.21330914129233
Date:  2019-04-16 01:00:00 Long close  Profit or Loss:  -85545.67483403088
Date:  2019-04-17 09:00:00 Long Entry:  193550.0 Size:  21.57507388701364
Date:  2019-04-21 21:00:00 Long close  Profit or Loss:  53184.714638877325
Date:  2019-04-23 13:00:00 Long Entry:  202340.0 Size:  20.90066356365705
Date:  2019-04-24 09:00:00 Long close  Profit or Loss:  -139875.60083341843
Date:  2019-04-30 21:00:00 Long Entry:  184230.0 Size:  22.195976033419907
Date:  2019-05-06 01:00:00 Long close  Profit or Loss:  34059.72522328285
Date:  2019-05-06 21:00:00 Long Entry:  193560.0 Size:  21.30204789140438
Date:  2019-05-23 05:00:00 Long close  Profit or Loss:  2134842.244966397
Date:  2019-05-25 17:00:00 Long Entry:  304950.0 Size:  20.521615460982552
Date:  2019-05-31 05:00:00 Long close  Profit or Loss:  272849.2426845857
Date:  2019-06-08 01:00:00 Long Entry:  305400.0 Size:  21.384793312086494
Date:  2019-06-09 21:00:00 Long close  Profit or Loss:  -257015.27690064273
Date:  2019-06-12 05:00:00 Long Entry:  298570.0 Size:  21.01316475402945
Date:  2019-06-18 21:00:00 Long close  Profit or Loss:  372998.3835993505
Date:  2019-06-21 05:00:00 Long Entry:  323770.0 Size:  20.529693869752982
Date:  2019-06-27 17:00:00 Long close  Profit or Loss:  893460.4890891977
Date:  2019-07-08 01:00:00 Long Entry:  353760.0 Size:  21.31490127006762
Date:  2019-07-10 21:00:00 Long close  Profit or Loss:  -44524.69726304425
Date:  2019-07-20 09:00:00 Long Entry:  264620.0 Size:  28.326788511964615
Date:  2019-07-22 21:00:00 Long close  Profit or Loss:  -109930.60085723228
Date:  2019-07-25 09:00:00 Long Entry:  264800.0 Size:  27.892387368500163
Date:  2019-07-27 17:00:00 Long close  Profit or Loss:  -535425.057164466
Date:  2019-07-31 13:00:00 Long Entry:  251610.0 Size:  27.226577314154355
Date:  2019-08-08 21:00:00 Long close  Profit or Loss:  450676.08896573423
Date:  2019-08-18 17:00:00 Long Entry:  227650.0 Size:  32.07184365025307
Date:  2019-08-21 13:00:00 Long close  Profit or Loss:  -27940.990188100477
Date:  2019-09-02 17:00:00 Long Entry:  208960.0 Size:  34.80672959797096
Date:  2019-09-05 13:00:00 Long close  Profit or Loss:  -25499.41010347352
Date:  2019-09-08 01:00:00 Long Entry:  211320.0 Size:  34.2973443435952
Date:  2019-09-11 13:00:00 Long close  Profit or Loss:  23768.05963011147
Date:  2019-09-14 21:00:00 Long Entry:  215760.0 Size:  33.701718883568084
Date:  2019-09-23 01:00:00 Long close  Profit or Loss:  1127726.9172819552
Date:  2019-09-28 21:00:00 Long Entry:  206360.0 Size:  40.70173378368194
Date:  2019-10-04 05:00:00 Long close  Profit or Loss:  115242.88903511704
Date:  2019-10-07 21:00:00 Long Entry:  212120.0 Size:  40.13979196980823
Date:  2019-10-12 01:00:00 Long close  Profit or Loss:  154979.73679542958
Date:  2019-10-15 01:00:00 Long Entry:  219560.0 Size:  39.485481915791354
Date:  2019-10-16 01:00:00 Long close  Profit or Loss:  -224771.10580564226
Date:  2019-10-21 17:00:00 Long Entry:  208610.0 Size:  40.480615999355294
Date:  2019-10-21 21:00:00 Long close  Profit or Loss:  -213604.06644379807
Date:  2019-10-25 21:00:00 Long Entry:  201180.0 Size:  40.91389421006914
Date:  2019-10-31 09:00:00 Long close  Profit or Loss:  475120.77929326985
Date:  2019-11-03 09:00:00 Long Entry:  214700.0 Size:  40.55043323928728
Date:  2019-11-04 01:00:00 Long close  Profit or Loss:  -186673.919417059
Date:  2019-11-04 17:00:00 Long Entry:  214760.0 Size:  39.66988311164984
Date:  2019-11-07 17:00:00 Long close  Profit or Loss:  -66764.41327690668
Date:  2019-11-10 13:00:00 Long Entry:  219140.0 Size:  38.57232674902352
Date:  2019-11-12 21:00:00 Long close  Profit or Loss:  -164202.3949705931
Date:  2019-11-17 21:00:00 Long Entry:  216040.0 Size:  38.36575304948352
Date:  2019-11-19 01:00:00 Long close  Profit or Loss:  -227132.93120355235
Date:  2019-11-27 21:00:00 Long Entry:  174220.0 Size:  46.27140602460606
Date:  2019-12-01 09:00:00 Long close  Profit or Loss:  57718.9518750936
Date:  2019-12-04 21:00:00 Long Entry:  176240.0 Size:  46.068561674318886
Date:  2019-12-05 05:00:00 Long close  Profit or Loss:  -213444.85994945426
Date:  2019-12-08 17:00:00 Long Entry:  174280.0 Size:  45.361937396904445
Date:  2019-12-09 21:00:00 Long close  Profit or Loss:  -57482.64706935731
Date:  2019-12-22 21:00:00 Long Entry:  149430.0 Size:  52.520884711658624
Date:  2019-12-24 05:00:00 Long close  Profit or Loss:  -72273.98945171342
Date:  2019-12-29 21:00:00 Long Entry:  148990.0 Size:  52.190897462993725
Date:  2020-01-02 09:00:00 Long close  Profit or Loss:  -11883.86735232367
Date:  2020-01-03 17:00:00 Long Entry:  150260.0 Size:  51.67069044096307
Date:  2020-01-09 01:00:00 Long close  Profit or Loss:  324316.2556217488
Date:  2020-01-12 01:00:00 Long Entry:  163790.0 Size:  49.382466580871
Date:  2020-01-20 17:00:00 Long close  Profit or Loss:  1120527.6726932277
Date:  2020-01-26 17:00:00 Long Entry:  190220.0 Size:  48.41174363355109
Date:  2020-02-16 09:00:00 Long close  Profit or Loss:  5155095.473772508
Date:  2020-02-18 21:00:00 Long Entry:  319400.0 Size:  44.971751245293035
Date:  2020-02-25 13:00:00 Long close  Profit or Loss:  -391793.8968489929
Date:  2020-03-03 01:00:00 Long Entry:  277060.0 Size:  50.43017198764745
Date:  2020-03-08 21:00:00 Long close  Profit or Loss:  -38942.17880886136
Date:  2020-03-19 17:00:00 Long Entry:  155600.0 Size:  89.54525239131583
Date:  2020-03-23 05:00:00 Long close  Profit or Loss:  482254.91127867054
Date:  2020-03-24 17:00:00 Long Entry:  169940.0 Size:  84.82697530521015
Date:  2020-03-27 21:00:00 Long close  Profit or Loss:  -314920.1458205927
Date:  2020-03-31 17:00:00 Long Entry:  162220.0 Size:  86.92254985542361
Date:  2020-04-10 13:00:00 Long close  Profit or Loss:  2986050.355183367
Date:  2020-04-16 13:00:00 Long Entry:  197260.0 Size:  86.61982354623434
Date:  2020-04-21 01:00:00 Long close  Profit or Loss:  1011892.7786671096
Date:  2020-04-22 21:00:00 Long Entry:  221920.0 Size:  81.55425005135768
Date:  2020-05-04 09:00:00 Long close  Profit or Loss:  2304282.713501091
Date:  2020-05-07 21:00:00 Long Entry:  253000.0 Size:  80.64348571106083
Date:  2020-05-10 09:00:00 Long stop loss  Profit or Loss:  -2060682.9903747374
Date:  2020-05-13 21:00:00 Long Entry:  233330.0 Size:  78.61020397944394
Date:  2020-05-21 17:00:00 Long close  Profit or Loss:  1331570.384187403
Date:  2020-05-23 09:00:00 Long Entry:  253640.0 Size:  77.56540482065549
Date:  2020-05-26 21:00:00 Long close  Profit or Loss:  -681892.9868593465
Date:  2020-05-27 17:00:00 Long Entry:  251840.0 Size:  75.41215173066912
Date:  2020-06-02 21:00:00 Long close  Profit or Loss:  1772381.6372652242
Date:  2020-06-04 09:00:00 Long Entry:  296360.0 Size:  70.06403674286993
Date:  2020-06-07 17:00:00 Long close  Profit or Loss:  -520225.47281580925
Date:  2020-06-08 05:00:00 Long Entry:  293960.0 Size:  68.8663507154073
Date:  2020-06-11 21:00:00 Long close  Profit or Loss:  -293164.05499548884
Date:  2020-06-16 17:00:00 Long Entry:  282280.0 Size:  70.6773005572681
Date:  2020-06-19 09:00:00 Long close  Profit or Loss:  -496091.0403415205
Date:  2020-06-22 09:00:00 Long Entry:  279070.0 Size:  69.71260744961522
Date:  2020-06-24 21:00:00 Long close  Profit or Loss:  35197.895501310726
Date:  2020-07-01 17:00:00 Long Entry:  272170.0 Size:  71.6092708838793
Date:  2020-07-04 05:00:00 Long close  Profit or Loss:  -185031.19503685573
Date:  2020-07-06 13:00:00 Long Entry:  273580.0 Size:  70.56387185257906
Date:  2020-07-10 13:00:00 Long close  Profit or Loss:  570043.1823738746
Date:  2020-07-13 09:00:00 Long Entry:  287030.0 Size:  69.24330991116766
Date:  2020-07-16 01:00:00 Long close  Profit or Loss:  -270090.45463950053
Date:  2020-07-20 01:00:00 Long Entry:  280280.0 Size:  69.94725556287622
Date:  2020-08-02 13:00:00 Long close  Profit or Loss:  7906019.385937442
Date:  2020-08-03 21:00:00 Long Entry:  469370.0 Size:  58.612259358502655
Date:  2020-08-07 21:00:00 Long close  Profit or Loss:  -688189.982031923
Date:  2020-08-09 09:00:00 Long Entry:  470770.0 Size:  56.976116135413186
Date:  2020-08-11 21:00:00 Long close  Profit or Loss:  -987675.2755957741
Date:  2020-08-13 09:00:00 Long Entry:  464250.0 Size:  55.64883342482002
Date:  2020-08-18 21:00:00 Long close  Profit or Loss:  1501266.403718082
Date:  2020-08-25 05:00:00 Long Entry:  476520.0 Size:  57.36640082512964
Date:  2020-08-25 21:00:00 Long close  Profit or Loss:  -899596.9511793529
Date:  2020-08-29 01:00:00 Long Entry:  464930.0 Size:  56.86154984623798
Date:  2020-09-03 17:00:00 Long close  Profit or Loss:  2311950.8136631437
Date:  2020-09-10 01:00:00 Long Entry:  425200.0 Size:  67.61192658437103
Date:  2020-09-13 21:00:00 Long close  Profit or Loss:  475244.231961544
Date:  2020-09-17 09:00:00 Long Entry:  448620.0 Size:  65.14162412651267
Date:  2020-09-21 05:00:00 Long close  Profit or Loss:  -807417.4027232992
Date:  2020-09-25 05:00:00 Long Entry:  403690.0 Size:  70.39168176797249
Date:  2020-10-02 01:00:00 Long close  Profit or Loss:  628583.6398516407
Date:  2020-10-05 21:00:00 Long Entry:  410820.0 Size:  70.70006731114468
Date:  2020-10-06 17:00:00 Long close  Profit or Loss:  -342966.0265263628
Date:  2020-10-09 17:00:00 Long Entry:  408320.0 Size:  70.29299477429
Date:  2020-10-16 13:00:00 Long close  Profit or Loss:  1605442.7955484414
Date:  2020-10-19 05:00:00 Long Entry:  433410.0 Size:  69.92796294913947
Date:  2020-10-20 17:00:00 Long close  Profit or Loss:  -699901.9883616421
Date:  2020-10-21 21:00:00 Long Entry:  434800.0 Size:  68.0947020087969
Date:  2020-10-26 05:00:00 Long close  Profit or Loss:  1639502.5213254013
Date:  2020-11-01 09:00:00 Long Entry:  441560.0 Size:  70.76519375566241
Date:  2020-11-02 21:00:00 Long close  Profit or Loss:  -697072.5410901526
Date:  2020-11-05 01:00:00 Long Entry:  450510.0 Size:  67.81204948538355
Date:  2020-11-14 17:00:00 Long close  Profit or Loss:  3705121.540987335
Date:  2020-11-17 21:00:00 Long Entry:  513820.0 Size:  66.66756442849146
Date:  2020-11-26 09:00:00 Long close  Profit or Loss:  6247644.132312992
Date:  2020-11-30 17:00:00 Long Entry:  631500.0 Size:  64.1374063134766
Date:  2020-12-04 21:00:00 Long close  Profit or Loss:  384785.9554370715
Date:  2020-12-13 05:00:00 Long Entry:  622760.0 Size:  65.65540182798757
Date:  2020-12-21 05:00:00 Long close  Profit or Loss:  4481020.568001248
Date:  2020-12-23 09:00:00 Long Entry:  716800.0 Size:  63.293217927453675
Date:  2020-12-23 17:00:00 Long close  Profit or Loss:  -3035264.2416417976
Date:  2020-12-25 17:00:00 Long Entry:  701620.0 Size:  60.33652742047974
Date:  2021-01-02 01:00:00 Long close  Profit or Loss:  6054553.315146428
Date:  2021-01-02 21:00:00 Long Entry:  825720.0 Size:  58.60081829664223
Date:  2021-01-11 09:00:00 Long close  Profit or Loss:  27155572.318009373
Date:  2021-01-15 05:00:00 Long Entry:  1302300.0 Size:  58.00770943861845
Date:  2021-01-21 17:00:00 Long close  Profit or Loss:  4071619.1332060676
Date:  2021-01-24 13:00:00 Long Entry:  1458000.0 Size:  54.60566470172762
Date:  2021-01-27 17:00:00 Long close  Profit or Loss:  -2681356.559513633
Date:  2021-01-29 17:00:00 Long Entry:  1502300.0 Size:  51.21061211183202
Date:  2021-02-01 01:00:00 Long close  Profit or Loss:  -3472847.6603638884
Date:  2021-02-01 21:00:00 Long Entry:  1509000.0 Size:  48.681812402413094
Date:  2021-02-01 21:00:00 Long close  Profit or Loss:  -3470039.588044005
Date:  2021-02-02 09:00:00 Long Entry:  1509000.0 Size:  46.38225005115796
Date:  2021-02-07 21:00:00 Long close  Profit or Loss:  7668377.400957946
Date:  2021-02-08 21:00:00 Long Entry:  1813100.0 Size:  42.83227220128801
Date:  2021-02-15 09:00:00 Long close  Profit or Loss:  4066538.755062485
Date:  2021-02-16 01:00:00 Long Entry:  1973600.0 Size:  41.40947075558258
Date:  2021-02-22 09:00:00 Long close  Profit or Loss:  8043292.780622849
Date:  2021-03-01 17:00:00 Long Entry:  1723600.0 Size:  52.08228374555619
Date:  2021-03-05 09:00:00 Long close  Profit or Loss:  397023.24899237487
Date:  2021-03-07 01:00:00 Long Entry:  1839500.0 Size:  49.01660642176299
Date:  2021-03-12 21:00:00 Long close  Profit or Loss:  9341339.768827481
Date:  2021-03-13 17:00:00 Long Entry:  2119000.0 Size:  46.95959758454955
Date:  2021-03-15 13:00:00 Long close  Profit or Loss:  -2742910.094913539
Date:  2021-03-09 05:00:00 Long Entry:  2098400.0 Size:  46.11345653199912
Date:  2021-03-12 21:00:00 Long close  Profit or Loss:  -3031314.178587494
Date:  2021-03-13 17:00:00 Long Entry:  2119000.0 Size:  44.23462152343533
Date:  2021-03-15 13:00:00 Long close  Profit or Loss:  -2583744.2431838578
Date:  2021-03-18 09:00:00 Long Entry:  2145400.0 Size:  42.485978728896995
Date:  2021-03-21 21:00:00 Long close  Profit or Loss:  -3827561.82368633
Date:  2021-03-28 05:00:00 Long Entry:  2048000.0 Size:  42.63762545961391
Date:  2021-04-07 13:00:00 Long close  Profit or Loss:  22760305.57134558


(110082162.51263486,
 '11008.216251263486%',
 157,
 0.4140127388535032,
 5.091368266712472)

output_7_2

초기 자금 100만원으로 시작하여 마지막 청산이 이루어진 2021년 4월 7일 오후 1시에 1억 1008만원이 되었습니다. 약 3년 6개월 정도의 기간 동안 누적 수익 11008% (110배)로 CAGR 383% 정도입니다. 승률은 41%, 손익비는 5.09입니다. 추세 추종이기 때문에 대체로 손익비가 높아 승률이 높을 필요는 없으나, 41%면 꽤 괜찮습니다. (야구처럼 3할만 쳐도 손익비가 높으면 우상향합니다) 같은 기간 Ethereum을 매수 후 쭉 보유하고 있었다면 누적 수익 815%로 CAGR 82% 수준입니다. 현재 테스트한 전략은 매수 후 보유 전략과 달리 청산과 탈출 전략도 겸하고 있기 때문에, 매수 후 보유 시 겪을 하락에 의한 스트레스도 덜합니다.

다른 암호화폐를 같은 조건으로 테스트해도 성과가 Ethereum보다는 못하지만, 매수 후 보유보다는 낫습니다.

 전략 누적 수익승률손익비매수 후 보유 누적 수익
Ethereum11008%41%5.09815%
Bitcoin2951%42%4.021692%
Bitcoin Cash2750%35%2.9676%
EOS405%34%2.524.3%
Ripple*999%27%3.45570%

(Ripple은 2021년 4월 1일 오전 5시 진입한 거래가 아직 청산되지 않았는데, 690원에 진입했으므로 2021년 4월 8일 오전 1시 1250원인 것을 고려하면 포지션이 승리로 청산될 가능성이 높아 전략 누적 수익은 더 올라갈 것입니다)

이 전략과 백테스트의 약점은 다음과 같습니다.

  • 실제 틱 데이터를 가져다 한 것이 아니므로 실제 거래에서는 테스트와 누적 수익이 다르든 승률이 다르든 손익비가 다르든 결과가 다를 가능성이 매우 높습니다.
  • 규제가 가해진다면 사용 못 합니다.
  • Upbit 거래소에서는 잘 작동하나, 다른 거래소에서는 잘 작동하지 않을 수 있습니다.
  • 지금까지는 암호화폐가 대체로 우상향했지만, 극도의 횡보장에서는 손절 주문과 손실 거래만 반복될 수 있습니다.
  • 지금까지처럼 강력한 추세와 엄청난 변동성을 동반해야 성과가 납니다.
  • 승률이 30~40%로 일반적인 추세 추종 전략 수준이지만, 생각보다 참기 힘듭니다.

본 글은 매수 및 매도, 종목 추천 등과는 무관하며, 거래에 따른 책임은 모두 거래 실행 당사자에게 있습니다.






© 2021.03. by JacobJinwonLee

Powered by theorydb