1

챗GPT로 비트코인 자동매매 프로그램 개발시키기

타이키모스

챗GPT로 비트코인 자동매매 프로그램 개발시키기

AF 김태영
2023.02.16 17:53
7280

챗GPT를 활용하여 비트코인 자동매매 프로그램 개발한 순서는 아래와 같습니다.

  1. 매매 전략을 제외한 비트코인 자동매매 프로그램 작성하기
  2. 매매 전략을 챗GPT에게 작성 부탁하기
  3. 챗GPT가 작성한 매매 전략에 대해 검증하기
  4. 실제로 시장에서 자동매매 시켜보기

하나씩 설명하는 영상을 첨부합니다.

아래는 챗GPT가 생성한 비트코인 자동매매 전략 중 하나입니다.

import talib

# Define MACD and RSI parameters
fast_period = 12
slow_period = 26
signal_period = 9
rsi_period = 14

def check_buy_signal(ticker, curr_price):
    # Get historical data for MACD and RSI calculation
    historical_data = pybithumb.get_ohlcv(ticker)
    close_prices = historical_data['close']
    
    # Calculate MACD and signal line
    macd, signal, _ = talib.MACD(close_prices, fastperiod=fast_period, slowperiod=slow_period, signalperiod=signal_period)
    
    # Calculate RSI
    rsi = talib.RSI(close_prices, timeperiod=rsi_period)
    
    # Check if MACD line crosses signal line from below and RSI is below 30
    if macd[-1] > signal[-1] and macd[-2] < signal[-2] and rsi[-1] < 30:
        return True
    else:
        return False

아래는 매수 시그널을 체크하는 코드입니다.

def check_sell_signal(ticker, curr_price, buy_price):
    # Get historical data for MACD calculation
    historical_data = pybithumb.get_ohlcv(ticker)
    close_prices = historical_data['close']
    
    # Calculate MACD and signal line
    macd, signal, _ = talib.MACD(close_prices, fastperiod=fast_period, slowperiod=slow_period, signalperiod=signal_period)
    
    # Calculate RSI
    rsi = talib.RSI(close_prices, timeperiod=rsi_period)
    
    # Check if MACD line crosses signal line from above or RSI is above 70
    if macd[-1] < signal[-1] and macd[-2] > signal[-2] or rsi[-1] > 70:
        return True
    else:
        return False

매수 및 매도 전략 코드만 챗GPT로 제작하였고, 베이스가 되는 자동매매 프로그램이나 백테스팅 코드는 개인마다 이미 사용하고 있거나 검증이 마친 코드이어야 되기 때문에 간단하게 직접 작성했습니다. 전체 코드에 대해서는 제 블로그에서 확인할 수 있습니다.

https://tykimos.github.io/2023/02/16/ChatGPT_Auto_Trading_Program_in_Python/

1
0개의 댓글
로그인 후 이용해주세요!