![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
이 안내서에서는 Coingecko API를 활용하는 암호화 백 테스트 도구를 구축하여 다양한 거래 전략을 쉽게 테스트 할 수 있습니다.
This guide will help you build a crypto backtesting tool using the CoinGecko API. With this tool, you can easily test various trading strategies, ranging from simple price-based approaches like buying the dip to more complex strategies utilizing technical analysis and indicators.
이 안내서는 Coingecko API를 사용하여 암호화 백 테스트 도구를 구축하는 데 도움이됩니다. 이 도구를 사용하면 DIP 구매와 같은 간단한 가격 기반 접근 방식에서 기술 분석 및 지표를 활용하는보다 복잡한 전략에 이르기까지 다양한 거래 전략을 쉽게 테스트 할 수 있습니다.
As always, you'll find a link to the GitHub repository at the end of the article, allowing you to dive right in and start experimenting.
언제나 그렇듯이 기사 끝에 Github 저장소에 대한 링크를 찾으므로 바로 뛰어 들어 실험을 시작할 수 있습니다.
What is Crypto Backtesting?
암호화 백 테스트 란 무엇입니까?
In the world of trading, crypto backtesting refers to the process of evaluating a trading strategy using historical market data to assess how it would have performed in the past.
거래 세계에서 암호화 백 테스트는 과거 시장 데이터를 사용하여 거래 전략을 평가하여 과거에 어떻게 수행되었는지 평가하는 과정을 말합니다.
This enables traders to gauge the profitability, risk, and overall effectiveness of a strategy before deploying it in live trading. By simulating trades based on past data, traders can refine their approach, identify potential weaknesses, and gain confidence in their strategy without risking real money.
이를 통해 거래자는 전략을 라이브 거래에 배포하기 전에 전략의 수익성, 위험 및 전반적인 효과를 측정 할 수 있습니다. 과거 데이터를 기반으로 거래를 시뮬레이션함으로써 거래자는 자신의 접근 방식을 개선하고 잠재적 약점을 식별하며 실제 돈을 위험에 빠뜨리지 않고 전략에 대한 신뢰를 얻을 수 있습니다.
Pre-requisites
사전 반품
Before we start building our crypto backtesting tool, we'll need the following:
암호화 백 테스트 도구를 구축하기 전에 다음과 같은 것이 필요합니다.
To obtain a CoinGecko API key, head over to the Developer’s Dashboard and click on +Add New Key in the top right corner. For detailed instructions on generating and setting up your key, refer to this guide.
Coingecko API 키를 얻으려면 개발자의 대시 보드로 가서 오른쪽 상단에 새 키를 추가하십시오. 키 생성 및 설정에 대한 자세한 지침은이 안내서를 참조하십시오.
We'll be using the OHLC Chart within Time Range endpoint to fetch historical prices, which is available on the Analyst plan and above. For a free alternative, you may use this endpoint instead. The only difference is that, on the Demo endpoint, you cannot specify a time range.
우리는 시간 범위 내에서 OHLC 차트를 사용하여 분석가 이상에서 이용할 수있는 역사 가격을 가져올 것입니다. 무료 대안의 경우이 엔드 포인트를 대신 사용할 수 있습니다. 유일한 차이점은 데모 엔드 포인트에서 시간 범위를 지정할 수 없다는 것입니다.
Step 1. Set Up Your Environment
1 단계. 환경을 설정하십시오
To get started, create an empty directory, which will serve as the root of your project. Within the root directory, let's create a new virtual environment that will allow us to install our requirements locally, without making any changes to the global Python environment.
시작하려면 빈 디렉토리를 만들어 프로젝트의 근본으로 사용됩니다. 루트 디렉토리 내에서 글로벌 파이썬 환경을 변경하지 않고 요구 사항을 로컬로 설치할 수있는 새로운 가상 환경을 만들어 봅시다.
Let’s now configure our Python application. Run the following commands to create and activate your environment:
이제 Python 응용 프로그램을 구성하겠습니다. 환경을 생성하고 활성화하기 위해 다음 명령을 실행하십시오.
If you're using VS Code, your IDE may also ask you if you’d like to use the local Python compiler – choose yes.
VS 코드를 사용하는 경우 IDE에서 로컬 Python 컴파일러를 사용하고 싶은지 묻습니다. 예를 선택하십시오.
Installing Requirements
요구 사항 설치
We’re now ready to install our project’s requirements. The easiest way to do this is by copying the file below to your root directory in a file called requirements.txt and then running pip install -r requirements.txt.
이제 프로젝트 요구 사항을 설치할 준비가되었습니다. 이를 수행하는 가장 쉬운 방법은 요구 사항이라는 파일의 루트 디렉토리에 아래 파일을 복사 한 다음 Pip Install -R 요구 사항을 실행하는 것입니다.
Installing Ta-Lib (Optional)
TA-LIB 설치 (선택 사항)
There is one more requirement that we need to install: ta-lib. This is a fantastic Python library for calculating indicator values from raw data. Unlike the requirements above, ta-lib requires us to use the release files and build the package ourselves, otherwise, it will error during installation.
설치해야 할 요구 사항이 하나 더 있습니다 : TA-LIB. 이것은 원시 데이터의 표시 값을 계산하기위한 환상적인 파이썬 라이브러리입니다. 위의 요구 사항과 달리 TA-LIB는 릴리스 파일을 사용하고 패키지를 직접 구축해야합니다. 그렇지 않으면 설치 중에 오류가 발생합니다.
Head over to the project’s release page and select a version that matches your OS, CPU architecture, and Python version. For instance, I’m running 64-bit Windows 11 with Python 3.11 and an x86 CPU architecture. The correct release for me was ta_lib-0.6.0-cp311-cp311-win_amd64.whl.
프로젝트의 릴리스 페이지로 이동하여 OS, CPU 아키텍처 및 파이썬 버전과 일치하는 버전을 선택하십시오. 예를 들어, Python 3.11과 X86 CPU 아키텍처로 64 비트 Windows 11을 실행하고 있습니다. 나에게 올바른 릴리스는 TA_LIB-0.6.0-CP311-CP311-WIN_AMD64.WHL입니다.
To run this on a Macbook with Python 3.11 and an M1 chip or higher, you may use the following release: ta_lib-0.6.0-cp311-cp311-win_arm64.whl. Once you have downloaded the correct version for your machine, drop the file inside your project root. From your project root, install the package using the file you just downloaded.
Python 3.11과 M1 칩 이상의 MacBook 에서이 작업을 실행하려면 다음 릴리스를 사용할 수 있습니다. 컴퓨터의 올바른 버전을 다운로드 한 후에는 프로젝트 루트 내부의 파일을 드롭하십시오. 프로젝트 루트에서 방금 다운로드 한 파일을 사용하여 패키지를 설치하십시오.
For instance: pip install ta_lib-0.6.0-cp311-cp311-win_amd64.whl. This should take care of all the project requirements.
예를 들어 : PIP 설치 ta_lib-0.6.0-cp311-cp311-win_amd64.whl. 이것은 모든 프로젝트 요구 사항을 처리해야합니다.
Create project scaffold
프로젝트 스캐 폴드를 만듭니다
Inside your root directory, create the services and utils directories, alongside an empty .env file and an empty main.py file. It should look like so:
루트 디렉토리 내부에서 빈 .env 파일과 빈 메인 .py 파일과 함께 서비스 및 Utils 디렉토리를 작성하십시오. 그렇게 보일 것입니다 :
Inside your .env file, define a variable called CG_API_KEY and assign your CoinGecko API key as its value. We’ll use this to securely load the key into our app, without hardcoding it in the project files.
.env 파일 내부에서 cg_api_key라는 변수를 정의하고 Coingecko API 키를 그 값으로 할당하십시오. 이를 사용하여 프로젝트 파일에서 하드 코딩하지 않고 키를 앱에 단단히로드합니다.
Step 2. Defining Utilities
2 단계. 유틸리티 정의
Inside the utils directory that we defined, create a file called load_env.py. This will help us load our API key and define any additional configuration options that we may have.
우리가 정의한 Utils 디렉토리 내부에서 load_env.py라는 파일을 만듭니다. 이를 통해 API 키를로드하고 추가 구성 옵션을 정의하는 데 도움이됩니다.
Note that in addition to our API Key, which we’re storing in cg_api_key, we’ve also defined some basic strategy settings such as a take_profit, a stop_loss, an order size, and a total_amount.
CG_API_Key에 저장하는 API 키 외에도 Take_Profit, Stop_Loss, 주문 크기 및 Total_Amount와 같은 기본 전략 설정을 정의했습니다.
Feel free to adjust these settings to suit your needs, and play around with different settings during backtesting to find the best combination of stop loss and take profit for your strategy.
필요에 맞게 이러한 설정을 자유롭게 조정하고 백 테스트 중에 다양한 설정을 통해 스톱 손실의 최상의 조합을 찾고 전략에 대한 이익을 얻으십시오.
The backtesting library can behave unpredictably if the input amount is much smaller than the asset's price. To avoid this, we've set the amount high enough to prevent issues.
입력 금액이 자산 가격보다 훨씬 작은 경우 백 테스트 라이브러리는 예측할 수 없을 정도로 행동 할 수 있습니다. 이를 피하기 위해 문제를 방지 할만 큼 많은 양을 설정했습니다.
부인 성명:info@kdj.com
제공된 정보는 거래 조언이 아닙니다. kdj.com은 이 기사에 제공된 정보를 기반으로 이루어진 투자에 대해 어떠한 책임도 지지 않습니다. 암호화폐는 변동성이 매우 높으므로 철저한 조사 후 신중하게 투자하는 것이 좋습니다!
본 웹사이트에 사용된 내용이 귀하의 저작권을 침해한다고 판단되는 경우, 즉시 당사(info@kdj.com)로 연락주시면 즉시 삭제하도록 하겠습니다.