feat: Add new files and enhance backtesting functionality
Changes: - Introduced new files for strategy definitions and study names. - Enhanced `backtest_web.py` with functions to handle integer display prices and trade data formatting. - Updated backtesting logic to incorporate end-of-day (EOD) parameters for breakout and momentum strategies. - Added EOD configuration options in the database and parameter search files. Impact: - These changes improve the modularity and usability of the backtesting framework, allowing for better integration of EOD strategies and clearer trade data presentation.
This commit is contained in:
@@ -18,9 +18,9 @@ from datetime import datetime as dt
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from ..engine import momentum_engine as me
|
||||
from ..utils.env import get_env_bool, get_env_float, get_env_int
|
||||
from ..utils.env import get_env_bool, get_env_float, get_env_from_db, get_env_int
|
||||
from ..utils.position_sizing import invest_qty_for_price
|
||||
from .base import BaseStrategy
|
||||
from .base import BaseStrategy, is_live_eod_now
|
||||
|
||||
|
||||
class MomentumStrategy(BaseStrategy):
|
||||
@@ -53,6 +53,8 @@ class MomentumStrategy(BaseStrategy):
|
||||
self.mom_rsi_min = float(base.get("mom_rsi_min", 50.0))
|
||||
self.mom_rsi_max = float(base.get("mom_rsi_max", 80.0))
|
||||
self.max_daily = int(base.get("max_daily", 5))
|
||||
self.eod_enabled = get_env_bool("MOMENTUM_EOD_ENABLED", True)
|
||||
self.eod_hm = get_env_from_db("MOMENTUM_EOD_HM", "15:25")
|
||||
except Exception as e:
|
||||
self.logger.debug("momentum_engine defaults 조회 실패: %s", e)
|
||||
self._engine_params = {}
|
||||
@@ -197,7 +199,12 @@ class MomentumStrategy(BaseStrategy):
|
||||
|
||||
signals: List[Dict] = []
|
||||
now = dt.now()
|
||||
is_eod = (now.hour == 15 and now.minute >= 25) or now.hour > 15
|
||||
is_eod = is_live_eod_now(
|
||||
getattr(self, "eod_enabled", True),
|
||||
getattr(self, "eod_hm", "15:25"),
|
||||
now,
|
||||
default_hm="15:25",
|
||||
)
|
||||
params = dict(self._engine_params or me.get_momentum_defaults_from_db())
|
||||
|
||||
for code, holding in list(self.holdings.items()):
|
||||
|
||||
Reference in New Issue
Block a user