根据执行价格过滤掉期权链表

问题描述

我正在尝试使用执行价格列过滤掉期权链表。我正在尝试获取之前的收盘价,并使用它来过滤掉执行价格与之前的收盘价相差 20 美元 (+ & -) 的期权。这是我到目前为止的代码。我不断收到不受支持的 & 操作数类型:'float' 和 'float'。任何帮助深表感谢。谢谢。

#Set inputs
Ticker = "AAPL"
Period = "6mo"
Expiration_date = '2021-04-16'
#Get historical market data from Yahoo Finance. 6 Months of data with 1 day frequency. 
import yfinance as yf
stock = yf.Ticker(Ticker)
hist = stock.history(period=Period)
hist.head()
hist.info()
#Get past and upcoming earnings date
stock.calendar
#Get options data. First step is to get the expiration date,then using one of the expiration date to get the related data.
stock.options
opt = stock.option_chain(Expiration_date)
calls = opt.calls
calls.info()
puts = opt.puts
puts.inf()
#Filter unneccessary option chain data with far away strike prices from current stock price.
prevIoUs_closed = hist['Close'].tail(1)
is_strikeprice= calls['strike']== prevIoUs_closed + 20 & prevIoUs_closed -20
filterd_calls = calls[is_strikeprice]
print(filterd_calls)
print(is_strikeprice)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)