콘텐츠로 건너뛰기
Reddit

효율적인 백테스트 방법 공유하기 🕒

r/Daytrading 조회 3
원문 보기 →
💡

백테스트는 전략의 실효성을 확인하는 중요한 과정이지만 느리게 진행되면 시간과 노력이 많이 듭니다. 빠르고 효율적인 백테스트 방식을 통해 더 많은 기간과 데이터를 신속하게 검증할 수 있다는 점에서 의미가 큽니다. 투자자들은 본인의 전략에 맞는 최적의 백테스트 방법과 현실적인 데이터 환경을 고민하는데 집중해야 합니다.

저도 전략들을 백테스트하려고 하는데 한 달치만 해도 시간이 너무 오래 걸려서 방법을 찾고 있었습니다. 여러 개의 코드나 봇을 가지고 있는데, 매번 너무 많은 봉(bar) 데이터를 불러와서 시간이 너무 소모돼요. 다른 분들은 어떻게 빠르게 백테스트를 하는지 궁금합니다. 혹시 더 빠르고 짧은 시간에 검증할 수 있는 방법이 있을까요?

💬 원문 댓글 (4)

u/Ima**************** ▲ 1
TOS에서는 저도 몇 시간씩 걸립니다. 전통적인 방법으로 '온디맨드' 기능을 켜고 과거 데이터를 하루 단위로 한참씩 살펴보는 편이에요.
원문 보기
It takes hours for me on TOS. I do it the old school way of turning on the “on demand” feature and going through the historic data day by day.
u/Nat**************** ▲ 1
저는 데이터 소스에서 과거 데이터를 모두 수집하는 코드나 봇을 만들었어요. 관심 있는 가격대나 티커 볼륨, 델타, OHLC 같은 필요한 정보를 전부 기록하고 파일로 저장시켜 둡니다. 그리고 또 다른 코드가 이 데이터를 읽고 계산하면서 본인의 봇을 연결해 백테스트를 하도록 했죠. 하루 정도 걸려서 만든 결과, 7년치 티커 완벽 데이터를 20분 정도만에 백테스트할 수 있었어요. 물론 봇 성격에 따라 다릅니다. 만약 차트의 모든 시점을 모두 거래한다면 시간이 더 걸릴 수도 있겠죠.
원문 보기
Create a code/bot that looks through historical data from a data source. Have it log all the relevant levels, and any other information you need like tick based volume, delta, OHLC, etc. have it cache this data into a file. Have another code be a medium or a backtesting engine that reads and computes the data and then can insert your bot to backtest. Took me a day and I can backtest 7 years of tick perfect data in like 20 minutes. Well it depends on your bot I guess. May take awhile if you’re looking to trade at every single point on the chart 24/7.
u/pic************ ▲ 1
TOS가 느린 이유는 티커별로 하나하나 차트를 재생하면서 모든 봉을 렌더링하기 때문인데, 그래서 한 달치 데이터도 몇 시간씩 걸립니다. 빠르게 백테스트하는 방법 세 가지를 소개할게요. 첫째, Python의 벡터화 백테스트를 활용하는 겁니다. vectorbt, Backtrader, Freqtrade 같은 라이브러리가 넘파이 배열을 이용해 봉 단위 반복 대신 한 번에 계산해서 5분봉 1년치도 몇 초 만에 처리해요. 둘째, 티커별 재생 없이 OHLCV 데이터를 미리 불러와서 벡터화 신호 함수로 처리하는 방법입니다. 훨씬 빠릅니다(100배 이상 속도 차이). 셋째, 모든 기간을 다 돌리기보다는 변동성이 큰 몇 달과 조용한 몇 달만 골라서 테스트하는 것이 현실적이죠. 그리고 백테스트할 때 수수료를 0으로 잡거나 같은 봉에서 채결된 것으로 가정하는 경우가 많아서 실제 거래 결과와 차이가 크고, 한 종목이나 기간에만 맞춰서 조정하면 과최적화가 쉽다는 점도 조심해야 합니다. 이럴 때는 60% 구간으로 학습하고 나머지 40% 구간으로 검증하는 '워크포워드' 방법이 가장 간단한 해결책입니다.
원문 보기
TOS is slow because it replays tick-by-tick through the charting engine. Every bar is rendered. It's visual, which is why you can step through it, but that's why it takes hours for a month of data. Three faster paths:

1. **Vectorized Python backtesting.** Libraries like vectorbt, Backtrader, or Freqtrade use numpy arrays to run the whole backtest in one matrix operation instead of looping bar by bar. A year of 5m data runs in seconds, not hours. Steeper learning curve but it's how quants actually work.
2. **Pre-load OHLCV, skip the tick replay.** Most strategies don't need tick-level data. Pull the candles for your coin/TF into a dataframe once, then iterate with a vectorized signal function. Same backtest, 100x faster.
3. **Stop backtesting everything over every period.** Pick your 3-5 most volatile months and 3-5 calmer months. If a strategy works on both, it's more likely real. Testing 36 months at once is also 36x slower.

Two things to watch for regardless of tool: most retail backtests default to zero fees and same-candle fills, which makes every strategy look better than it actually trades. And if you're testing on one coin/period and tweaking until it works, you're overfitting without realizing it. Walk-forward (train on 60%, test on the 40% you haven't looked at) is the cheapest fix for that.
u/Hel********* ▲ 1
저는 Gemini와 Oanda 데이터를 씁니다. 특히 Oanda 데이터는 무료예요. Gemini는 Oanda API와 바로 연결할 수 있어서 가격 데이터를 따로 엑셀에 저장할 필요도 없습니다.
원문 보기
Use Gemini and oanda data. Oanda data is free. Gemini can talk directly to the oanda API. No need to create an excel database of prices.

댓글 (0)

로그인하고 댓글을 작성하세요.

아직 댓글이 없습니다.