!pip install urllib3==1.26.14 requests==2.25.1 yahooquery==2.3.0
ctrl+enter로 실행하여 설치...
새 코드. 라이브러리를 불러옵니다.
from yahooquery import Ticker
이렇게 치고 shift+enter
그럼 또 새 코드가 생김
테슬라 가져와보자
company = Ticker('TSLA')
또 shift+enter
company.summary_detail
또 shift+enter
그럼 이것저것 정보가 막 나온다.
야후쿼리 공식홈페이지. 전체 사용법을 둘러보고 싶다면 아래를 참고.
https://yahooquery.dpguthrie.com/guide/
Ticker modules의 사용법을 둘러보고 싶다면 아래를 참고. 이 안에서 찾으면 된다.
https://yahooquery.dpguthrie.com/guide/ticker/modules/
1) 기본 정보 얻기. 티커의 여러 모듈의 정보를 한 번에 불러서 모아둔다.get modules.
새 코드. 아래 입력 후 실행.
modules = 'summaryDetail assetProfile price financialData defaultKeyStatistics'
all_data = company.get_modules(modules)
예) 회사명, 산업, 시가총액, 매출
name = all_data['TSLA']['price']['shortName']
marketcap = all_data['TSLA']['price']['marketCap']
industry = all_data['TSLA']['assetProfile']['industry']
revenue = all_data['TSLA']['financialData']['totalRevenue']
print(name, marketcap, industry, revenue)
2) 재무제표에서 3년치 데이터 얻기(대차대조표, 현금흐름표, 기업 실적)
company.balance_sheet()
company.cash_flow()
company.earnings
3) 그 외 정보들(주주정보, 애널리스트 추천 등)
company.institution_ownership
company.recommendations
company.calendar_events
-------------
써보자.
company = Ticker('TSLA')
modules = 'summaryDetail assetProfile price financialData defaultKeyStatistics'
all_data = company.get_modules(modules)
name = all_data['TSLA']['price']['shortName']
marketcap = all_data['TSLA']['price']['marketCap']
industry = all_data['TSLA']['assetProfile']['industry']
revenue = all_data['TSLA']['financialData']['totalRevenue']
print(name, marketcap, industry, revenue)
결과는
TESLA 말고 code라고 대체어를 넣어보자.
------------
revenue 대신 summary랑 다른 price들을 찾아보자
------------------
code = 'TSLA'
company = Ticker(code)
modules = 'summaryDetail assetProfile price financialData defaultKeyStatistics'
all_data = company.get_modules(modules)
name = all_data[code]['price']['shortName']
marketcap = all_data[code]['price']['marketCap']
industry = all_data[code]['assetProfile']['industry']
summary = all_data[code]['assetProfile']['longBusinessSummary']
currentPrice = all_data[code]['financialData']['currentPrice']
targetPrice = all_data[code]['financialData']['targetMeanPrice']
per = all_data[code]['summaryDetail']['trailingPE']
eps = all_data[code]['defaultKeyStatistics']['trailingEps']
pbr = all_data[code]['defaultKeyStatistics']['priceToBook']
print(name, marketcap, industry, summary, currentPrice, targetPrice, per, eps, pbr)
'개발일지_파이썬for금융인' 카테고리의 다른 글
Dart OpenAPI 키 발급받기 (0) | 2023.04.15 |
---|---|
분석하기(2) - 데이터 모으기 (0) | 2023.04.04 |
엑셀파일 불러와서 판다스로 조정하기 (0) | 2023.03.28 |
라이브러리: 판다스pandas 넘파이numpy (0) | 2023.03.28 |
파일 읽어서, 이미지 다운받기 (0) | 2023.03.27 |