52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import numpy as np
|
||
from scipy.signal import stft
|
||
from datetime import datetime, timedelta
|
||
from typing import Optional, Any, List, Dict
|
||
|
||
from src.core_data import Bar, Order
|
||
from src.indicators.base_indicators import Indicator
|
||
from src.indicators.indicators import Empty, NormalizedATR, AtrVolatility
|
||
from src.strategies.base_strategy import Strategy
|
||
|
||
|
||
# =============================================================================
|
||
# 策略实现 (SpectralTrendStrategy)
|
||
# =============================================================================
|
||
|
||
class TestConnectionStrategy(Strategy):
|
||
"""
|
||
频域能量相变策略 - 捕获肥尾趋势
|
||
|
||
核心哲学:
|
||
1. 显式傅里叶变换: 直接分离低频(趋势)、高频(噪音)能量
|
||
2. 相变临界点: 仅当低频能量占比 > 阈值时入场
|
||
3. 低频交易: 每月仅2-5次信号,持仓数日捕获肥尾
|
||
4. 完全参数化: 无硬编码,适配任何市场时间结构
|
||
|
||
参数说明:
|
||
- bars_per_day: 市场每日K线数量 (e.g., 23 for 15min US markets)
|
||
- low_freq_days: 低频定义下限 (天), 默认2.0
|
||
- high_freq_days: 高频定义上限 (天), 默认1.0
|
||
"""
|
||
|
||
def __init__(
|
||
self,
|
||
context: Any,
|
||
main_symbol: str,
|
||
enable_log: bool,
|
||
):
|
||
super().__init__(context, main_symbol, enable_log)
|
||
# --- 内部状态变量 ---
|
||
self.main_symbol = main_symbol
|
||
|
||
|
||
def on_open_bar(self, open_price: float, symbol: str):
|
||
self.log(f'on open bar: {symbol}')
|
||
|
||
def on_init(self):
|
||
super().on_init()
|
||
|
||
|
||
def on_rollover(self, old_symbol: str, new_symbol: str):
|
||
super().on_rollover(old_symbol, new_symbol)
|