# 筛选期权

get_option_screen(request)

  • 介绍

    期权选股。混合使用标的属性(underlying)与期权属性(option)进行筛选。同一组内不能同时筛选标的属性(underlying)与期权属性(option),SDK 自动按需开新筛选组:默认每条筛选条件 AND 拼接(开新组),同 indicator_type 显式 or_with_previous=True 时与上一条件 OR(同组)。

  • 参数

    参数 类型 说明
    request OptionScreenRequest 期权选股请求对象,构造时必传 market_categories
    • OptionScreenRequest 字段:

      字段 类型 说明
      market_categories list[int] 期权市场品类列表
      page_from int 分页起始位置
      page_count int 单页最大返回数
    • 筛选条件 builder 方法(默认每次调用自动开新筛选组与之前条件 AND;同 indicator_type 显式 or_with_previous=True 时与上一条件 OR 同组。同一组内不能同时筛选标的属性(underlying)与期权属性(option)):

      方法 说明
      add_underlying_filter(indicator_type, values=None, lower=None, upper=None, plate_list=None, parent_plate_id=None, or_with_previous=False) 标的属性筛选
      add_option_filter(indicator_type, values=None, lower=None, upper=None, or_with_previous=False) 期权属性筛选
      new_filter_group() 手动开始新的筛选组
      add_sort(indicator_type, desc=False) 排序
      add_option_retrieve(indicator_type) 声明额外要返回的期权字段
      add_underlying_retrieve(indicator_type) 声明要返回的标的字段
  • 返回

    参数 类型 说明
    ret RET_CODE 接口调用结果
    data tuple 当 ret == RET_OK,返回 (last_page, all_count, DataFrame)
    str 当 ret != RET_OK,返回错误描述
    • 返回 DataFrame 字段:

      字段 类型 说明
      code str 期权代码
      option_name str 期权名称
      strike_price float 行权价
      strike_date str 行权日
      option_type int 认购/认沽
      exercise_type int 行权方式
      expiration_type int 到期类型
      in_the_money bool 是否价内
      left_day int 剩余天数
      price float 期权价格
      mid_price float 中间价
      bid_price float 买价
      ask_price float 卖价
      bid_ask_spread float 买卖价差
      bid_volume int 买量
      ask_volume int 卖量
      bid_ask_volume_ratio float 买卖量比
      change_ratio float 涨跌幅
      volume int 成交量
      turnover float 成交额
      open_interest int 未平仓合约数(持仓量)
      open_interest_market_cap float 持仓市值
      vol_oi_ratio float 成交量/持仓量
      premium float 权利金
      implied_volatility float 隐含波动率
      history_volatility float 历史波动率
      iv_hv_ratio float IV/HV
      delta float 希腊字母 Delta
      gamma float 希腊字母 Gamma
      vega float 希腊字母 Vega
      theta float 希腊字母 Theta
      rho float 希腊字母 Rho
      leverage_ratio float 杠杆比率
      effective_gearing float 有效杠杆
      itm_probability float 价内概率
      buy_to_bep float 买入到盈亏平衡点比率
      sell_to_bep float 卖出到盈亏平衡点比率
      buy_profit_probability float 买入盈利概率
      sell_profit_probability float 卖出盈利概率
      intrinsic_value_per float 内在价值百分比
      time_value_per float 时间价值百分比
      itm_degree float 价内程度
      otm_degree float 价外程度
      otm_probability float 价外概率
      sell_annualized_return float 卖出年化收益率
      interval_return float 卖出区间收益率
      underlying dict 标的信息(仅当调用 add_underlying_retrieve 后返回)
  • Example

from futu import (
    OpenQuoteContext, RET_OK, OptionScreenRequest,
    OptMarketCategory, OptIndicator, OptUnderlyingIndicator,
)

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

# 示例 1:美股标的 IV>30% + 平值附近 CALL
req = OptionScreenRequest(market_categories=[OptMarketCategory.US_STOCK])
req.add_underlying_filter(OptUnderlyingIndicator.IV, lower=0.3)              # 标的 IV ≥ 30%(小数)
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[1])                  # CALL
req.add_option_filter(OptIndicator.DELTA, lower=0.3, upper=0.7)              # Delta 0.3~0.7
req.add_option_filter(OptIndicator.LEFT_DAY, lower=7, upper=60)              # 剩余 7~60 天
req.add_sort(OptIndicator.VOLUME, desc=True)                                 # 成交量降序
req.add_option_retrieve(OptIndicator.DELTA)
req.add_option_retrieve(OptIndicator.VOLUME)
req.page_count = 30

ret, data = quote_ctx.get_option_screen(req)
if ret == RET_OK:
    last_page, all_count, df = data
    print(df[['code', 'option_name', 'delta', 'volume']].head(10))
else:
    print('error: ', data)

# 示例 2:港股按指定标的筛选 + 同时取标的信息
# 注意:STOCK_LIST 接收的是内部 stock_id,需通过 get_market_snapshot/get_static_info 等接口
# 提前取得;下面 54047868453564 即为港股腾讯(00700)的 stock_id
req = OptionScreenRequest(market_categories=[OptMarketCategory.HK_STOCK])
req.add_underlying_filter(OptUnderlyingIndicator.STOCK_LIST,
                          values=[54047868453564])                            # 标的=腾讯
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[1])                   # CALL
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[2],
                      or_with_previous=True)                                  # 与上一条 OR:CALL + PUT
req.add_underlying_retrieve(OptUnderlyingIndicator.IV)
req.add_underlying_retrieve(OptUnderlyingIndicator.MARKET_CAP)
req.add_sort(OptIndicator.OPEN_INTEREST, desc=True)                           # 持仓量降序
req.page_count = 50

ret, data = quote_ctx.get_option_screen(req)

quote_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  • Output
                 code        option_name    delta  volume
0  US.SLV260529C70000  SLV 260529 70.00C  0.52937   45838
1   US.TZA260612C5500   TZA 260612 5.50C  0.37815   40777
2  US.HIVE260717C5000  HIVE 260717 5.00C  0.36626   31104
3  US.NKE260618C45000  NKE 260618 45.00C  0.32579   24046
4    US.SG260618C9500    SG 260618 9.50C  0.39444   19020
1
2
3
4
5
6