77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""
|
|
평균 회귀(Mean Reversion) 전략 구현체
|
|
|
|
RSI, 볼린저밴드 등 과매수/과매도 구간에서 반대 방향으로 거래하는 전략들을 포함합니다.
|
|
"""
|
|
|
|
from typing import Dict, Any
|
|
import time
|
|
import random
|
|
from ..base import BaseQuantStrategy, strategy
|
|
|
|
|
|
@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)
|
|
}
|