국내주식자동거래개발/ChatGPT를활용한주식매매

OpenAI platform playground를 통한 프롬프트 개발

알토란7 2024. 10. 5. 16:00

Youtube 조코딩 채널의 코인 자동 매매 영상에 ChatGPT API를 이용해서 자동 거래를 하는 것이 인상적이어서 해당 영상을 약간 응용해서 캔들 차트분석을 해보았습니다.

영상을 통해서 OpenAI playground에서 일반 ChatGPT 사용하듯 Chat창에서 프롬프트와 입력을 넣고 이를 실제 코드에 넣을 수 있는 소스코드를 획득할 수 있다는 것을 알게되어 이 부분을 정리했습니다. 자동거래 전반에 대해 관심있는 분은 아래 약 한시간 분량의 영상 링크를 보시면 GPT로 실제 거래를 어떻게 하지 하는 인사이트를 얻을 수 있습니다. 전체 풀 영상은 유료인데, 저는 맞뵈기 영상만으로도 좋았습니다.

ChatGPT를 통한 차트 데이터로 부터 지지/저항선 분석하기

  1. 프롬프트 작성: 영문 프롬프트로 작성하는게 효율적이며, 프롬프트 내용에 출력 예시를 주어 json 형태로 받을 수 있음.
  2. 프롬프트에 입력으로 넣은 이미지 파일.
  3. chat API response.
  4. 한번의 API 사용에 소요된 토큰수: 비용과 직결됨으로 얼마나 사용되는지 확인해야 함.
    지금 날짜 24년 10월의 GPT-4o 기준 1M 당 입력토큰 2.5 달러, 출력 토큰 10 달러로 위  시험의 사용량 1272 토큰이면 현재 환율 달러당 1350원으로 하고 출력은 전체 토큰의 1/20라고 가정한다면 약 0.003657×1350=4.937 원의 요금이 산정됨, 즉 위 테스트에 약 5원의 내 돈이 나갔음
  5. Playground에서 수행했던 과정의 소스코드를 볼수 있음

위 시험을 통해 얻은 소스코드입니다. 이미지 내용이 너무 많아서 내용 중간은 없앴습니다.

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4o",
  messages=[
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are a professional who is good at day trading.\nFind the support and resistance of the daily candle chart  and tell me the reason for your finding.\nThe output format is json and the format is as follows.\n{\"support_line\": 1000, \"resistance_line\": 15000, \"support_note\": \"reason\", \"resistance_note\": \"reason\",}"
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,iVBORw0KGgoAAAY6UGe+R ... JRU5ErkJggg=="
          }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "```json\n{\n  \"support_line\": 311000,\n  \"resistance_line\": 430000,\n  \"support_note\": \"The support line is identified at 311,000, which is the lowest point marked on the chart.\",\n  \"resistance_note\": \"The resistance line is marked at 430,000, which is the highest point indicated on the chart.\"\n}\n```"
        }
      ]
    }
  ],
  temperature=1,
  max_tokens=2048,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0,
  response_format={
    "type": "text"
  }
)

입력에 사용된 이미지 파일

참고 자료

참고 영상

https://youtu.be/EOnaOpZy9ew?si=5AwW84eKtxY0-beV

 

OpenAI playground URL

https://platform.openai.com/playground/chat