fix: 数据源路由修复与因子计算改进
1. 修复期货路由逻辑:NYMEX期货(.NYM)走YFinance而非Tushare 2. 添加SSH隧道路径修复(原引擎) 3. 因子计算只使用close列(处理部分指数只有收盘价的情况) 4. 添加数据不足和缺失率剔除日志 收益对比: - 原引擎(剔除国债): 累计1804%, 调仓459次 - 新框架: 累计772%, 调仓1276次 差异原因待查: - 国债剔除逻辑不同 - 调仓频率差异
This commit is contained in:
@@ -113,7 +113,8 @@ class HybridDataSource:
|
||||
Optional[pd.DataFrame], # etf_nav_data: ETF净值
|
||||
Optional[pd.DataFrame], # benchmark_data: 基准数据
|
||||
List[str], # valid_codes: 有效代码列表
|
||||
Dict[str, pd.DataFrame] # index_ohlcv_data: 原始OHLCV数据
|
||||
Dict[str, pd.DataFrame], # index_ohlcv_data: 原始OHLCV数据
|
||||
Dict[str, str] # etf_code_map: {指数代码: ETF代码} 映射
|
||||
]:
|
||||
"""
|
||||
批量获取数据
|
||||
@@ -125,7 +126,7 @@ class HybridDataSource:
|
||||
end_date: 结束日期
|
||||
|
||||
Returns:
|
||||
(index_data, etf_data, etf_nav_data, benchmark_data, valid_codes, index_ohlcv_data)
|
||||
(index_data, etf_data, etf_nav_data, benchmark_data, valid_codes, index_ohlcv_data, etf_code_map)
|
||||
"""
|
||||
if end_date is None:
|
||||
end_date = datetime.now().strftime('%Y-%m-%d')
|
||||
@@ -247,7 +248,7 @@ class HybridDataSource:
|
||||
benchmark_data.index = pd.to_datetime(benchmark_data.index, utc=True).tz_localize(None).normalize()
|
||||
print(f"\n✓ 基准 {benchmark_code}: {len(benchmark_data)} 条")
|
||||
|
||||
return index_data, etf_data, etf_nav_data, benchmark_data, valid_codes, index_ohlcv_data
|
||||
return index_data, etf_data, etf_nav_data, benchmark_data, valid_codes, index_ohlcv_data, etf_codes
|
||||
|
||||
def __enter__(self):
|
||||
self._start_tunnel()
|
||||
|
||||
@@ -226,8 +226,10 @@ class TushareSource:
|
||||
return code.endswith(".SH") or code.endswith(".SZ") or code.endswith(".SS") or code.endswith(".CSI")
|
||||
|
||||
def is_futures(self, code: str) -> bool:
|
||||
"""判断是否为期货"""
|
||||
return ".SHF" in code or ".NYM" in code or ".DCE" in code or ".CZC" in code
|
||||
"""判断是否为中国期货(仅支持上期所、大商所、郑商所)"""
|
||||
# 只支持中国交易所期货(.SHF上期所、.DCE大商所、.CZC郑商所)
|
||||
# NYMEX (.NYM) 和 ICE (.ICE) 走 YFinance
|
||||
return ".SHF" in code or ".DCE" in code or ".CZC" in code
|
||||
|
||||
def fetch(self, code: str, start_date: str, end_date: str) -> Optional[pd.DataFrame]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user