Initial commit: Django quantitative strategy executor
- Django 5.2.7 project with Python 3.13+ - Quant strategy management system with version control - Strategy implementations using registry pattern - API endpoints for strategy listing and execution - Sample strategy implementations (MovingAverage, RSI, BollingerBand) - Async strategy execution with status tracking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
110
strategies/base.py
Normal file
110
strategies/base.py
Normal file
@@ -0,0 +1,110 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Any
|
||||
import json
|
||||
|
||||
|
||||
class BaseQuantStrategy(ABC):
|
||||
"""
|
||||
퀀트 전략의 기본 클래스
|
||||
모든 전략 구현체는 이 클래스를 상속받아야 합니다.
|
||||
"""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str:
|
||||
"""전략 이름"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def description(self) -> str:
|
||||
"""전략 설명"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def version(self) -> str:
|
||||
"""전략 버전"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def default_parameters(self) -> Dict[str, Any]:
|
||||
"""기본 파라미터"""
|
||||
return {}
|
||||
|
||||
@abstractmethod
|
||||
def execute(self, parameters: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
전략을 실행합니다.
|
||||
|
||||
Args:
|
||||
parameters: 실행 파라미터
|
||||
|
||||
Returns:
|
||||
실행 결과
|
||||
"""
|
||||
pass
|
||||
|
||||
def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
파라미터 유효성 검사
|
||||
|
||||
Args:
|
||||
parameters: 검사할 파라미터
|
||||
|
||||
Returns:
|
||||
유효성 검사 결과
|
||||
"""
|
||||
return True
|
||||
|
||||
|
||||
class StrategyRegistry:
|
||||
"""전략 구현체 레지스트리"""
|
||||
|
||||
_strategies = {}
|
||||
|
||||
@classmethod
|
||||
def register(cls, strategy_class: BaseQuantStrategy):
|
||||
"""전략 구현체를 레지스트리에 등록"""
|
||||
strategy_instance = strategy_class()
|
||||
key = f"{strategy_instance.name}:{strategy_instance.version}"
|
||||
cls._strategies[key] = strategy_class
|
||||
return strategy_class
|
||||
|
||||
@classmethod
|
||||
def get_strategy(cls, name: str, version: str) -> BaseQuantStrategy:
|
||||
"""전략 구현체를 가져옵니다"""
|
||||
key = f"{name}:{version}"
|
||||
strategy_class = cls._strategies.get(key)
|
||||
if strategy_class:
|
||||
return strategy_class()
|
||||
raise ValueError(f"Strategy {key} not found in registry")
|
||||
|
||||
@classmethod
|
||||
def list_strategies(cls) -> Dict[str, Dict[str, Any]]:
|
||||
"""등록된 모든 전략 목록을 반환합니다"""
|
||||
strategies = {}
|
||||
for key, strategy_class in cls._strategies.items():
|
||||
strategy_instance = strategy_class()
|
||||
name = strategy_instance.name
|
||||
if name not in strategies:
|
||||
strategies[name] = {
|
||||
'name': name,
|
||||
'description': strategy_instance.description,
|
||||
'versions': []
|
||||
}
|
||||
strategies[name]['versions'].append({
|
||||
'version': strategy_instance.version,
|
||||
'default_parameters': strategy_instance.default_parameters
|
||||
})
|
||||
return strategies
|
||||
|
||||
@classmethod
|
||||
def get_strategy_key(cls, name: str, version: str) -> str:
|
||||
"""전략 키를 생성합니다"""
|
||||
return f"{name}:{version}"
|
||||
|
||||
|
||||
def strategy(cls):
|
||||
"""전략 구현체를 자동으로 레지스트리에 등록하는 데코레이터"""
|
||||
return StrategyRegistry.register(cls)
|
||||
Reference in New Issue
Block a user