1. Investpy 소개 1
Investpy는 Investing.com에서 데이터를 검색하기 위한 Python 패키지로, 최대 39952개의 주식, 82221개의 펀드, 11403개의 ETF, 2029개의 통화 교차, 7797개의 지수, 688개의 채권, 66개의 상품, 250개의 인증서 및 4697개의 통화에서 데이터 검색을 제공합니다.
Investpy를 통해 사용자는 Investing.com에 색인된 모든 금융 상품의 최근 데이터와 과거 데이터를 모두 다운로드할 수 있습니다. 여기에는 미국, 프랑스, 인도, 스페인, 러시아 또는 독일과 같은 국가의 전 세계 데이터가 포함됩니다.
Investpy는 무료이며 제한이 없기 때문에 공개/비공개 API에 대한 의존을 중단하기 위해 재무 데이터 추출과 관련하여 가장 완벽한 Python 패키지 중 하나가 되기를 원합니다. 이는 재무 데이터 검색과 관련하여 현재Investpy가 가장 일관된 패키지 중 하나로 이끄는 기능 중 일부입니다.
Investing.com은 Investpy가 데이터를 검색하는 주요 데이터 소스입니다. Investing.com은 글로벌 금융 시장에 대한 뉴스, 분석, 스트리밍 시세, 차트, 기술 데이터 및 금융 도구를 제공하는 Fusion Media Ltd. 소유의 글로벌 금융 포털이자 인터넷 브랜드입니다.
2. 활용방법
investpy 설치 및 불러오기
>>> !pip install investpy
>>> import investpy
원하는 종목의 정보(예:ticker) 찾기
>>> search_result = investpy.search_quotes(text='samsung', products=['stocks'],
countries=['south korea'], n_results=1)
>>> print(search_result)
{"id_": 43433, "name": "Samsung Electronics Co Ltd", "symbol": "005930", "country": "south korea", "tag": "/equities/samsung-electronics-co-ltd", "pair_type": "stocks", "exchange": "Seoul"}
과거 데이터 조회하기
# search_result = 위에서 조회한 원하는데이터
>>> historical_data = search_result.retrieve_historical_data(from_date='01/01/2021', to_date='31/12/2021')
>>> print(historical_data.head())
기본 정보(fundamental) 확인하기
>>> information = search_result.retrieve_information()
>>> print(information)
{'prevClose': 75000, 'dailyRange': '73,700-74,800', 'revenue': 279600000000000.03, 'open': 74600, 'weekRange': '68,400-86,200', 'eps': 5777.37, 'volume': 10028854, 'marketCap': 499020000000000, 'dividend': '1,444.00(1.80%)', 'avgVolume': 4526546, 'ratio': 19.53, 'beta': 1.05, 'oneYearReturn': '-10.05%', 'sharesOutstanding': 6792669250, 'nextEarningDate': '28/04/2022'}
기술적 지표 조회하기
>>> technical_indicators = search_result.retrieve_technical_indicators(interval="daily")
>>> print(technical_indicators)
3. 응용하기
3-1. 배당수익률 조회하기
# 삼성전자 (티커: 005930)
ticker = '005930'
ctry = 'south korea'
SSE_div = investpy.stocks.get_stock_dividends(stock=ticker,
country=ctry)
SSE_div
# 다만 몇몇 종목(예:SKT, Realty Income 등)은 str to float 에러로 조회가 되지 않는다.
3-2. 손익계산서 조회
SSE_fin = investpy.stocks.get_stock_financial_summary(stock=ticker, country=ctry, summary_type='income_statement', period='annual')
SSE_fin
3-3. ETF 조회
etf = 'AAM S&P 500 Sector High Dividend'
country = 'united states'
from_date = '01/01/2021'
to_date = '31/12/2021'
data = investpy.etfs.get_etf_historical_data(etf, country, from_date, to_date, stock_exchange=None, as_json=False, order='ascending', interval='Daily')
data
3-4. 환율조회
import datetime as dt
now = dt.datetime.now()
today = now.strftime('%d/%m/%Y')
fx_df = investpy.get_currency_cross_historical_data(currency_cross='USD/KRW',
from_date = '01/01/2000',
to_date = today)
fx_df
3-5. 경제이벤트 조회하기
data = investpy.economic_calendar()
important_event = data.loc[data['importance'] == 'high']
important_event
'Develop > the code' 카테고리의 다른 글
[Open API] 네이버 API를 활용한 지도 만들기 (0) | 2022.02.04 |
---|---|
[Open API] 네이버 API 쉽게 쓰기 (0) | 2022.02.03 |
[Open API] 국경일 & 공휴일 구하기 (0) | 2021.11.04 |
[OpenAPI] 한국은행 경제통계시스템 활용법 (2) | 2021.10.14 |
'비오는 날' 예측하기 (0) | 2021.10.13 |