Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于执行价格筛选出期权链表_Python_Options - Fatal编程技术网

Python 基于执行价格筛选出期权链表

Python 基于执行价格筛选出期权链表,python,options,Python,Options,我试图使用“执行价格”列筛选出选项链表。我试图得到上一个收盘价,并用它过滤出与上一个收盘价相差20美元(+&-)的期权。这是我目前掌握的代码。我一直在为&:“float”和“float”获取不支持的操作数类型。非常感谢您的帮助。谢谢 #Set inputs Ticker = "AAPL" Period = "6mo" Expiration_date = '2021-04-16' #Get historical market data from Yahoo

我试图使用“执行价格”列筛选出选项链表。我试图得到上一个收盘价,并用它过滤出与上一个收盘价相差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)