64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
"""Base strategy interface."""
|
|
from abc import ABC, abstractmethod
|
|
from typing import List, Dict
|
|
from decimal import Decimal
|
|
from datetime import datetime
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
class BaseStrategy(ABC):
|
|
"""전략 기본 인터페이스."""
|
|
|
|
def __init__(self, config: Dict = None):
|
|
"""
|
|
초기화.
|
|
|
|
Args:
|
|
config: 전략 설정 딕셔너리
|
|
"""
|
|
self.config = config or {}
|
|
|
|
@abstractmethod
|
|
def select_stocks(self, rebal_date: datetime, db_session: Session) -> List[str]:
|
|
"""
|
|
종목 선정.
|
|
|
|
Args:
|
|
rebal_date: 리밸런싱 날짜
|
|
db_session: 데이터베이스 세션
|
|
|
|
Returns:
|
|
선정된 종목 코드 리스트
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_prices(
|
|
self,
|
|
tickers: List[str],
|
|
date: datetime,
|
|
db_session: Session
|
|
) -> Dict[str, Decimal]:
|
|
"""
|
|
종목 가격 조회.
|
|
|
|
Args:
|
|
tickers: 종목 코드 리스트
|
|
date: 조회 날짜
|
|
db_session: 데이터베이스 세션
|
|
|
|
Returns:
|
|
{ticker: price} 딕셔너리
|
|
"""
|
|
pass
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
"""전략 이름."""
|
|
return self.__class__.__name__
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
"""전략 설명."""
|
|
return self.__doc__ or ""
|