Files
system-specs/components/phase1/risk.md

170 lines
3.7 KiB
Markdown

# risk - 리스크 관리
## 개요
**risk** 컴포넌트는 사전 주문 검증과 포지션 리스크 모니터링을 담당합니다.
### 책임
- 주문 전 리스크 체크 (잔고, 포지션 한도, 레버리지)
- 포지션 리스크 지표 계산 (VaR, 베타, 집중도)
- 손절/익절 조건 관리 및 트리거 평가
- 리스크 한도 설정 및 위반 감지
### 의존성
```mermaid
graph LR
Risk[risk] --> Mgmt[mgmt]
Risk --> Balance[balance]
Risk --> Data[data]
Risk --> DB[(Database)]
Scheduler[scheduler] --> Risk
Monitor[monitor] --> Risk
style Risk fill:#E53935,color:#fff
```
## 주요 기능
### 1. 사전 주문 검증
```typescript
validateOrder(order: Order, container: Container): RiskCheckResult
validateOrderBatch(orders: Order[], container: Container): RiskCheckResult[]
```
- 잔고 충분성, 포지션 사이즈, 집중도, 레버리지를 검증합니다.
### 2. 포지션 리스크 모니터링
```typescript
calculatePositionRisk(containerId: string): PositionRisk
checkRiskLimits(containerId: string): LimitViolation[]
```
### 3. 손절/익절 관리
```typescript
setStopLoss(containerId: string, symbol: string, config: StopLossConfig): void
setTakeProfit(containerId: string, symbol: string, level: number): void
checkStopConditions(containerId: string): StopTrigger[]
```
### 4. 리스크 한도 설정
```typescript
setRiskLimits(containerId: string, limits: RiskLimits): void
getRiskProfile(containerId: string): RiskProfile
```
### 5. 포트폴리오 리스크 분석
```typescript
calculatePortfolioVaR(containerId: string, confidence: number, horizon: number): VaRResult
calculateCorrelationMatrix(containerId: string): CorrelationMatrix
stressTest(containerId: string, scenarios: Scenario[]): StressTestResult[]
```
## 데이터 모델
```typescript
interface RiskLimits {
containerId: string
position: {
maxSinglePositionPct: number
maxSectorPct: number
maxTotalLeverage: number
}
loss: {
maxDailyLossPct: number
maxDrawdownPct: number
stopLossEnabled: boolean
}
exposure: {
maxLongExposure: number
maxShortExposure: number
maxGrossExposure: number
}
}
interface RiskCheckResult {
passed: boolean
violations: {
rule: string
severity: 'BLOCKING' | 'WARNING'
message: string
currentValue: number
limitValue: number
}[]
recommendations?: string[]
}
interface PositionRisk {
containerId: string
positions: {
symbol: string
marketValue: number
weightPct: number
VaR95: number
beta: number
sector: string
}[]
portfolio: {
totalValue: number
totalVaR95: number
beta: number
correlationRisk: number
}
limits: {
type: string
current: number
limit: number
utilizationPct: number
}[]
calculatedAt: Date
}
interface StopLossConfig {
type: 'FIXED' | 'TRAILING' | 'TIME_BASED'
fixedPrice?: number
fixedPct?: number
trailingPct?: number
holdingPeriodDays?: number
autoExecute: boolean
}
interface VaRResult {
confidence: number
horizon: number
VaR: number
VaRPct: number
method: 'HISTORICAL' | 'PARAMETRIC' | 'MONTE_CARLO'
calculatedAt: Date
}
```
## API 명세
### POST /api/risk/check
주문 리스크 체크
### GET /api/risk/containers/:containerId
리스크 프로필 조회
## 구현 고려사항
- 리스크 위반은 monitor 알림과 연동합니다.
- 한도 변경은 감사 로그로 추적합니다.
## 관련 문서
- [공통 데이터 모델](../../docs/03-data-models.md)
- [주요 워크플로우](../../docs/04-workflows.md)
### 관련 컴포넌트
- [mgmt - 컨테이너 관리](./mgmt.md)
- [balance - 계좌 관리](./balance.md)
- [strategy - 전략 관리](./strategy.md)