And*_*ndy 4 finance python-3.x yahoo-finance yfinance
我一直想知道如何使用 yfinance 获得一系列基本面信息,例如公司的市盈率。多家公司的历史比率。
我努力了
import yfinance as yf
rio=yf.Ticker("RIO.AX")
rio.financials
Run Code Online (Sandbox Code Playgroud)
但我的结果给了我空数据框,有人可以帮忙吗?或我能阅读的任何文档,非常感谢
yfinance 似乎无法再检索公司财务信息(自 2020 年 10 月以来它就不再对我有用)
但是,如果您不反对尝试另一个库,那么可以使用yahoo_fin
pip install yahoo_fin
pip install requests_html
Run Code Online (Sandbox Code Playgroud)
安装后:
import yahoo_fin.stock_info as si
msft_data = si.get_quote_table("MSFT")
Run Code Online (Sandbox Code Playgroud)
该词典如下所示:
{'1y Target Est': 239.71,
'52 Week Range': '132.52 - 232.86',
'Ask': '215.25 x 800',
'Avg. Volume': 31253650.0,
'Beta (5Y Monthly)': 0.87,
'Bid': '215.00 x 900',
"Day's Range": '214.04 - 216.27',
'EPS (TTM)': 6.2,
'Earnings Date': 'Jan 27, 2021 - Feb 01, 2021',
'Ex-Dividend Date': 'Nov 18, 2020',
'Forward Dividend & Yield': '2.24 (1.04%)',
'Market Cap': '1.627T',
'Open': 214.85,
'PE Ratio (TTM)': 34.72,
'Previous Close': 213.87,
'Quote Price': 215.22999572753906,
'Volume': 12886232.0}
Run Code Online (Sandbox Code Playgroud)
过去 12 个月的市盈率在那里,市净率无法通过该库获得。
免责声明:我与上述库没有任何关系,我只是发现当 yfinance 不起作用时它是 yfinance 的有用替代品。
更多信息可以通过此链接找到: https://algotrading101.com/learn/yahoo-finance-api-guide/
小智 5
使用以下代码行会更容易一些。更简单,输出产生一个 pandas df,其尾随和远期市盈率作为 150 个值之一:
\nmicrosoft = yf.Ticker('MSFT')\ndict = microsoft.info\ndf = pd.DataFrame.from_dict(dict,orient='index')\ndf = df.reset_index()\nRun Code Online (Sandbox Code Playgroud)\n输出:
\nindex 0\n0 zip 98052-6399\n1 sector Technology\n2 fullTimeEmployees 181000\n3 longBusinessSummary Microsoft Corporation develops, licenses, and ...\n4 city Redmond\n5 phone 425 882 8080\n6 state WA\n7 country United States\n8 companyOfficers []\n9 website http://www.microsoft.com\n10 maxAge 1\n11 address1 One Microsoft Way\n12 industry Software\xe2\x80\x94Infrastructure\n13 ebitdaMargins 0.48649\n14 profitMargins 0.38515\n15 grossMargins 0.68865\n16 operatingCashflow 81945001984\n17 revenueGrowth 0.22\n18 operatingMargins 0.42143\n19 ebitda 85745000448\n20 targetLowPrice 299.93\n21 recommendationKey buy\n22 grossProfits 115856000000\n23 freeCashflow 49819750400\n24 targetMedianPrice 360\n25 currentPrice 336.07\n26 earningsGrowth 0.489\n27 currentRatio 2.165\n28 returnOnAssets 0.14589\n29 numberOfAnalystOpinions 38\n30 targetMeanPrice 357.27\n31 debtToEquity 51.938\n32 returnOnEquity 0.49303\n33 targetHighPrice 407\n34 totalCash 130584002560\n35 totalDebt 78934999040\n36 totalRevenue 176250994688\n37 totalCashPerShare 17.393\n38 financialCurrency USD\n39 revenuePerShare 23.395\n40 quickRatio 1.961\n41 recommendationMean 1.6\n42 exchange NMS\n43 shortName Microsoft Corporation\n44 longName Microsoft Corporation\n45 exchangeTimezoneName America/New_York\n46 exchangeTimezoneShortName EST\n47 isEsgPopulated False\n48 gmtOffSetMilliseconds -18000000\n49 quoteType EQUITY\n50 symbol MSFT\n51 messageBoardId finmb_21835\n52 market us_market\n53 annualHoldingsTurnover None\n54 enterpriseToRevenue 14.051\n55 beta3Year None\n56 enterpriseToEbitda 28.881\n57 52WeekChange 0.550062\n58 morningStarRiskRating None\n59 forwardEps 10.51\n60 revenueQuarterlyGrowth None\n61 sharesOutstanding 7507979776\n62 fundInceptionDate None\n63 annualReportExpenseRatio None\n64 totalAssets None\n65 bookValue 20.242\n66 sharesShort 49332744\n67 sharesPercentSharesOut 0.0066\n68 fundFamily None\n69 lastFiscalYearEnd 1625011200\n70 heldPercentInstitutions 0.71896\n71 netIncomeToCommon 67882999808\n72 trailingEps 8.939\n73 lastDividendValue 0.56\n74 SandP52WeekChange 0.29114\n75 priceToBook 16.6026\n76 heldPercentInsiders 0.00078\n77 nextFiscalYearEnd 1688083200\n78 yield None\n79 mostRecentQuarter 1632960000\n80 shortRatio 1.97\n81 sharesShortPreviousMonthDate 1632960000\n82 floatShares 7500172144\n83 beta 0.862337\n84 enterpriseValue 2476438192128\n85 priceHint 2\n86 threeYearAverageReturn None\n87 lastSplitDate 1045526400\n88 lastSplitFactor 2:1\n89 legalType None\n90 lastDividendDate 1629244800\n91 morningStarOverallRating None\n92 earningsQuarterlyGrowth 0.476\n93 priceToSalesTrailing12Months 14.316\n94 dateShortInterest 1635465600\n95 pegRatio 2.25\n96 ytdReturn None\n97 forwardPE 31.9762\n98 lastCapGain None\n99 shortPercentOfFloat 0.0066\n100 sharesShortPriorMonth 47171313\n101 impliedSharesOutstanding None\n102 category None\n103 fiveYearAverageReturn None\n104 previousClose 336.72\n105 regularMarketOpen 337.54\n106 twoHundredDayAverage 284.087\n107 trailingAnnualDividendYield 0.0068306\n108 payoutRatio 0.2506\n109 volume24Hr None\n110 regularMarketDayHigh 337.842\n111 navPrice None\n112 averageDailyVolume10Day 21823516\n113 regularMarketPreviousClose 336.72\n114 fiftyDayAverage 310.283\n115 trailingAnnualDividendRate 2.3\n116 open 337.54\n117 toCurrency None\n118 averageVolume10days 21823516\n119 expireDate None\n120 algorithm None\n121 dividendRate 2.48\n122 exDividendDate 1637107200\n123 circulatingSupply None\n124 startDate None\n125 regularMarketDayLow 334.034\n126 currency USD\n127 trailingPE 37.5959\n128 regularMarketVolume 15975249\n129 lastMarket None\n130 maxSupply None\n131 openInterest None\n132 marketCap 2523206778880\n133 volumeAllCurrencies None\n134 strikePrice None\n135 averageVolume 23879857\n136 dayLow 334.034\n137 ask 336.4\n138 askSize 800\n139 volume 15975249\n140 fiftyTwoWeekHigh 338.79\n141 fromCurrency None\n142 fiveYearAvgDividendYield 1.45\n143 fiftyTwoWeekLow 208.16\n144 bid 336.32\n145 tradeable False\n146 dividendYield 0.0074\n147 bidSize 900\n148 dayHigh 337.842\n149 regularMarketPrice 336.07\n150 preMarketPrice 337.5\n151 logo_url https://logo.clearbit.com/microsoft.com\nRun Code Online (Sandbox Code Playgroud)\n