# 篩選期權

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