feat: 프로젝트 기본 구조 구축
This commit is contained in:
@@ -1,202 +1,27 @@
|
||||
from typing import Dict, Any
|
||||
import time
|
||||
import random
|
||||
import math
|
||||
from .base import BaseQuantStrategy, strategy
|
||||
"""
|
||||
전략 구현체 통합 모듈
|
||||
|
||||
모든 전략 구현체를 임포트하여 레지스트리에 등록합니다.
|
||||
실제 구현은 strategies/impls/ 하위 모듈에 분리되어 있습니다.
|
||||
"""
|
||||
|
||||
@strategy
|
||||
class MovingAverageCrossover(BaseQuantStrategy):
|
||||
"""이동평균선 교차 전략"""
|
||||
# 각 카테고리별 전략 임포트
|
||||
from .impls.trend_following import MovingAverageCrossover
|
||||
from .impls.mean_reversion import RSIMeanReversion
|
||||
from .impls.volatility_breakout import BollingerBandBreakout
|
||||
from .impls.asset_allocation import BoldAssetAllocation
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "MovingAverageCrossover"
|
||||
# __all__에 등록하여 외부에서 임포트 가능하도록 설정
|
||||
__all__ = [
|
||||
# Trend Following
|
||||
'MovingAverageCrossover',
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return "단기 이동평균선이 장기 이동평균선을 상향 돌파할 때 매수, 하향 돌파할 때 매도하는 전략"
|
||||
# Mean Reversion
|
||||
'RSIMeanReversion',
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
return "1.0.0"
|
||||
# Volatility Breakout
|
||||
'BollingerBandBreakout',
|
||||
|
||||
@property
|
||||
def default_parameters(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"short_window": 20,
|
||||
"long_window": 50,
|
||||
"initial_capital": 100000,
|
||||
"position_size": 0.1
|
||||
}
|
||||
|
||||
def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
|
||||
required_params = ["short_window", "long_window", "initial_capital"]
|
||||
for param in required_params:
|
||||
if param not in parameters:
|
||||
return False
|
||||
|
||||
if parameters["short_window"] >= parameters["long_window"]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def execute(self, parameters: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||
if parameters is None:
|
||||
parameters = self.default_parameters
|
||||
|
||||
if not self.validate_parameters(parameters):
|
||||
raise ValueError("Invalid parameters")
|
||||
|
||||
# 시뮬레이션 실행
|
||||
time.sleep(1) # 실행 시간 시뮬레이션
|
||||
|
||||
# 모의 결과 생성
|
||||
profit_rate = random.uniform(-0.15, 0.25)
|
||||
trades_count = random.randint(15, 60)
|
||||
win_rate = random.uniform(0.45, 0.75)
|
||||
|
||||
return {
|
||||
"strategy": self.name,
|
||||
"version": self.version,
|
||||
"profit_loss": round(parameters["initial_capital"] * profit_rate, 2),
|
||||
"profit_rate": round(profit_rate * 100, 2),
|
||||
"trades_executed": trades_count,
|
||||
"win_rate": round(win_rate, 3),
|
||||
"execution_time": "1.2s",
|
||||
"parameters_used": parameters,
|
||||
"final_capital": round(parameters["initial_capital"] * (1 + profit_rate), 2)
|
||||
}
|
||||
|
||||
|
||||
@strategy
|
||||
class RSIMeanReversion(BaseQuantStrategy):
|
||||
"""RSI 평균회귀 전략"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "RSIMeanReversion"
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return "RSI 지표를 이용한 평균회귀 전략. RSI가 과매수/과매도 구간에서 반대 방향으로 거래"
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
return "1.0.0"
|
||||
|
||||
@property
|
||||
def default_parameters(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"rsi_period": 14,
|
||||
"oversold_threshold": 30,
|
||||
"overbought_threshold": 70,
|
||||
"initial_capital": 100000,
|
||||
"position_size": 0.05
|
||||
}
|
||||
|
||||
def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
|
||||
required_params = ["rsi_period", "oversold_threshold", "overbought_threshold", "initial_capital"]
|
||||
for param in required_params:
|
||||
if param not in parameters:
|
||||
return False
|
||||
|
||||
if not (0 < parameters["oversold_threshold"] < parameters["overbought_threshold"] < 100):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def execute(self, parameters: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||
if parameters is None:
|
||||
parameters = self.default_parameters
|
||||
|
||||
if not self.validate_parameters(parameters):
|
||||
raise ValueError("Invalid parameters")
|
||||
|
||||
# 시뮬레이션 실행
|
||||
time.sleep(1.5) # 실행 시간 시뮬레이션
|
||||
|
||||
# 모의 결과 생성
|
||||
profit_rate = random.uniform(-0.10, 0.18)
|
||||
trades_count = random.randint(25, 80)
|
||||
win_rate = random.uniform(0.40, 0.65)
|
||||
|
||||
return {
|
||||
"strategy": self.name,
|
||||
"version": self.version,
|
||||
"profit_loss": round(parameters["initial_capital"] * profit_rate, 2),
|
||||
"profit_rate": round(profit_rate * 100, 2),
|
||||
"trades_executed": trades_count,
|
||||
"win_rate": round(win_rate, 3),
|
||||
"execution_time": "1.5s",
|
||||
"parameters_used": parameters,
|
||||
"final_capital": round(parameters["initial_capital"] * (1 + profit_rate), 2),
|
||||
"max_drawdown": round(random.uniform(0.05, 0.20), 3)
|
||||
}
|
||||
|
||||
|
||||
@strategy
|
||||
class BollingerBandBreakout(BaseQuantStrategy):
|
||||
"""볼린저 밴드 돌파 전략"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "BollingerBandBreakout"
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return "볼린저 밴드 상한선 돌파시 매수, 하한선 돌파시 매도하는 돌파 전략"
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
return "2.0.0"
|
||||
|
||||
@property
|
||||
def default_parameters(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"period": 20,
|
||||
"std_dev": 2.0,
|
||||
"initial_capital": 100000,
|
||||
"position_size": 0.08,
|
||||
"stop_loss": 0.05
|
||||
}
|
||||
|
||||
def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
|
||||
required_params = ["period", "std_dev", "initial_capital"]
|
||||
for param in required_params:
|
||||
if param not in parameters:
|
||||
return False
|
||||
|
||||
if parameters["std_dev"] <= 0 or parameters["period"] <= 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def execute(self, parameters: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||
if parameters is None:
|
||||
parameters = self.default_parameters
|
||||
|
||||
if not self.validate_parameters(parameters):
|
||||
raise ValueError("Invalid parameters")
|
||||
|
||||
# 시뮬레이션 실행
|
||||
time.sleep(2) # 실행 시간 시뮬레이션
|
||||
|
||||
# 모의 결과 생성
|
||||
profit_rate = random.uniform(-0.20, 0.30)
|
||||
trades_count = random.randint(10, 40)
|
||||
win_rate = random.uniform(0.35, 0.70)
|
||||
|
||||
return {
|
||||
"strategy": self.name,
|
||||
"version": self.version,
|
||||
"profit_loss": round(parameters["initial_capital"] * profit_rate, 2),
|
||||
"profit_rate": round(profit_rate * 100, 2),
|
||||
"trades_executed": trades_count,
|
||||
"win_rate": round(win_rate, 3),
|
||||
"execution_time": "2.0s",
|
||||
"parameters_used": parameters,
|
||||
"final_capital": round(parameters["initial_capital"] * (1 + profit_rate), 2),
|
||||
"sharpe_ratio": round(random.uniform(0.5, 2.5), 2),
|
||||
"volatility": round(random.uniform(0.15, 0.35), 3)
|
||||
}
|
||||
# Asset Allocation
|
||||
'BoldAssetAllocation',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user