【发布时间】: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