REPO STORY / 레포 이야기
paperswithbacktest/pwb-toolbox
과거 가격 데이터로 거래 전략을 검증하고 실제 거래하는 Python 라이브러리
01 / 뭐 하는 레포인가요?
어떤 일을
도와주나요?
pwb-toolbox는 체계적 거래 전략을 개발하고 백테스트하기 위한 Python 패키지다. 주식, 채권, 암호화폐 등 여러 자산의 일일 가격 데이터를 불러온 뒤, Backtrader를 이용해 거래 전략을 과거 데이터로 시뮬레이션한 후 수익률과 CAGR 같은 성과를 분석할 수 있다. 원하면 Interactive Brokers나 CCXT를 통해 실시간으로도 거래할 수 있다. Python 3.10 이상이 필요하고, 데이터 접근을 위해 Papers With Backtest API 키 또는 Huggingface 계정이 필요하다.
- 주식·채권·상품·암호화폐·ETF·포렉스·지수 등 다양한 자산의 OHLC 일일 가격 데이터 제공
- Backtrader 엔진 기반 거래 전략 백테스팅 및 CAGR·총 수익률 같은 성과 지표 분석
- Interactive Brokers 및 CCXT 암호화폐 거래소 연결로 실시간 거래 자동화 실행
데이터셋 로드, 백테스팅, 성과 분석, 실시간 거래 실행을 한 패키지로 통합하며 140개 이상의 예제 전략을 제공한다.
02 / 내 상황에 맞을까?
이럴 때 써요,
선택 전에 확인해요.
이럴 때 써요
- 양적 거래 연구원이 SPY와 채권의 모멘텀 기반 월간 리밸런싱 전략을 2005년 이후 역사 데이터로 백테스트해 CAGR과 총 수익률을 검증
- 암호화폐 거래자가 CCXT를 통해 다수 거래소의 코인 가격 데이터를 수집한 뒤 자동화 거래 봇을 개발하고 실시간으로 실행
- 포트폴리오 매니저가 Interactive Brokers에 연결해 주식·채권·상품 등 다중 자산 거래 전략을 라이브 트레이딩
이럴 땐 다시 확인해요
아래 준비 조건이 맞지 않으면 먼저 환경을 준비해 주세요.
- Python 3.10 이상
- 데이터 로드용 Papers With Backtest API 키 또는 Huggingface Hub 계정
- 실시간 거래용 Interactive Brokers 또는 CCXT 암호화폐 거래소 계정 (선택)
깃밥 한국어 요약의 활용 예와 준비 조건을 옮겼어요.
03 / 시작하려면
첫 걸음,
차근차근.
준비할 것
- Python 3.10 이상
- 데이터 로드용 Papers With Backtest API 키 또는 Huggingface Hub 계정
- 실시간 거래용 Interactive Brokers 또는 CCXT 암호화폐 거래소 계정 (선택)
- pwb-toolbox 패키지 설치
pip install pwb-toolbox
- 데이터 접근용 인증 설정 (PWB API 키 또는 Huggingface 중 하나)
# 옵션 A: PWB API 키 설정
export PWB_API_KEY="your-api-key-here"
# 또는 옵션 B: Huggingface 로그인
huggingface-cli login
- Python 스크립트에서 데이터 로드
import pwb_toolbox.datasets as pwb_ds
df = pwb_ds.get_pricing(["AAPL", "MSFT", "GOOGL"])
print(df.head())
- 거래 전략 정의 및 백테스트 실행
import numpy as np
import backtrader as bt
import pwb_toolbox.backtesting as pwb_bt
class SimpleMomentum(bt.Indicator):
lines = ("roc",)
params = (("period", 252),)
def __init__(self):
self.lines.roc = bt.indicators.RateOfChange(self.data.close, period=self.p.period)
class MonthlySwitcher(pwb_bt.BaseStrategy):
params = dict(period=252, risky="SPY", safe="BIL", leverage=1.0)
def __init__(self):
super().__init__()
self.mom = {d._name: SimpleMomentum(d, period=self.p.period) for d in self.datas}
self._last_month = -1
def next(self):
super().next()
today = self.datas[0].datetime.date(0)
if today.month == self._last_month:
return
self._last_month = today.month
idx = -1
spy_m = float(self.mom[self.p.risky].roc[idx])
bil_m = float(self.mom[self.p.safe].roc[idx])
hold_risky = (not np.isnan(spy_m)) and (not np.isnan(bil_m)) and (spy_m > bil_m)
targets = {
self.p.risky: self.p.leverage if hold_risky else 0.0,
self.p.safe: 0.0 if hold_risky else self.p.leverage,
}
for d in self.datas:
self.order_target_percent(d, targets.get(d._name, 0.0))
result = pwb_bt.run_strategy(
strategy_cls=MonthlySwitcher,
strategy_kwargs={"period": 252, "risky": "SPY", "safe": "BIL", "leverage": 1.0},
symbols=["SPY", "BIL"],
start_date="2005-01-01",
cash=100_000.0,
)
명령은 기존 요약에 적힌 그대로예요. 실행하거나 설치 성공을 검증하지 않았어요. 공식 소요시간 미제시.
04 / 이웃 레포
어떤 레포와 연결될까요?
비교 연결망의 정적 스냅샷 · 관계 종류와 기록된 근거예요. 현재 공개된 레포만 표시해요.
paperswithbacktest/awesome-systematic-trading ↗
구체 GitHub 토픽 공유: trading-bot,algotrading,quant,trading-strategies,trading-algorithms
repos.topics 교집합 (trading-bot,algotrading,quant,trading-strategies,trading-algorithms)
연결망 스냅샷 원자료 ↗wilsonfreitas/awesome-quant ↗
구체 GitHub 토픽 공유: algotrading,quant,trading-bot,trading-strategies,arbitrage-bot
repos.topics 교집합 (algotrading,quant,trading-bot,trading-strategies,arbitrage-bot)
연결망 스냅샷 원자료 ↗wangzhe3224/awesome-systematic-trading ↗
구체 GitHub 토픽 공유: quant,trading-bot,trading-strategies,algorithmic-trading,alpha
repos.topics 교집합 (quant,trading-bot,trading-strategies,algorithmic-trading,alpha)
연결망 스냅샷 원자료 ↗je-suis-tm/quant-trading ↗
구체 GitHub 토픽 공유: trading-strategies,quantitative-trading,trading-bot,algorithmic-trading,quant
repos.topics 교집합 (trading-strategies,quantitative-trading,trading-bot,algorithmic-trading,quant)
연결망 스냅샷 원자료 ↗kachence/polymm ↗
구체 GitHub 토픽 공유: algorithmic-trading,arbitrage-bot,quant,trading-bot
repos.topics 교집합 (algorithmic-trading,arbitrage-bot,quant,trading-bot)
연결망 스냅샷 원자료 ↗buzzsubash/algo_trading_strategies_india ↗
구체 GitHub 토픽 공유: algorithmic-trading,trading-algorithms,trading-strategies,algotrading
repos.topics 교집합 (algorithmic-trading,trading-algorithms,trading-strategies,algotrading)
연결망 스냅샷 원자료 ↗