자동매매(Automated Trading)란 미리 정의된 규칙이나 알고리즘에 따라 매수/매도 주문을 자동으로 실행하는 시스템이다. 사람의 감정을 배제하고, 24시간 일관된 규칙으로 시장에 대응할 수 있다.
Automated trading is a system that automatically executes buy/sell orders based on predefined rules or algorithms. It eliminates human emotion and responds to the market with consistent rules around the clock.
핵심: 자동매매는 "돈을 벌어주는 마법"이 아니라, 전략을 일관되게 실행하는 도구다. 좋은 전략 없이 자동화하면 손실도 자동화된다.
Key point: Automated trading is not a "money-making magic" but a tool for consistent strategy execution. Automating without a good strategy just automates losses.
자동매매 시스템은 다섯 가지 핵심 모듈로 구성된다. 각 모듈이 독립적으로 동작하면서 서로 데이터를 주고받는 구조가 이상적이다.
An automated trading system consists of five core modules. The ideal architecture has each module operating independently while exchanging data with others.
| 전략 | Strategy | 원리 | Principle | 장점 | Pros | 단점 | Cons |
|---|---|---|---|---|---|---|---|
| Momentum | 오르는 종목은 계속 오른다는 가정. 추세 추종 | Assumption that rising stocks keep rising. Trend-following | 강한 추세에서 높은 수익 | High returns in strong trends | 횡보장에서 손실 누적 | Losses accumulate in sideways markets | |
| Mean Reversion | 가격은 평균으로 회귀한다는 가정. 과매수/과매도 매매 | Assumption prices revert to mean. Overbought/oversold trading | 횡보장에서 안정적 | Stable in sideways markets | 강한 추세에서 역행 손실 | Adverse losses in strong trends | |
| Volatility Breakout | 전일 변동성 돌파 시 진입. 래리 윌리엄스 전략 기반 | Enter on previous-day volatility breakout. Based on Larry Williams strategy | 구현이 단순, 단타에 적합 | Simple implementation, suited for day trading | K값 최적화 과적합 위험 | Risk of K-value optimization overfitting | |
| ML-based | 머신러닝 모델이 매매 신호 생성. LSTM, XGBoost 등 | ML model generates signals. LSTM, XGBoost, etc. | 복잡한 패턴 포착 가능 | Can capture complex patterns | 과적합, 블랙박스, 유지보수 비용 | Overfitting, black-box, maintenance cost |
과적합 경고: 백테스트에서 수익률이 너무 좋으면 과적합을 의심해야 한다. 학습 기간과 검증 기간을 반드시 분리하고, 최소 1년 이상의 out-of-sample 테스트를 거쳐야 한다.
Overfitting warning: If backtest returns look too good, suspect overfitting. Always separate training and validation periods, and run at least 1 year of out-of-sample testing.
자동매매 시스템의 데이터는 다섯 단계를 거쳐 흐른다. 각 단계는 명확한 입출력을 가지며, 파이프라인처럼 연결된다.
Data flows through five stages in an automated trading system. Each stage has clear input/output and connects like a pipeline.
지연(Latency): Quote에서 Order까지의 지연 시간이 전략 수익에 직접 영향을 미친다. 단타 전략은 100ms 이하, 스윙 전략은 수초 단위도 무방하다.
Latency: The delay from Quote to Order directly affects strategy returns. Day trading needs under 100ms; swing trading tolerates seconds.
수익을 내는 것보다 생존하는 것이 더 중요하다. 리스크 관리는 자동매매 시스템의 가장 핵심적인 모듈이다.
Survival matters more than profit. Risk management is the most critical module in any automated trading system.
| 기법 | Technique | 설명 | Description | 예시 | Example |
|---|---|---|---|---|---|
| Stop-Loss | 손실이 기준치에 도달하면 자동 매도 | Auto-sell when loss hits threshold | -2% ~ -5% |
||
| 포지션 사이징 | Position Sizing | 한 종목에 전체 자본의 일부만 투입 | Invest only a portion of capital per stock | 종목당 최대 10% |
Max 10% per stock |
| 일일 한도 | Daily Limit | 하루 최대 손실 도달 시 거래 중단 | Stop trading when daily max loss is reached | 일일 손실 -3% 도달 시 중단 |
Stop at -3% daily loss |
| 분산 투자 | Diversification | 여러 종목/전략에 분산하여 리스크 축소 | Spread across multiple stocks/strategies to reduce risk | 3~5개 종목 동시 운용 | Run 3-5 stocks simultaneously |
생존 규칙: "한 번의 거래로 전체 자본의 2% 이상을 잃지 않는다." 이 단순한 규칙 하나만 지켜도 파산 확률이 극적으로 줄어든다.
Survival rule: "Never lose more than 2% of total capital on a single trade." This one simple rule dramatically reduces the probability of ruin.
| 구분 | Category | 장기 투자 | Long-term | 단타 매매 | Day Trading |
|---|---|---|---|---|---|
| 보유 기간 | Holding Period | 수개월~수년 | Months to years | 수분~당일 | Minutes to same day |
| 매매 빈도 | Trade Frequency | 월 1~2회 | 1-2 per month | 일 5~50회 | 5-50 per day |
| 전략 | Strategy | 밸류, 모멘텀, 배당 | Value, momentum, dividend | 변동성 돌파, 스캘핑 | Volatility breakout, scalping |
| 인프라 | Infrastructure | cron + 일배치 | Cron + daily batch | 실시간 스트리밍, 저지연 | Real-time streaming, low latency |
| 수수료 영향 | Fee Impact | 미미 | Minimal | 수익률에 큰 영향 | Significant impact on returns |
| 자동화 난이도 | Automation Difficulty | 쉬움 | Easy | 어려움 (지연, 예외처리) | Hard (latency, error handling) |
초보자 권장: 장기 투자 자동화부터 시작하라. 일배치로 충분하고, 실시간 처리의 복잡성 없이 시스템 구축 경험을 쌓을 수 있다. 단타는 충분한 경험 후에 도전.
Beginner advice: Start with long-term investment automation. Daily batch is sufficient, and you gain system-building experience without real-time complexity. Attempt day trading only after sufficient experience.
| 계층 | Layer | 기술 | Technology | 용도 | Purpose |
|---|---|---|---|---|---|
| 언어 | Language | Python, TypeScript | 전략 개발(Python), UI/API(TypeScript) | Strategy dev (Python), UI/API (TypeScript) | |
| 브로커 API | Broker API | KIS Open API, Kiwoom | 한국 주식 주문, 시세 조회 | Korean stock orders, quote queries | |
| 데이터 | Data | PostgreSQL, Redis | 시세 저장(PG), 캐시/세션(Redis) | Quote storage (PG), cache/session (Redis) | |
| ML | ML | scikit-learn, XGBoost, PyTorch | 전략 모델 학습, 종목 선별 | Strategy model training, stock selection | |
| 인프라 | Infra | Railway, Vercel, Docker | 봇 배포(Railway), UI(Vercel), 로컬 개발(Docker) | Bot deploy (Railway), UI (Vercel), local dev (Docker) | |
| 모니터링 | Monitoring | Slack, Telegram, Grafana | 매매 알림, 시스템 상태 대시보드 | Trade alerts, system status dashboard | |
| AI 에이전트 | AI Agent | Claude Code, LLM API | 전략 분석, 종목 선별, 코드 생성 | Strategy analysis, stock selection, code generation |
자동매매 시스템을 구축하고 운영할 때 반드시 알아야 할 위험 요소들이다.
These are the risk factors you must understand when building and operating an automated trading system.
실전 투입 전 필수: (1) 최소 3개월 모의투자 검증, (2) 소액으로 시작, (3) 모든 매매 기록 보존, (4) 비상 정지 버튼(kill switch) 구현. 이 네 가지를 건너뛰면 큰 손실을 볼 수 있다.
Before going live: (1) Minimum 3 months paper trading validation, (2) Start with small capital, (3) Preserve all trade records, (4) Implement an emergency kill switch. Skipping these four can lead to significant losses.