提问人:widemangojutsu 提问时间:10/7/2023 更新时间:10/7/2023 访问量:29
Ticker 对象没有属性“stats” 与 yfinance 相关的问题
Ticker object has no attribute 'stats' yfinance related issue
问:
这是我得到的错误。 “ AttributeError: 'Ticker' 对象没有属性 'stats' ”
我假设它没有创建 asset.stats() 供它访问或存储 ['价格']['常规市场价格']
还是与yFinance的tickers.tickers问题有关,无法评估?访问多个代码的 yfinance Ticker 对象会导致 AttributeError
有人可以帮忙回答这个问题或引导我朝着正确的方向前进吗? 谢谢你:)(我的第一篇文章在这里)
def option_chains(ticker):
"""
"""
asset = yf.Ticker(ticker)
expirations = asset.options
last_price = asset.stats()['price']['regularMarketPrice']
chains = pd.DataFrame()
for expiration in expirations:
# tuple of two dataframes
opt = asset.option_chain(expiration)
calls = opt.calls
calls['OptionType'] = "call"
puts = opt.puts
puts['OptionType'] = "put"
chain = pd.concat([calls, puts])
chain['Expiration'] = pd.to_datetime(expiration, utc=True)
chains = pd.concat([chains, chain])
chains['UnderlyingSymbol'] = ticker
chains['UnderlyingPrice'] = last_price
return chains
# define a Options object
options_obj = option_chains(underlying_symbol)
# let's pickle the dataframe so we don't have to hit the network every time
options_obj.to_pickle('options_frame.pickle')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
\The_46-Page_Ultimate_Guide_to_Pricing_Options_and_Implied_Volatility_With_Python_PDF__code__live_options_data.ipynb Cell 44 line 2
1 # define a Options object
----> 2 options_obj = option_chains(underlying_symbol)
4 # let's pickle the dataframe so we don't have to hit the network every time
5 options_obj.to_pickle('options_frame.pickle')
\The_46-Page_Ultimate_Guide_to_Pricing_Options_and_Implied_Volatility_With_Python_PDF__code__live_options_data.ipynb Cell 44 line 7
4 asset = yf.Ticker(ticker)
5 expirations = asset.options
----> 7 last_price = asset.stats()['price']['regularMarketPrice']
9 chains = pd.DataFrame()
11 for expiration in expirations:
12 # tuple of two dataframes
AttributeError: 'Ticker' object has no attribute 'stats'
我尝试更改资产 = yf。股票代码(ticker)到yf。股票代码(tickers) YF。股票代码(股票代码)
在代码块的第二个块上 options_obj = option_chains(underlying_symbol) underlying_symbol最初是“aapl”,我将其更改为代码“DVN”。
所有其他图表显示/绘制 DVN 信息。
我以为它会存储期权信息。
答: 暂无答案
下一个:对数正常蒙特卡洛
评论