Phase 1: - Real-time signal alerts (Discord/Telegram webhook) - Trading journal with entry/exit tracking - Position sizing calculator (Fixed/Kelly/ATR) Phase 2: - Pension asset allocation (DC/IRP 70% risk limit) - Drawdown monitoring with SVG gauge - Benchmark dashboard (portfolio vs KOSPI vs deposit) Phase 3: - Tax benefit simulation (Korean pension tax rules) - Correlation matrix heatmap - Parameter optimizer with grid search + overfit detection
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""
|
|
Benchmark comparison API endpoints.
|
|
"""
|
|
from typing import List
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.api.deps import CurrentUser
|
|
from app.schemas.benchmark import (
|
|
BenchmarkCompareResponse,
|
|
BenchmarkIndexInfo,
|
|
BenchmarkType,
|
|
PeriodType,
|
|
)
|
|
from app.services.benchmark import BenchmarkService
|
|
|
|
router = APIRouter(prefix="/api/benchmark", tags=["benchmark"])
|
|
|
|
|
|
@router.get("/indices", response_model=List[BenchmarkIndexInfo])
|
|
async def list_indices():
|
|
"""사용 가능한 벤치마크 목록 반환."""
|
|
return [
|
|
BenchmarkIndexInfo(
|
|
code="kospi",
|
|
name="KOSPI",
|
|
description="코스피 종합지수",
|
|
),
|
|
BenchmarkIndexInfo(
|
|
code="deposit",
|
|
name="정기예금",
|
|
description="정기예금 금리 (연 3.5%)",
|
|
),
|
|
]
|
|
|
|
|
|
@router.get("/compare/{portfolio_id}", response_model=BenchmarkCompareResponse)
|
|
async def compare_with_benchmark(
|
|
portfolio_id: int,
|
|
current_user: CurrentUser,
|
|
db: Session = Depends(get_db),
|
|
benchmark: BenchmarkType = Query(BenchmarkType.KOSPI),
|
|
period: PeriodType = Query(PeriodType.ONE_YEAR),
|
|
):
|
|
"""포트폴리오 성과를 벤치마크와 비교."""
|
|
service = BenchmarkService(db)
|
|
try:
|
|
result = service.compare_with_benchmark(
|
|
portfolio_id=portfolio_id,
|
|
benchmark_type=benchmark.value,
|
|
period=period.value,
|
|
user_id=current_user.id,
|
|
)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
|
|
return result
|