feat: 프로젝트 개요 및 컴포넌트별 명세, 로드맵 등 문서 추가
This commit is contained in:
177
components/phase1/strategy.md
Normal file
177
components/phase1/strategy.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# strategy - 전략 관리
|
||||
|
||||
## 개요
|
||||
|
||||
**strategy** 컴포넌트는 전략 등록, 버전 관리, 신호 생성, 백테스트를 담당합니다.
|
||||
|
||||
### 책임
|
||||
|
||||
- 전략 코드/메타데이터 등록 및 버전 관리
|
||||
- 시장 데이터 기반 매매 신호 생성
|
||||
- 신호를 주문으로 변환
|
||||
- 백테스트 실행 및 성과 지표 계산
|
||||
- 파라미터 관리 및 검증
|
||||
|
||||
### 의존성
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
Strategy[strategy] --> Data[data]
|
||||
Strategy --> Risk[risk]
|
||||
Strategy --> DB[(Database)]
|
||||
|
||||
Scheduler[scheduler] --> Strategy
|
||||
Analytics[analytics] --> Strategy
|
||||
|
||||
style Strategy fill:#2196F3,color:#fff
|
||||
```
|
||||
|
||||
## 주요 기능
|
||||
|
||||
### 1. 전략 등록 및 버전 관리
|
||||
|
||||
```typescript
|
||||
registerStrategy(strategy: StrategyDefinition): Strategy
|
||||
updateStrategy(id: string, version: StrategyVersion): Strategy
|
||||
getStrategy(id: string, version?: string): Strategy
|
||||
```
|
||||
|
||||
- 전략 코드와 파라미터 메타데이터를 저장합니다.
|
||||
- 새 버전은 불변으로 보존하고 변경 이력을 추적합니다.
|
||||
|
||||
### 2. 전략 실행 엔진
|
||||
|
||||
```typescript
|
||||
calculateSignals(strategyId: string, marketData: MarketData): Signal[]
|
||||
generateOrders(containerId: string, signals: Signal[]): Order[]
|
||||
```
|
||||
|
||||
- 전략 신호를 생성하고 현재 포지션과 목표 포지션 차이로 주문을 계산합니다.
|
||||
|
||||
### 3. 백테스트
|
||||
|
||||
```typescript
|
||||
runBacktest(config: BacktestConfig): BacktestResult
|
||||
calculateMetrics(backtestResult: BacktestResult): PerformanceMetrics
|
||||
```
|
||||
|
||||
- 거래 비용과 슬리피지를 반영해 성과 지표를 산출합니다.
|
||||
|
||||
### 4. 파라미터 관리
|
||||
|
||||
```typescript
|
||||
getParameters(strategyId: string): Parameter[]
|
||||
setParameters(strategyId: string, params: Record<string, any>): void
|
||||
```
|
||||
|
||||
- 파라미터 타입/범위를 검증하고 실행 컨텍스트에 반영합니다.
|
||||
|
||||
### 전략 인터페이스
|
||||
|
||||
```typescript
|
||||
interface StrategyInterface {
|
||||
initialize(context: StrategyContext): void
|
||||
generateSignals(data: MarketData): Signal[]
|
||||
|
||||
onMarketOpen?(): void
|
||||
onMarketClose?(): void
|
||||
onOrderFilled?(order: Order): void
|
||||
}
|
||||
```
|
||||
|
||||
## 데이터 모델
|
||||
|
||||
```typescript
|
||||
interface Strategy {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
category: 'ASSET_ALLOCATION' | 'MOMENTUM' | 'VALUE' | 'ARBITRAGE' | 'CUSTOM'
|
||||
versions: StrategyVersion[]
|
||||
currentVersion: string
|
||||
parameters: Parameter[]
|
||||
requiredData: string[]
|
||||
createdBy: string
|
||||
createdAt: Date
|
||||
isPublic: boolean
|
||||
}
|
||||
|
||||
interface StrategyVersion {
|
||||
version: string
|
||||
code: string
|
||||
changelog?: string
|
||||
createdAt: Date
|
||||
backtestResults?: BacktestResult[]
|
||||
}
|
||||
|
||||
interface Signal {
|
||||
symbol: string
|
||||
action: 'BUY' | 'SELL' | 'HOLD'
|
||||
targetWeight?: number
|
||||
targetQuantity?: number
|
||||
reason?: string
|
||||
confidence?: number
|
||||
generatedAt: Date
|
||||
}
|
||||
|
||||
interface BacktestConfig {
|
||||
strategyId: string
|
||||
strategyVersion: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
initialCapital: number
|
||||
universe: string[]
|
||||
benchmark?: string
|
||||
costs: {
|
||||
commission: number
|
||||
slippage: number
|
||||
}
|
||||
}
|
||||
|
||||
interface BacktestResult {
|
||||
strategyId: string
|
||||
config: BacktestConfig
|
||||
equity: {
|
||||
date: Date
|
||||
value: number
|
||||
cash: number
|
||||
positions: Record<string, number>
|
||||
}[]
|
||||
trades: {
|
||||
date: Date
|
||||
symbol: string
|
||||
action: 'BUY' | 'SELL'
|
||||
quantity: number
|
||||
price: number
|
||||
commission: number
|
||||
}[]
|
||||
metrics: PerformanceMetrics
|
||||
runAt: Date
|
||||
}
|
||||
```
|
||||
|
||||
## API 명세
|
||||
|
||||
### POST /api/strategies
|
||||
전략 등록
|
||||
|
||||
### GET /api/strategies/:strategyId
|
||||
전략 조회 (version 파라미터 지원)
|
||||
|
||||
### POST /api/strategies/:strategyId/backtests
|
||||
백테스트 실행
|
||||
|
||||
## 구현 고려사항
|
||||
|
||||
- 전략 코드 저장 시 보안 검토 및 샌드박스 실행 환경을 고려합니다.
|
||||
- 파라미터 변경은 감사 로그에 기록합니다.
|
||||
|
||||
## 관련 문서
|
||||
|
||||
- [시스템 개요](../../docs/01-overview.md)
|
||||
- [공통 데이터 모델](../../docs/03-data-models.md)
|
||||
|
||||
### 관련 컴포넌트
|
||||
- [data - 데이터 관리](./data.md)
|
||||
- [risk - 리스크 관리](./risk.md)
|
||||
- [scheduler - 실행 스케줄러](./scheduler.md)
|
||||
Reference in New Issue
Block a user