使用 yfinance 的资产负债表没有像雅虎财经那样的“总债务”

问题描述 投票:0回答:4

我正在尝试使用 yfinance 访问公司的“总债务”行以计算实际利率,但在创建的资产上使用 .balancesheet、.balance_sheet 或 .get_balance_sheet 时它不会显示股票代码对象。

例如,这是雅虎财经上“AAPL”的资产负债表: enter image description here

但是如果我使用 yfinance,我就不会看到“总债务”:

import yfinance as yf
ticker_object = yf.Ticker('AAPL')
balancesheet = ticker_object.balancesheet
print(balancesheet)

看不到“总债务”行。 enter image description here

(我知道完整的表格没有被捕获,我的屏幕很小,但你可以相信我它不在那里)

我发现的另一个解决方法是,我可以只获取“短期长期债务”,然后从表中添加“长期债务”,但有两个问题:

  • 对于像 MSFT 这样的公司,如果你这样做,它不会加到雅虎财经上显示的“总债务”中。
  • 对于像 SNOW 或 FB 这样的公司,使用 yfinance 时甚至不会出现“短期长期债务”和“长期债务”行。

因此,我认为能够从雅虎财经的表格中访问“总债务”行是解决此问题的最快方法。只是我用 yfinance 找不到它。

我还知道,在股票代码对象上使用 .info 时,字典中有一个“总债务”键,但这是最近的季度值,而不是我要查找的年度值。

python python-3.x pandas yfinance
4个回答
2
投票

我做了一个简单的函数来直接从finance.yahoo.com grep数据

import pandas as pd
import requests
from datetime import datetime
from bs4 import BeautifulSoup

def get_balance_sheet_from_yfinance_web(ticker):
    url = f"https://finance.yahoo.com/quote/GOOG/balance-sheet?p={ticker}"
    header = {'Connection': 'keep-alive',
                'Expires': '-1',
                'Upgrade-Insecure-Requests': '1',
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) \
                AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'
                }
        
    r = requests.get(url, headers=header)
    html = r.text
    soup = BeautifulSoup(html, "html.parser")

    div = soup.find_all('div', attrs={'class': 'D(tbhg)'})
    if len(div) < 1:
        print("Fail to retrieve table column header")
        exit(0)

    col = []
    for h in div[0].find_all('span'):
        text = h.get_text()
        if text != "Breakdown":
            col.append( datetime.strptime(text, "%m/%d/%Y") )
    
    df = pd.DataFrame(columns=col)
    for div in soup.find_all('div', attrs={'data-test': 'fin-row'}):
        i = 0
        idx = ""
        val = []
        for h in div.find_all('span'):
            if i == 0:
                idx = h.get_text()
            else:
                num = int(h.get_text().replace(",", "")) * 1000
                val.append( num )
            i += 1
        row = pd.DataFrame([val], columns=col, index=[idx] )
        df = df.append(row)

    return df

这是输出

print( get_balance_sheet_from_yfinance_web("GOOG") )
                                           2021-12-31    2020-12-31    2019-12-31    2018-12-31
Total Assets                             359268000000  319616000000  275909000000  232792000000
Total Liabilities Net Minority Interest  107633000000   97072000000   74467000000   55164000000
Total Equity Gross Minority Interest     251635000000  222544000000  201442000000  177628000000
Total Capitalization                     264479000000  236476000000  205400000000  181578000000
Common Stock Equity                      251635000000  222544000000  201442000000  177628000000
Capital Lease Obligations                 15551000000   12840000000   12009000000      62000000
Net Tangible Assets                      227262000000  199924000000  178839000000  157520000000
Working Capital                          123889000000  117462000000  107357000000  101056000000
Invested Capital                         264479000000  236476000000  205400000000  181578000000
Tangible Book Value                      227262000000  199924000000  178839000000  157520000000
Total Debt                                28395000000   26772000000   15967000000    4012000000
Share Issued                                662121000     675222000     688335000     695556000
Ordinary Shares Number                      662121000     675222000     688335000     695556000

2
投票

在雅虎财经 v3/统计中,financialData 部分下有一个“totalDeb”行。 您的差异可能是由于总债务中考虑的租赁义务造成的。但是,如果您的目的是计算实际利率,则应仅考虑“短期长期债务”和“长期债务”行。


1
投票

根据我的经验和理解,资产负债表不像损益表,需要将其相加才能进行TTM。因此,当前季度资产负债表就是该公司目前的情况。因此,总债务价值截至报告日期。


0
投票

我发现 yfinance 现在包含“资产负债表”数据框,这是一种更简单的方法。 例子: googl = yf.Ticker("GOOGL")

谷歌资产负债表 2023-12-31 ... 2019-12-31 库存股数量 0.0 ... NaN 普通股数量 12460000000.0 ... NaN 已发行股票 12460000000.0 ... NaN 债务总额 28504000000.0 ... NaN 有形账面价值 254181000000.0 ... NaN ………… 呆账应收账款备抵 -771000000.0 ... NaN 应收账款总额 48735000000.0 ... NaN 现金 现金等价物和短期投资 110916000000.0 ... NaN 其他短期投资 86868000000.0 ... NaN 现金及现金等价物 24048000000.0 ... NaN [74 行 x 5 列]

© www.soinside.com 2019 - 2024. All rights reserved.