feat: 프로젝트 기본 구조 구축
This commit is contained in:
494
BAA_CURL_EXAMPLES.md
Normal file
494
BAA_CURL_EXAMPLES.md
Normal file
@@ -0,0 +1,494 @@
|
||||
# BAA 전략 API curl 예제
|
||||
|
||||
## 서버 실행
|
||||
|
||||
```bash
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
기본 URL: `http://localhost:8000/api`
|
||||
|
||||
---
|
||||
|
||||
## 1. 사용 가능한 전략 구현체 목록 조회
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8000/api/strategies/implementations/ \
|
||||
-H "Content-Type: application/json" | jq '.'
|
||||
```
|
||||
|
||||
**응답 예시:**
|
||||
```json
|
||||
{
|
||||
"available_implementations": {
|
||||
"BoldAssetAllocation": {
|
||||
"name": "BoldAssetAllocation",
|
||||
"description": "상대 모멘텀과 절대 모멘텀을 결합한 공격적 전술적 자산배분 전략. 카나리아 유니버스 기반 크래시 보호",
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"default_parameters": {
|
||||
"initial_capital": 100000,
|
||||
"variant": "BAA-G12",
|
||||
"offensive_top": 6,
|
||||
"defensive_top": 3,
|
||||
"breadth_param": 1,
|
||||
"transaction_cost": 0.001,
|
||||
"as_of_date": null,
|
||||
"use_real_data": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. BAA-G12 시뮬레이션 모드 (백테스트 결과)
|
||||
|
||||
### 전략 실행 요청
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"parameters": {
|
||||
"initial_capital": 100000,
|
||||
"variant": "BAA-G12",
|
||||
"use_real_data": false
|
||||
}
|
||||
}' | jq '.'
|
||||
```
|
||||
|
||||
**응답:**
|
||||
```json
|
||||
{
|
||||
"execution_id": 1,
|
||||
"status": "pending",
|
||||
"message": "Strategy execution started"
|
||||
}
|
||||
```
|
||||
|
||||
### 실행 결과 조회
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8000/api/executions/1/ | jq '.'
|
||||
```
|
||||
|
||||
**응답 예시:**
|
||||
```json
|
||||
{
|
||||
"execution_id": 1,
|
||||
"strategy": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"status": "completed",
|
||||
"started_at": "2025-10-04T10:30:00Z",
|
||||
"completed_at": "2025-10-04T10:30:02Z",
|
||||
"execution_parameters": {
|
||||
"initial_capital": 100000,
|
||||
"variant": "BAA-G12",
|
||||
"use_real_data": false
|
||||
},
|
||||
"result": {
|
||||
"strategy": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"variant": "BAA-G12",
|
||||
"cagr": 14.6,
|
||||
"max_drawdown": 8.7,
|
||||
"sharpe_ratio": 1.19,
|
||||
"upi": 4.81,
|
||||
"profit_loss": 14600.0,
|
||||
"final_capital": 114600.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. BAA-G4 실제 데이터 모드 (현재 날짜 기준 포트폴리오)
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"parameters": {
|
||||
"initial_capital": 50000,
|
||||
"variant": "BAA-G4",
|
||||
"use_real_data": true,
|
||||
"as_of_date": null
|
||||
}
|
||||
}' | jq '.'
|
||||
```
|
||||
|
||||
**응답:**
|
||||
```json
|
||||
{
|
||||
"execution_id": 2,
|
||||
"status": "pending",
|
||||
"message": "Strategy execution started"
|
||||
}
|
||||
```
|
||||
|
||||
### 결과 조회 (약 10초 후)
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:8000/api/executions/2/ | jq '.'
|
||||
```
|
||||
|
||||
**응답 예시:**
|
||||
```json
|
||||
{
|
||||
"execution_id": 2,
|
||||
"strategy": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"status": "completed",
|
||||
"result": {
|
||||
"strategy": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"variant": "BAA-G4",
|
||||
"mode": "offensive",
|
||||
"as_of_date": "2025-10-04",
|
||||
"canary_status": {
|
||||
"SPY": {
|
||||
"momentum": 0.0854,
|
||||
"is_bad": false
|
||||
},
|
||||
"VWO": {
|
||||
"momentum": 0.1015,
|
||||
"is_bad": false
|
||||
},
|
||||
"VEA": {
|
||||
"momentum": 0.0863,
|
||||
"is_bad": false
|
||||
},
|
||||
"BND": {
|
||||
"momentum": 0.0132,
|
||||
"is_bad": false
|
||||
}
|
||||
},
|
||||
"canary_bad_count": 0,
|
||||
"breadth_threshold": 1,
|
||||
"portfolio": [
|
||||
{
|
||||
"ticker": "VEA",
|
||||
"weight": 100.0,
|
||||
"target_amount": 50000.0,
|
||||
"current_price": 61.06,
|
||||
"shares": 818,
|
||||
"actual_amount": 49947.08
|
||||
}
|
||||
],
|
||||
"total_allocated": 49947.08,
|
||||
"cash_remaining": 52.92,
|
||||
"initial_capital": 50000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 특정 날짜 기준 포트폴리오 (2024-01-31)
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"parameters": {
|
||||
"initial_capital": 100000,
|
||||
"variant": "BAA-G12",
|
||||
"use_real_data": true,
|
||||
"as_of_date": "2024-01-31"
|
||||
}
|
||||
}' | jq '.'
|
||||
```
|
||||
|
||||
**결과 조회:**
|
||||
```bash
|
||||
curl -X GET http://localhost:8000/api/executions/3/ | jq '.'
|
||||
```
|
||||
|
||||
**응답 예시 (방어 모드):**
|
||||
```json
|
||||
{
|
||||
"execution_id": 3,
|
||||
"strategy": "BoldAssetAllocation",
|
||||
"version": "1.0.0",
|
||||
"status": "completed",
|
||||
"result": {
|
||||
"mode": "defensive",
|
||||
"as_of_date": "2024-01-31",
|
||||
"canary_status": {
|
||||
"SPY": {
|
||||
"momentum": 0.0815,
|
||||
"is_bad": false
|
||||
},
|
||||
"VWO": {
|
||||
"momentum": -0.0110,
|
||||
"is_bad": true
|
||||
},
|
||||
"VEA": {
|
||||
"momentum": 0.0350,
|
||||
"is_bad": false
|
||||
},
|
||||
"BND": {
|
||||
"momentum": 0.0169,
|
||||
"is_bad": false
|
||||
}
|
||||
},
|
||||
"canary_bad_count": 1,
|
||||
"portfolio": [
|
||||
{
|
||||
"ticker": "DBC",
|
||||
"weight": 33.33,
|
||||
"current_price": 21.43,
|
||||
"shares": 1555,
|
||||
"actual_amount": 33317.63
|
||||
},
|
||||
{
|
||||
"ticker": "TLT",
|
||||
"weight": 33.33,
|
||||
"current_price": 89.0,
|
||||
"shares": 374,
|
||||
"actual_amount": 33287.61
|
||||
},
|
||||
{
|
||||
"ticker": "LQD",
|
||||
"weight": 33.33,
|
||||
"current_price": 101.69,
|
||||
"shares": 327,
|
||||
"actual_amount": 33253.17
|
||||
}
|
||||
],
|
||||
"total_allocated": 99858.4,
|
||||
"cash_remaining": 141.6
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 모든 전략 변형 예제
|
||||
|
||||
### BAA-G12 (Balanced)
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "BAA-G12",
|
||||
"initial_capital": 100000,
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### BAA-G4 (Aggressive)
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "BAA-G4",
|
||||
"initial_capital": 100000,
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### BAA-G12/T3
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "BAA-G12/T3",
|
||||
"initial_capital": 100000,
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### BAA-G4/T2
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "BAA-G4/T2",
|
||||
"initial_capital": 100000,
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### BAA-SPY
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "BAA-SPY",
|
||||
"initial_capital": 100000,
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 파라미터 커스터마이징
|
||||
|
||||
### 예산 변경
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"initial_capital": 250000,
|
||||
"variant": "BAA-G4",
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### 특정 날짜 + 변형 조합
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"initial_capital": 150000,
|
||||
"variant": "BAA-G12/T3",
|
||||
"use_real_data": true,
|
||||
"as_of_date": "2024-06-30"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 비동기 실행 패턴
|
||||
|
||||
### 1단계: 실행 시작
|
||||
```bash
|
||||
EXEC_ID=$(curl -s -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"initial_capital": 50000,
|
||||
"variant": "BAA-G4",
|
||||
"use_real_data": true
|
||||
}
|
||||
}' | jq -r '.execution_id')
|
||||
|
||||
echo "Execution ID: $EXEC_ID"
|
||||
```
|
||||
|
||||
### 2단계: 상태 폴링
|
||||
```bash
|
||||
while true; do
|
||||
STATUS=$(curl -s http://localhost:8000/api/executions/${EXEC_ID}/ | jq -r '.status')
|
||||
echo "Status: $STATUS"
|
||||
|
||||
if [ "$STATUS" = "completed" ] || [ "$STATUS" = "failed" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
done
|
||||
```
|
||||
|
||||
### 3단계: 최종 결과 조회
|
||||
```bash
|
||||
curl -s http://localhost:8000/api/executions/${EXEC_ID}/ | jq '.result'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. 에러 처리
|
||||
|
||||
### 잘못된 variant
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {
|
||||
"variant": "INVALID",
|
||||
"use_real_data": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
**응답:**
|
||||
```json
|
||||
{
|
||||
"execution_id": 4,
|
||||
"status": "failed",
|
||||
"error_message": "Invalid parameters"
|
||||
}
|
||||
```
|
||||
|
||||
### 누락된 필수 파라미터
|
||||
```bash
|
||||
curl -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"strategy_name": "BoldAssetAllocation",
|
||||
"parameters": {}
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 원라인 실행 + 결과 조회
|
||||
|
||||
```bash
|
||||
# 실행하고 10초 후 자동으로 결과 조회
|
||||
EXEC_ID=$(curl -s -X POST http://localhost:8000/api/strategies/execute/ \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"strategy_name":"BoldAssetAllocation","parameters":{"initial_capital":50000,"variant":"BAA-G4","use_real_data":true}}' \
|
||||
| jq -r '.execution_id') && \
|
||||
echo "Execution ID: $EXEC_ID" && \
|
||||
sleep 10 && \
|
||||
curl -s http://localhost:8000/api/executions/${EXEC_ID}/ | jq '.'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 참고사항
|
||||
|
||||
1. **jq 설치**: JSON 포맷팅을 위해 `jq` 설치 권장
|
||||
```bash
|
||||
# macOS
|
||||
brew install jq
|
||||
|
||||
# Ubuntu/Debian
|
||||
sudo apt-get install jq
|
||||
```
|
||||
|
||||
2. **실행 시간**:
|
||||
- 시뮬레이션 모드: 약 2초
|
||||
- 실제 데이터 모드: 약 5-15초 (데이터 다운로드 시간 포함)
|
||||
|
||||
3. **날짜 형식**: `YYYY-MM-DD` (예: `2024-01-31`)
|
||||
|
||||
4. **초기 자본**: 달러($) 단위
|
||||
|
||||
5. **매수 수량**: 정수 주식만 매수, 잔액은 현금 보유
|
||||
Reference in New Issue
Block a user