【问题标题】:Is there a way to fetch historical nifty option data for particular strike price?有没有办法获取特定执行价格的历史漂亮期权数据?
【发布时间】:2022-01-12 10:13:11
【问题描述】:

我正在分析特定执行价格从特定日期到到期日的精美历史期权数据。假设 25/11/2021 是星期四(期权到期日是星期四),我想分析 2021 年 11 月 15 日的数据,这是 2021 年 11 月 18 日(星期四)执行价格的星期一。因此开始日期为 15/11/2021,结束日期为 25/11/2021,到期日期为 18/11/2021(星期四),行使价为 2021 年 11 月 18 日。我可以手动执行此操作,但我无法连续星期四在 for 循环中执行此操作。我附上了下面的代码。我的代码中是否有任何错误,或者有没有办法获取连续星期四的选项数据?

for yr in year_list:
    for mnth in month_list:
        exp_dt= list (get_expiry_date(year=yr, month = mnth))
        exp_dt.sort()
        strike = nifty_data.loc[nifty_data['Date'].isin(exp_dt)]
        strikeprice = list (strike['Close'])
        for s, e in zip(strikeprice, exp_dt):
            prev_exp_dt = e - timedelta(days=10)
            expi = e - timedelta(days = 7)
            nifty_opt = get_history(symbol = 'NIFTY',
                                       start = prev_exp_dt, end = e,
                                       index = True, option_type = 'PE',
                                       strike_price = float(s),
                                       expiry_date = expi)
            option_data = option_data.append(nifty_opt)
            nifty_opt = get_history(symbol = 'NIFTY',
                                   start = prev_exp_dt, end = e,
                                   index = True, option_type = 'CE',
                                   strike_price = float(s),
                                   expiry_date = expi)
            
            option_data = option_data.append(nifty_opt)
        
   

我得到上述代码的空数据框。

【问题讨论】:

    标签: python pandas loops options stock


    【解决方案1】:

    感谢小伙伴们花时间查看我的帖子。

    我明白了!以下是代码:

    for yr in yr_list:
        for mnth in month_list:
            exp_dt= list (get_expiry_date(year=yr, month = mnth))
            exp_dt.sort()
            strike = nifty_data.loc[nifty_data['Date'].isin(exp_dt)]
            strikeprice = list (strike['Strike'])
            for e in exp_dt:
                prev_exp_dt = e - timedelta(days =3)
                for s in strikeprice:
                    nifty_opt = get_history(symbol = 'NIFTY',
                                               start = prev_exp_dt, end = e,
                                               index = True, option_type = 'PE',
                                               strike_price = float(s),
                                               expiry_date = e)
                    option_data = option_data.append(nifty_opt)
                    nifty_opt = get_history(symbol = 'NIFTY',
                                               start = prev_exp_dt, end = e,
                                               index = True, option_type = 'CE',
                                               strike_price = float(s),
                                               expiry_date = e)
                    option_data = option_data.append(nifty_opt)
    

    再次感谢您!希望对你也有帮助!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      相关资源
      最近更新 更多