ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

Implement Analysis (no scraping) #2023

Closed Fidasek009 closed 3 months ago

Fidasek009 commented 3 months ago

I implemented most of the analysis page (https://finance.yahoo.com/quote/AAPL/analysis/). As the URL suggests, analysis is just a part of the quoteSummary API endpoint, which means all the data can be fetched from there. I saw some attempts at scraping the data (#1668 #1778), but that can be inefficient and slower.

Preview

I was trying to follow the table layouts on the website. So far the outputs look like this (for AAPL):

Analyst Price Targets

{'current': 216.24, 'low': 183.86, 'high': 300.0, 'mean': 235.47, 'median': 240.0}

Earnings Estimate

      numberOfAnalysts   avg   low  high  yearAgoEps  growth
0q                 25  1.59  1.53  1.63        1.36   0.169
+1q                20  2.40  2.21  2.61        2.04   0.176
0y                 36  6.70  6.64  6.75        5.73   0.169
+1y                37  7.49  6.88  8.00        6.70   0.118

Revenue Estimate

      numberOfAnalysts           avg           low          high  yearAgoRevenue  growth
0q                 23   94242200000   93653000000   95311000000     83600100000   0.127
+1q                19  128626000000  123883000000  136387000000    111695000000   0.152
0y                 34  390237000000  389030000000  391416000000    358027000000   0.090
+1y                34  421632000000  401691000000  441882000000    390237000000   0.080

Earnings History

             epsEstimate  epsActual  epsDifference  surprisePercent
2023-09-30         1.30       1.36           0.06            0.046
2023-12-31         1.96       2.04           0.08            0.041
2024-03-31         1.50       1.53           0.03            0.020
2024-06-30         1.35       1.40           0.05            0.037

EPS Trend

      current  7daysAgo  30daysAgo  60daysAgo  90daysAgo
0q      1.59      1.59       1.42       1.43       1.53
+1q     2.40      2.39       2.16       2.15       2.30
0y      6.70      6.68       6.07       6.13       6.59
+1y     7.49      7.43       6.72       6.74       7.23

EPS Revisions

      upLast7days  upLast30days downLast7days  downLast30days
0q             0            16          None               0
+1q            6             8          None               7
0y             1            32          None               0
+1y            2            29          None               0

Growth Estimates

        stock  industry  sector     index
0q   0.16900       NaN     NaN  0.080000
+1q  0.17600       NaN     NaN  0.126000
0y   0.16900       NaN     NaN  0.045000
+1y  0.11800       NaN     NaN  0.126000
+5y  0.11100       NaN     NaN  0.116768
-5y  0.20446       NaN     NaN       NaN

Related to:

ValueRaider commented 3 months ago

I was trying to follow the table layouts on the website.

Usually ok but sometimes Yahoo is dumb, we can deviate. Also Pandas works best with dates in index not columns (DatetimeIndex etc)

Fidasek009 commented 3 months ago

Sure, I'll see what I can do 👌.

Fidasek009 commented 3 months ago

Can I get a review or some change proposals? Also the commit history looks awful 😅, I could create a new PR with just one commit if needed.

ValueRaider commented 3 months ago

Looks good. Can you add some basic tests here: https://github.com/ranaroussi/yfinance/blob/459d5f69c20a757d8fa344e3cfe085063aeb4f6c/tests/test_ticker.py#L751

Git squash is the best way to tidy the commit history #1084

Khalizo commented 3 months ago

Can some one please merge this PR? would be good to get the estimates please. Mainly interested in revenue and earnings.

ValueRaider commented 3 months ago

1 last thing I promise: add these new attributes to README

Fidasek009 commented 3 months ago

From my perspective it is ready. I also tried to find all issues and PRs related to this PR so you may have to go over those (you can find them in the initial comment).

ValueRaider commented 3 months ago

ruff check yfinance/scrapers/analysis.py