# 獲取 Apple 公司的歷史數(shù)據(jù)
apple_data = get_data("AAPL", start_date="01/01/2020", end_date="01/01/2021", interval="1d")

# 打印數(shù)據(jù)
print(apple_data)

(三)獲取股票基本面數(shù)據(jù)

from yahoo_fin.stock_info import get_quote_table

# 獲取 Microsoft 公司的基本面數(shù)據(jù)
msft_quote = get_quote_table("MSFT")

# 打印市盈率(PE Ratio)
print("PE Ratio:", msft_quote["PE Ratio (TTM)"])

# 打印股息收益率(Forward Dividend & Yield)
print("Forward Dividend & Yield:", msft_quote["Forward Dividend & Yield"])

(四)獲取股票財(cái)務(wù)報(bào)表數(shù)據(jù)

from yahoo_fin.stock_info import get_income_statement, get_balance_sheet, get_cash_flow

# 獲取 Amazon 公司的財(cái)務(wù)報(bào)表數(shù)據(jù)
amazon_income = get_income_statement("AMZN")
amazon_balance = get_balance_sheet("AMZN")
amazon_cash_flow = get_cash_flow("AMZN")

# 打印收入報(bào)表數(shù)據(jù)
print("Income Statement:")
print(amazon_income)

# 打印資產(chǎn)負(fù)債表數(shù)據(jù)
print("\nBalance Sheet:")
print(amazon_balance)

# 打印現(xiàn)金流量表數(shù)據(jù)
print("\nCash Flow Statement:")
print(amazon_cash_flow)

(五)獲取期權(quán)數(shù)據(jù)

from yahoo_fin.options import get_calls, get_puts, get_expiration_dates

# 獲取 Apple 公司的期權(quán)到期日
expiration_dates = get_expiration_dates("AAPL")
print("Expiration Dates:", expiration_dates)

# 獲取 Apple 公司的看漲期權(quán)數(shù)據(jù)(以第一個(gè)到期日為例)
calls_data = get_calls("AAPL", expiration_dates[0])
print("\nCalls Data:")
print(calls_data)

# 獲取 Apple 公司的看跌期權(quán)數(shù)據(jù)(以第一個(gè)到期日為例)
puts_data = get_puts("AAPL", expiration_dates[0])
print("\nPuts Data:")
print(puts_data)

六、總結(jié)

Yahoo Finance API 是獲取金融數(shù)據(jù)的強(qiáng)大工具,盡管存在一些不足之處,但其免費(fèi)、數(shù)據(jù)豐富、易于上手等優(yōu)點(diǎn)使其在金融數(shù)據(jù)分析和量化交易領(lǐng)域有著廣泛的應(yīng)用。隨著非官方庫的不斷發(fā)展和完善,以及與其他金融數(shù)據(jù) API 的競爭和互補(bǔ),Yahoo Finance API 將繼續(xù)在金融數(shù)據(jù)領(lǐng)域發(fā)揮重要作用。然而,在使用過程中,我們也需要注意其穩(wěn)定性、數(shù)據(jù)質(zhì)量和完整性等問題,并根據(jù)實(shí)際需求選擇合適的 API 和工具。

上一篇:

智能旅行API:你的完美旅行規(guī)劃助手

下一篇:

手把手教你使用盤古API
#你可能也喜歡這些API文章!

我們有何不同?

API服務(wù)商零注冊

多API并行試用

數(shù)據(jù)驅(qū)動選型,提升決策效率

查看全部API→
??

熱門場景實(shí)測,選對API

#AI文本生成大模型API

對比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力

25個(gè)渠道
一鍵對比試用API 限時(shí)免費(fèi)

#AI深度推理大模型API

對比大模型API的邏輯推理準(zhǔn)確性、分析深度、可視化建議合理性

10個(gè)渠道
一鍵對比試用API 限時(shí)免費(fèi)