|
|
@@ -112,11 +112,21 @@ class DeepITMBullSpreadStrategy:
|
|
|
"""获取指定月份的期权合约信息"""
|
|
|
underlying_code = self.get_underlying_code()
|
|
|
|
|
|
+ # 根据标的ETF代码动态确定交易所代码
|
|
|
+ if underlying_code in ['510050', '510300']:
|
|
|
+ exchange_code = 'XSHG' # 上海交易所
|
|
|
+ elif underlying_code in ['159915']:
|
|
|
+ exchange_code = 'XSHE' # 深圳交易所
|
|
|
+ else:
|
|
|
+ exchange_code = 'XSHG' # 默认上海交易所
|
|
|
+
|
|
|
+ print(f" 期权筛选: 标的代码={underlying_code}, 交易所={exchange_code}")
|
|
|
+
|
|
|
# 基于自然月份计算期权筛选范围
|
|
|
query_date = trade_date.date() if hasattr(trade_date, 'date') else trade_date
|
|
|
current_year = query_date.year
|
|
|
current_month = query_date.month
|
|
|
- # print(f" 期权筛选调试: month_idx={month_idx}, query_date={query_date}, 当前年月={current_year}-{current_month:02d}")
|
|
|
+ print(f" 期权筛选调试: month_idx={month_idx}, query_date={query_date}, 当前年月={current_year}-{current_month:02d}")
|
|
|
|
|
|
# 计算目标月份
|
|
|
if month_idx == 0:
|
|
|
@@ -156,7 +166,7 @@ class DeepITMBullSpreadStrategy:
|
|
|
opt.OPT_CONTRACT_INFO.list_date
|
|
|
).filter(
|
|
|
opt.OPT_CONTRACT_INFO.contract_type == contract_type,
|
|
|
- opt.OPT_CONTRACT_INFO.exchange_code == 'XSHG',
|
|
|
+ opt.OPT_CONTRACT_INFO.exchange_code == exchange_code,
|
|
|
opt.OPT_CONTRACT_INFO.last_trade_date >= start_date,
|
|
|
opt.OPT_CONTRACT_INFO.last_trade_date <= end_date,
|
|
|
opt.OPT_CONTRACT_INFO.list_date < query_date
|
|
|
@@ -182,6 +192,7 @@ class DeepITMBullSpreadStrategy:
|
|
|
|
|
|
# 获取期权合约信息
|
|
|
contract_info = self.get_option_contracts(trade_date, month_idx, 'CO')
|
|
|
+ # print(f"contract_info: {contract_info}")
|
|
|
|
|
|
if contract_info.empty:
|
|
|
failure_reason = "无可用认购期权合约"
|
|
|
@@ -250,8 +261,8 @@ class DeepITMBullSpreadStrategy:
|
|
|
}
|
|
|
candidates.append(candidate)
|
|
|
|
|
|
- # if not silent:
|
|
|
- # print(f" 行权价 {contract['exercise_price']:.3f}: 期权价格 {option_price:.4f}, 剩余天数 {days_to_expiry}")
|
|
|
+ if not silent:
|
|
|
+ print(f" 行权价 {contract['exercise_price']:.3f}: 期权价格 {option_price:.4f}, 剩余天数 {days_to_expiry}")
|
|
|
|
|
|
except Exception as e:
|
|
|
price_error_count += 1
|
|
|
@@ -462,8 +473,6 @@ class DeepITMBullSpreadStrategy:
|
|
|
|
|
|
return buy_call, sell_call, None
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def calculate_bull_spread_profit(self, buy_call, sell_call, contract_size=None):
|
|
|
"""计算牛差组合的盈利情况"""
|
|
|
if contract_size is None:
|
|
|
@@ -494,6 +503,7 @@ class DeepITMBullSpreadStrategy:
|
|
|
|
|
|
# 安全获取合约数量
|
|
|
contract_size = self.get_safe_contract_size()
|
|
|
+ print(f"合约数量: {contract_size}")
|
|
|
|
|
|
# 计算盈利信息
|
|
|
profit_info = self.calculate_bull_spread_profit(buy_call, sell_call, contract_size)
|
|
|
@@ -1264,8 +1274,8 @@ class StrategyConfig:
|
|
|
def __init__(self):
|
|
|
# ETF标的配置字典
|
|
|
self.etf_symbols = {
|
|
|
- '50ETF': '510050.XSHG', # 上证50ETF
|
|
|
- '300ETF': '510300.XSHG', # 沪深300ETF
|
|
|
+ # '50ETF': '510050.XSHG', # 上证50ETF
|
|
|
+ # '300ETF': '510300.XSHG', # 沪深300ETF
|
|
|
'创业板ETF': '159915.XSHE' # 创业板ETF
|
|
|
}
|
|
|
|