如何使用 yahoo_fin 获取单个期权合约的数据

How to use yahoo_fin to get data for an individual option contract

我正在尝试使用 yahoo_fin 来查找期权组合的增量,我有计算增量的代码,但它目前获取的是期权数据链,而不是每个期权的数据投资组合中的单个选项。有没有一种方法可以一次获取一个特定选项的数据?在我的代码中,我获得了特定到期日的特定股票的期权,有没有办法也使用罢工?

这是我当前的代码:

from yahoo_fin import options
from yahoo_fin import stock_info as si
import numpy as np
from scipy.stats import norm
import pandas as pd
from datetime import *

stock = input("Enter stock symbol: Ex:QQQ ")
Day = int(input("Enter option expiration day: Ex:8 "))
month = int(input("Enter option expiration month: Ex:11 "))
year = int(input("Enter option expiration year: Ex:2021 "))
today = date.today()
future = date(year,month,Day)
expiry = future
str(future - today)
pd.set_option("display.max_rows", None, "display.max_columns", None)
options.get_options_chain(stock)
chain = options.get_options_chain(stock,expiry)

r = .025
S = si.get_live_price(stock)
K = chain["calls"].Strike
t = float((future - today).days)
T = t/365
s = chain["calls"]['Implied Volatility']
sigma = chain["calls"]["Implied Volatility"].apply(lambda x: float(x[:-1]) / 100)

def delta_calc(r, S, K, T, sigma):
    d1 = (np.log(S/K)+(r+sigma**2/2)*T)/(sigma*np.sqrt(T))
    delta_calc = norm.cdf(d1, 0, 1) 
    return delta_calc

print("Option Delta is: ", (delta_calc(r, S, K, T, sigma)))

http://theautomatic.net/2019/04/17/how-to-get-options-data-with-python/

我认为这可能有所帮助。

“要获取特定到期日期的数据,我们可以将需要的任何日期传递给 get_options_chain 方法。支持多种日期格式。”它还显示罢工