매직명령어(!)를 사용하여 코랩리서치에 필요한 패키지를 설치한다
!pip install yahoo_fin
!pip install requests_html
Requirement already satisfied: yahoo_fin in /usr/local/lib/python3.6/dist-packages (0.8.5) Requirement already satisfied: requests_html in /usr/local/lib/python3.6/dist-packages (0.10.0) Requirement already satisfied: pyquery in /usr/local/lib/python3.6/dist-packages (from requests_html) (1.4.1) Requirement already satisfied: fake-useragent in /usr/local/lib/python3.6/dist-packages (from requests_html) (0.1.11) Requirement already satisfied: parse in /usr/local/lib/python3.6/dist-packages (from requests_html) (1.15.0) Requirement already satisfied: w3lib in /usr/local/lib/python3.6/dist-packages (from requests_html) (1.22.0) Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from requests_html) (2.23.0) Requirement already satisfied: pyppeteer>=0.0.14 in /usr/local/lib/python3.6/dist-packages (from requests_html) (0.2.2) Requirement already satisfied: bs4 in /usr/local/lib/python3.6/dist-packages (from requests_html) (0.0.1) Requirement already satisfied: lxml>=2.1 in /usr/local/lib/python3.6/dist-packages (from pyquery->requests_html) (4.2.6) Requirement already satisfied: cssselect>0.7.9 in /usr/local/lib/python3.6/dist-packages (from pyquery->requests_html) (1.1.0) Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from w3lib->requests_html) (1.12.0) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->requests_html) (2020.4.5.1) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->requests_html) (1.24.3) Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->requests_html) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->requests_html) (2.9) Requirement already satisfied: pyee<8.0.0,>=7.0.1 in /usr/local/lib/python3.6/dist-packages (from pyppeteer>=0.0.14->requests_html) (7.0.2) Requirement already satisfied: tqdm<5.0.0,>=4.42.1 in /usr/local/lib/python3.6/dist-packages (from pyppeteer>=0.0.14->requests_html) (4.46.0) Requirement already satisfied: appdirs<2.0.0,>=1.4.3 in /usr/local/lib/python3.6/dist-packages (from pyppeteer>=0.0.14->requests_html) (1.4.4) Requirement already satisfied: websockets<9.0,>=8.1 in /usr/local/lib/python3.6/dist-packages (from pyppeteer>=0.0.14->requests_html) (8.1) Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.6/dist-packages (from bs4->requests_html) (4.6.3)
가장 먼저 할 일은 yahoo_fin에서 stock_info모듈을 임포트하는 것이다. 이 모듈과 함께 같이 필요한 것이 pandas패키지이다.
import yahoo_fin.stock_info as si
import pandas as pd
개별종목의 호가정보는 get_quote_table를 사용하여 구한다
quote = si.get_quote_table("aapl")
get_quote_table 메서드는 다음과 같이 여러 정보가 담긴 딕셔너리를 돌려준다.
quote
{'1y Target Est': 308.91, '52 Week Range': '170.27 - 327.85', 'Ask': '319.00 x 1100', 'Avg. Volume': 51660098.0, 'Beta (5Y Monthly)': 1.17, 'Bid': '318.91 x 900', "Day's Range": '315.37 - 319.23', 'EPS (TTM)': 12.73, 'Earnings Date': 'Jul 28, 2020 - Aug 03, 2020', 'Ex-Dividend Date': 'May 08, 2020', 'Forward Dividend & Yield': '3.28 (1.04%)', 'Market Cap': '1.382T', 'Open': 315.77, 'PE Ratio (TTM)': 25.05, 'Previous Close': 316.85, 'Quote Price': 318.8900146484375, 'Volume': 20450754.0}
다음과 같이 키 값(여기선 "PE Ratio (TTM)")을 사용하여 값을 얻을 수 있다.
quote["PE Ratio (TTM)"] # 22.71
25.05
PER을 구하는 또 다른 방법은 get_stats_valuation 메서드를 이용하는 것이다.
이것은 야후파이낸스의 종목 통계섹션의 내용이다.
val = si.get_stats_valuation("aapl")
val = val.iloc[:,:2]
val.columns = ["Attribute", "Recent"]
P/E 비율을 추출하면 다음과 같다
float(val[val.Attribute.str.contains("Trailing P/E")].iloc[0,1])
24.77
주가매출액(Price-to-Sales) 비율
float(val[val.Attribute.str.contains("Price/Sales")].iloc[0,1])
5.32
다우지수내 각 종목의 Price-to-Earnings 와 Price-to-Sales 비율을 구해보도록 하자.
tickers_dow메서드는 지수를 구성하는 종목의 티커를 돌려준다.
# get list of Dow tickers
dow_list = si.tickers_dow()
# Get data in the current column for each stock's valuation table
dow_stats = {}
for ticker in dow_list:
temp = si.get_stats_valuation(ticker)
temp = temp.iloc[:,:2]
temp.columns = ["Attribute", "Recent"]
dow_stats[ticker] = temp
# combine all the stats valuation tables into a single data frame
combined_stats = pd.concat(dow_stats)
combined_stats = combined_stats.reset_index()
del combined_stats["level_1"]
# update column names
combined_stats.columns = ["Ticker", "Attribute", "Recent"]
주가수익률(P/E) 비율
# get P/E ratio for each stock
combined_stats[combined_stats.Attribute.str.contains("Trailing P/E")]
Ticker | Attribute | Recent | |
---|---|---|---|
2 | AAPL | Trailing P/E | 24.77 |
11 | AXP | Trailing P/E | 13.61 |
20 | BA | Trailing P/E | NaN |
29 | CAT | Trailing P/E | 12.22 |
38 | CSCO | Trailing P/E | 17.96 |
47 | CVX | Trailing P/E | 44.25 |
56 | DIS | Trailing P/E | 51.45 |
65 | DOW | Trailing P/E | NaN |
74 | GS | Trailing P/E | 9.77 |
83 | HD | Trailing P/E | 23.68 |
92 | IBM | Trailing P/E | 11.79 |
101 | INTC | Trailing P/E | 12.03 |
110 | JNJ | Trailing P/E | 22.89 |
119 | JPM | Trailing P/E | 10.19 |
128 | KO | Trailing P/E | 19.47 |
137 | MCD | Trailing P/E | 24.26 |
146 | MMM | Trailing P/E | 17.11 |
155 | MRK | Trailing P/E | 19.38 |
164 | MSFT | Trailing P/E | 30.94 |
173 | NKE | Trailing P/E | 33.59 |
182 | PFE | Trailing P/E | 13.44 |
191 | PG | Trailing P/E | 60.66 |
200 | RTX | Trailing P/E | 12.65 |
209 | TRV | Trailing P/E | 10.71 |
218 | UNH | Trailing P/E | 20.08 |
227 | V | Trailing P/E | 34.87 |
236 | VZ | Trailing P/E | 12.18 |
245 | WBA | Trailing P/E | 10.19 |
254 | WMT | Trailing P/E | 23.85 |
263 | XOM | Trailing P/E | 16.69 |
주가매출액비율(Price-to-Sales) 비율
# get P/S ratio for each stock
combined_stats[combined_stats.Attribute.str.contains("Price/Sales")]
Ticker | Attribute | Recent | |
---|---|---|---|
5 | AAPL | Price/Sales (ttm) | 5.32 |
14 | AXP | Price/Sales (ttm) | 2.38 |
23 | BA | Price/Sales (ttm) | 1.11 |
32 | CAT | Price/Sales (ttm) | 1.27 |
41 | CSCO | Price/Sales (ttm) | 3.83 |
50 | CVX | Price/Sales (ttm) | 1.28 |
59 | DIS | Price/Sales (ttm) | 2.74 |
68 | DOW | Price/Sales (ttm) | 0.64 |
77 | GS | Price/Sales (ttm) | 2.02 |
86 | HD | Price/Sales (ttm) | 2.32 |
95 | IBM | Price/Sales (ttm) | 1.39 |
104 | INTC | Price/Sales (ttm) | 3.61 |
113 | JNJ | Price/Sales (ttm) | 4.75 |
122 | JPM | Price/Sales (ttm) | 2.50 |
131 | KO | Price/Sales (ttm) | 5.25 |
140 | MCD | Price/Sales (ttm) | 6.77 |
149 | MMM | Price/Sales (ttm) | 2.63 |
158 | MRK | Price/Sales (ttm) | 4.09 |
167 | MSFT | Price/Sales (ttm) | 10.31 |
176 | NKE | Price/Sales (ttm) | 3.53 |
185 | PFE | Price/Sales (ttm) | 4.19 |
194 | PG | Price/Sales (ttm) | 4.04 |
203 | RTX | Price/Sales (ttm) | 0.67 |
212 | TRV | Price/Sales (ttm) | 0.81 |
221 | UNH | Price/Sales (ttm) | 1.13 |
230 | V | Price/Sales (ttm) | 18.23 |
239 | VZ | Price/Sales (ttm) | 1.70 |
248 | WBA | Price/Sales (ttm) | 0.26 |
257 | WMT | Price/Sales (ttm) | 0.67 |
266 | XOM | Price/Sales (ttm) | 0.76 |
주가순자산(Price / Book) 비율
# get Price-to-Book ratio for each stock
combined_stats[combined_stats.Attribute.str.contains("Price/Book")]
Ticker | Attribute | Recent | |
---|---|---|---|
6 | AAPL | Price/Book (mrq) | 17.51 |
15 | AXP | Price/Book (mrq) | 3.44 |
24 | BA | Price/Book (mrq) | NaN |
33 | CAT | Price/Book (mrq) | 4.41 |
42 | CSCO | Price/Book (mrq) | 5.37 |
51 | CVX | Price/Book (mrq) | 1.19 |
60 | DIS | Price/Book (mrq) | 2.35 |
69 | DOW | Price/Book (mrq) | 2.06 |
78 | GS | Price/Book (mrq) | 0.76 |
87 | HD | Price/Book (mrq) | NaN |
96 | IBM | Price/Book (mrq) | 5.29 |
105 | INTC | Price/Book (mrq) | 3.44 |
114 | JNJ | Price/Book (mrq) | 6.31 |
123 | JPM | Price/Book (mrq) | 1.19 |
132 | KO | Price/Book (mrq) | 10.68 |
141 | MCD | Price/Book (mrq) | NaN |
150 | MMM | Price/Book (mrq) | 8.27 |
159 | MRK | Price/Book (mrq) | 7.37 |
168 | MSFT | Price/Book (mrq) | 12.30 |
177 | NKE | Price/Book (mrq) | 15.65 |
186 | PFE | Price/Book (mrq) | 3.22 |
195 | PG | Price/Book (mrq) | 6.19 |
204 | RTX | Price/Book (mrq) | 2.31 |
213 | TRV | Price/Book (mrq) | 0.99 |
222 | UNH | Price/Book (mrq) | 4.78 |
231 | V | Price/Book (mrq) | 14.17 |
240 | VZ | Price/Book (mrq) | 3.71 |
249 | WBA | Price/Book (mrq) | 1.47 |
258 | WMT | Price/Book (mrq) | 5.21 |
267 | XOM | Price/Book (mrq) | 1.04 |
주가이익성장배율(Price / Earnings-to-Growth) 비율
# get PEG ratio for each stock
combined_stats[combined_stats.Attribute.str.contains("PEG")]
Ticker | Attribute | Recent | |
---|---|---|---|
4 | AAPL | PEG Ratio (5 yr expected) 1 | 2.22 |
13 | AXP | PEG Ratio (5 yr expected) 1 | 1.07 |
22 | BA | PEG Ratio (5 yr expected) 1 | 5.91 |
31 | CAT | PEG Ratio (5 yr expected) 1 | 6.52 |
40 | CSCO | PEG Ratio (5 yr expected) 1 | 2.85 |
49 | CVX | PEG Ratio (5 yr expected) 1 | 7.07 |
58 | DIS | PEG Ratio (5 yr expected) 1 | 10.17 |
67 | DOW | PEG Ratio (5 yr expected) 1 | NaN |
76 | GS | PEG Ratio (5 yr expected) 1 | 2.70 |
85 | HD | PEG Ratio (5 yr expected) 1 | 2.16 |
94 | IBM | PEG Ratio (5 yr expected) 1 | 9.56 |
103 | INTC | PEG Ratio (5 yr expected) 1 | 2.04 |
112 | JNJ | PEG Ratio (5 yr expected) 1 | 4.29 |
121 | JPM | PEG Ratio (5 yr expected) 1 | 4.57 |
130 | KO | PEG Ratio (5 yr expected) 1 | 3.77 |
139 | MCD | PEG Ratio (5 yr expected) 1 | 4.21 |
148 | MMM | PEG Ratio (5 yr expected) 1 | 4.37 |
157 | MRK | PEG Ratio (5 yr expected) 1 | 1.64 |
166 | MSFT | PEG Ratio (5 yr expected) 1 | 2.26 |
175 | NKE | PEG Ratio (5 yr expected) 1 | 2.84 |
184 | PFE | PEG Ratio (5 yr expected) 1 | 2.42 |
193 | PG | PEG Ratio (5 yr expected) 1 | 2.84 |
202 | RTX | PEG Ratio (5 yr expected) 1 | 1.97 |
211 | TRV | PEG Ratio (5 yr expected) 1 | 0.91 |
220 | UNH | PEG Ratio (5 yr expected) 1 | 1.40 |
229 | V | PEG Ratio (5 yr expected) 1 | 2.83 |
238 | VZ | PEG Ratio (5 yr expected) 1 | 3.78 |
247 | WBA | PEG Ratio (5 yr expected) 1 | 6.89 |
256 | WMT | PEG Ratio (5 yr expected) 1 | 4.22 |
265 | XOM | PEG Ratio (5 yr expected) 1 | 10.47 |
Forward P/E 비율
# get forward P/E ratio for each stock
combined_stats[combined_stats.Attribute.str.contains("Forward P/E")]
Ticker | Attribute | Recent | |
---|---|---|---|
3 | AAPL | Forward P/E 1 | 26.74 |
12 | AXP | Forward P/E 1 | 14.66 |
21 | BA | Forward P/E 1 | 40.16 |
30 | CAT | Forward P/E 1 | 22.57 |
39 | CSCO | Forward P/E 1 | 14.93 |
48 | CVX | Forward P/E 1 | 14.49 |
57 | DIS | Forward P/E 1 | 60.61 |
66 | DOW | Forward P/E 1 | 25.25 |
75 | GS | Forward P/E 1 | 12.41 |
84 | HD | Forward P/E 1 | 24.57 |
93 | IBM | Forward P/E 1 | 10.99 |
102 | INTC | Forward P/E 1 | 13.70 |
111 | JNJ | Forward P/E 1 | 18.94 |
120 | JPM | Forward P/E 1 | 14.16 |
129 | KO | Forward P/E 1 | 22.68 |
138 | MCD | Forward P/E 1 | 31.06 |
147 | MMM | Forward P/E 1 | 17.70 |
156 | MRK | Forward P/E 1 | 14.45 |
165 | MSFT | Forward P/E 1 | 29.59 |
174 | NKE | Forward P/E 1 | 33.67 |
183 | PFE | Forward P/E 1 | 13.30 |
192 | PG | Forward P/E 1 | 21.32 |
201 | RTX | Forward P/E 1 | 14.73 |
210 | TRV | Forward P/E 1 | 10.71 |
219 | UNH | Forward P/E 1 | 17.61 |
228 | V | Forward P/E 1 | 38.46 |
237 | VZ | Forward P/E 1 | 11.32 |
246 | WBA | Forward P/E 1 | 6.72 |
255 | WMT | Forward P/E 1 | 25.19 |
264 | XOM | Forward P/E 1 | 121.95 |
야후파이낸스 종목 통계섹션에는“Valuation Measures” 테이블이 있는데
get_stats method를 통해 기타 통계 정보(Return on Equity (ROE),
Return on Assets, profit margin)를 구할 수 있다.
dow_extra_stats = {}
for ticker in dow_list:
dow_extra_stats[ticker] = si.get_stats(ticker)
combined_extra_stats = pd.concat(dow_extra_stats)
combined_extra_stats = combined_extra_stats.reset_index()
del combined_extra_stats["level_1"]
combined_extra_stats.columns = ["ticker", "Attribute", "Value"]
자기자본이익률(ROE)
combined_extra_stats[combined_extra_stats.Attribute.str.contains("Return on Equity")]
ticker | Attribute | Value | |
---|---|---|---|
33 | AAPL | Return on Equity (ttm) | 62.09% |
83 | AXP | Return on Equity (ttm) | 25.80% |
133 | BA | Return on Equity (ttm) | NaN |
183 | CAT | Return on Equity (ttm) | 35.69% |
233 | CSCO | Return on Equity (ttm) | 29.74% |
283 | CVX | Return on Equity (ttm) | 2.51% |
333 | DIS | Return on Equity (ttm) | 5.01% |
383 | DOW | Return on Equity (ttm) | -6.86% |
433 | GS | Return on Equity (ttm) | 8.02% |
483 | HD | Return on Equity (ttm) | NaN |
533 | IBM | Return on Equity (ttm) | 49.10% |
583 | INTC | Return on Equity (ttm) | 30.31% |
633 | JNJ | Return on Equity (ttm) | 28.55% |
683 | JPM | Return on Equity (ttm) | 11.56% |
733 | KO | Return on Equity (ttm) | 50.85% |
783 | MCD | Return on Equity (ttm) | NaN |
833 | MMM | Return on Equity (ttm) | 49.92% |
883 | MRK | Return on Equity (ttm) | 37.55% |
933 | MSFT | Return on Equity (ttm) | 44.20% |
983 | NKE | Return on Equity (ttm) | 47.96% |
1033 | PFE | Return on Equity (ttm) | 25.41% |
1083 | PG | Return on Equity (ttm) | 10.01% |
1133 | RTX | Return on Equity (ttm) | 10.79% |
1183 | TRV | Return on Equity (ttm) | 9.79% |
1233 | UNH | Return on Equity (ttm) | 23.96% |
1283 | V | Return on Equity (ttm) | 36.25% |
1333 | VZ | Return on Equity (ttm) | 31.76% |
1383 | WBA | Return on Equity (ttm) | 14.14% |
1433 | WMT | Return on Equity (ttm) | 18.86% |
1483 | XOM | Return on Equity (ttm) | 6.00% |
총자산이익률(ROA)
combined_extra_stats[combined_extra_stats.Attribute.str.contains("Return on Assets")]
ticker | Attribute | Value | |
---|---|---|---|
32 | AAPL | Return on Assets (ttm) | 12.38% |
82 | AXP | Return on Assets (ttm) | 2.91% |
132 | BA | Return on Assets (ttm) | -2.27% |
182 | CAT | Return on Assets (ttm) | 6.09% |
232 | CSCO | Return on Assets (ttm) | 9.59% |
282 | CVX | Return on Assets (ttm) | 2.49% |
332 | DIS | Return on Assets (ttm) | 2.77% |
382 | DOW | Return on Assets (ttm) | NaN |
432 | GS | Return on Assets (ttm) | 0.74% |
482 | HD | Return on Assets (ttm) | 20.79% |
532 | IBM | Return on Assets (ttm) | 4.30% |
582 | INTC | Return on Assets (ttm) | 11.48% |
632 | JNJ | Return on Assets (ttm) | 8.83% |
682 | JPM | Return on Assets (ttm) | 1.02% |
732 | KO | Return on Assets (ttm) | 7.31% |
782 | MCD | Return on Assets (ttm) | 11.07% |
832 | MMM | Return on Assets (ttm) | 10.40% |
882 | MRK | Return on Assets (ttm) | 11.76% |
932 | MSFT | Return on Assets (ttm) | 11.84% |
982 | NKE | Return on Assets (ttm) | 13.18% |
1032 | PFE | Return on Assets (ttm) | 5.78% |
1082 | PG | Return on Assets (ttm) | 8.35% |
1132 | RTX | Return on Assets (ttm) | 4.57% |
1182 | TRV | Return on Assets (ttm) | 1.86% |
1232 | UNH | Return on Assets (ttm) | 7.08% |
1282 | V | Return on Assets (ttm) | 14.02% |
1332 | VZ | Return on Assets (ttm) | 6.79% |
1382 | WBA | Return on Assets (ttm) | 3.22% |
1432 | WMT | Return on Assets (ttm) | 5.89% |
1482 | XOM | Return on Assets (ttm) | 1.52% |
이익률(profit margin)
combined_extra_stats[combined_extra_stats.Attribute.str.contains("Profit Margin")]
ticker | Attribute | Value | |
---|---|---|---|
30 | AAPL | Profit Margin | 21.35% |
80 | AXP | Profit Margin | 14.63% |
130 | BA | Profit Margin | -4.84% |
180 | CAT | Profit Margin | 10.41% |
230 | CSCO | Profit Margin | 21.32% |
280 | CVX | Profit Margin | 2.86% |
330 | DIS | Profit Margin | 6.88% |
380 | DOW | Profit Margin | -4.01% |
430 | GS | Profit Margin | 21.40% |
480 | HD | Profit Margin | 10.20% |
530 | IBM | Profit Margin | 11.78% |
580 | INTC | Profit Margin | 30.02% |
630 | JNJ | Profit Margin | 20.75% |
680 | JPM | Profit Margin | 29.42% |
730 | KO | Profit Margin | 26.95% |
780 | MCD | Profit Margin | 27.95% |
830 | MMM | Profit Margin | 15.37% |
880 | MRK | Profit Margin | 21.10% |
930 | MSFT | Profit Margin | 33.36% |
980 | NKE | Profit Margin | 10.46% |
1030 | PFE | Profit Margin | 31.17% |
1080 | PG | Profit Margin | 7.09% |
1130 | RTX | Profit Margin | 5.34% |
1180 | TRV | Profit Margin | 7.63% |
1230 | UNH | Profit Margin | 5.58% |
1280 | V | Profit Margin | 52.26% |
1330 | VZ | Profit Margin | 14.00% |
1380 | WBA | Profit Margin | 2.52% |
1430 | WMT | Profit Margin | 2.84% |
1480 | XOM | Profit Margin | 4.57% |
get_balance_sheet 메서드를 사용하여 재무상태표를 구할 수 있는 데, 유동현금, 자산, 부채등을 알 수 있다.
sheet = si.get_balance_sheet("aapl")
총현금(Total cash on hand)
sheet[sheet.Breakdown == "Total Cash"]
Breakdown | 9/30/2019 | 9/30/2018 | 9/30/2017 | 9/30/2016 |
---|
자본(Stockholders’ equity)
sheet[sheet.Breakdown == "Total stockholders' equity"]
Breakdown | 9/30/2019 | 9/30/2018 | 9/30/2017 | 9/30/2016 |
---|
총자산(Total Assets)
sheet[sheet.Breakdown == "Total Assets"]
Breakdown | 9/30/2019 | 9/30/2018 | 9/30/2017 | 9/30/2016 | |
---|---|---|---|---|---|
0 | Total Assets | 338516000 | 365725000 | 375319000 | 321686000 |
다우지수 구성종목들의 재무상태표를 다음과 같이 얻을 수 있다.
balance_sheets = {}
for ticker in dow_list:
balance_sheets[ticker] = si.get_balance_sheet(ticker)
각 종목의 재무상태표를 묶어서 최근 데이터를 보여준다.
recent_sheets = {ticker : sheet.iloc[:,:2] for ticker,sheet in balance_sheets.items()}
for ticker in recent_sheets.keys():
recent_sheets[ticker].columns = ["Breakdown", "Recent"]
# combine all balance sheets together
combined_sheets = pd.concat(recent_sheets)
# reset index to pull in ticker
combined_sheets = combined_sheets.reset_index()
# get rid of numeric index field
del combined_sheets["level_1"]
# update column names
combined_sheets.columns = ["Ticker", "Breakdown", "Recent"]
총자산(Total Assets)
combined_sheets[combined_sheets.Breakdown == "Total Assets"]
Ticker | Breakdown | Recent | |
---|---|---|---|
0 | AAPL | Total Assets | 338516000 |
13 | AXP | Total Assets | 198321000 |
28 | BA | Total Assets | 133625000 |
43 | CAT | Total Assets | 78453000 |
58 | CSCO | Total Assets | 97793000 |
71 | CVX | Total Assets | 237428000 |
86 | DIS | Total Assets | 193984000 |
100 | DOW | Total Assets | 60524000 |
115 | GS | Total Assets | 992968000 |
131 | HD | Total Assets | 51236000 |
146 | IBM | Total Assets | 152186000 |
161 | INTC | Total Assets | 136524000 |
174 | JNJ | Total Assets | 157728000 |
188 | JPM | Total Assets | 2687379000 |
203 | KO | Total Assets | 86381000 |
217 | MCD | Total Assets | 47510800 |
232 | MMM | Total Assets | 44659000 |
247 | MRK | Total Assets | 84397000 |
261 | MSFT | Total Assets | 286556000 |
275 | NKE | Total Assets | 23717000 |
287 | PFE | Total Assets | 167489000 |
302 | PG | Total Assets | 115095000 |
318 | RTX | Total Assets | 139716000 |
333 | TRV | Total Assets | 110122000 |
346 | UNH | Total Assets | 173889000 |
359 | V | Total Assets | 72574000 |
373 | VZ | Total Assets | 291727000 |
388 | WBA | Total Assets | 67598000 |
402 | WMT | Total Assets | 236495000 |
416 | XOM | Total Assets | 362597000 |
손익계산서는 get_income_statement 메서드를 사용하여 얻을 수 있다
income=si.get_income_statement("aapl")
매출액(total revenue)
income[income.Breakdown == "Total Revenue"]
Breakdown | ttm | 9/30/2019 | 9/30/2018 | 9/30/2017 | 9/30/2016 | |
---|---|---|---|---|---|---|
0 | Total Revenue | 267981000 | 260174000 | 265595000 | 229234000 | 215639000 |
매출총이익(gross profit)
income[income.Breakdown == "Gross Profit"]
Breakdown | ttm | 9/30/2019 | 9/30/2018 | 9/30/2017 | 9/30/2016 | |
---|---|---|---|---|---|---|
2 | Gross Profit | 102127000 | 98392000 | 101839000 | 88186000 | 84263000 |
여러 종목의 손익계산서 구하기
income_statements = {}
for ticker in dow_list:
income_statements[ticker] = si.get_income_statement(ticker)
각 종목의 손익계산서도 하나로 묶어 필요한 계정만 볼 수 있다
recent_income_statements = {ticker : sheet.iloc[:,:2] for ticker,sheet in income_statements.items()}
for ticker in recent_income_statements.keys():
recent_income_statements[ticker].columns = ["Breakdown", "Recent"]
combined_income = pd.concat(recent_income_statements)
combined_income = combined_income.reset_index()
del combined_income["level_1"]
combined_income.columns = ["Ticker", "Breakdown", "Recent"]
매출액(Total Revenue)
combined_income[combined_income.Breakdown == "Total Revenue"]
현금흐름표(cash flow statements)는 get_cash_flow 메서드를 사용하여 구한다
flow = si.get_cash_flow("aapl")
여러 종목의 현금흐름표 다운로드
cash_flows = {}
for ticker in dow_list:
cash_flows[ticker] = si.get_cash_flow(ticker)
다운받은 현금흐름표 묶기
recent_cash_flows = {ticker : flow.iloc[:,:2] for ticker,flow in cash_flows.items()}
for ticker in recent_cash_flows.keys():
recent_cash_flows[ticker].columns = ["Breakdown", "Recent"]
combined_cash_flows = pd.concat(recent_cash_flows)
combined_cash_flows = combined_cash_flows.reset_index()
del combined_cash_flows["level_1"]
combined_cash_flows.columns = ["Ticker", "Breakdown", "Recent"]
잉여현금흐름(free cash flow)
combined_cash_flows[combined_cash_flows.Breakdown == "Free Cash Flow"]
부채정보(debt information)
combined_cash_flows[combined_cash_flows.Breakdown == "Issuance of Debt"]