
Python調(diào)用Google Bard API 完整指南
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"])
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)
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)
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 和工具。