Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Star_project

oil price - Yahoo Finance API 로 유가데이터 받아오기 본문

데이터 분석/데이터 수집

oil price - Yahoo Finance API 로 유가데이터 받아오기

star빛 2022. 4. 13. 18:10

https://junyoru.tistory.com/129

#YahooFinanceAPI #주가데이터 받아오는 법

 

[Python] Yahoo Finance API로 주가 데이터 받아오기

미국 주식 정보는 네이버 등 우리가 흔히 쓰는 사이트에서 확인하기 쉽지 않다. 따라서 해외주식 투자자들은 여러 종류의 사이트를 통해 미국 주식 정보를 얻고 있을 것이다. investing.com, FINVIZ, S

junyoru.tistory.com

위 블로그를 참고했습니다.

 

https://finance.yahoo.com/quote/CL%3DF?p=CL%3DF 

 

Crude Oil May 22 (CL=F) Stock Price, News, Quote & History - Yahoo Finance

Find the latest Crude Oil May 22 (CL=F) stock quote, history, news and other vital information to help you with your stock trading and investing.

finance.yahoo.com

### Yahoo Finance 에서 유가 데이터 불러온 후 저장하기

# ! pip install yfinance

import yfinance as yf
import pandas as pd

# apple 주가
yf.download('AAPL', start = '2021-01-01', end='2021-12-31')

data = yf.download(['AAPL','MU'], start = '2021-01-01', end = '2021-12-31')
print(data)

# 유가데이터 불러오기, csv 저장하기
CLF = yf.download(['CL=F'], start = '2021-01-01', end = '2022-01-01') # Crude Oil May 22 (CL=F)
BZF = yf.download(['BZ=F'], start = '2021-01-01', end = '2022-01-01') # Brent Crude Oil Last Day Financ (BZ=F)


CLF.to_csv('CL=F_2021.csv')
BZF.to_csv('BZ=F_2021.csv')

# csv 저장 확인하기
CLF = pd.read_csv('CL=F_2021.csv')
BZF = pd.read_csv('BZ=F_2021.csv')
print(CLF)
print(BZF)

 

 

import yfinance as yf
import pandas as pd
oil_price_2021 = yf.download(['CL=F','BZ=F'], start = '2021-01-01', end = '2021-12-31')
oil_price_2021.to_csv('oil_price_2021.csv')
oil_price_2021 = pd.read_csv('oil_price_2021.csv')
print(oil_price_2021)

 

 

아래 패키지도 해봤는데 library는 yahoo finance 모듈 이 훨씬 깔끔합니다!

 

https://pypi.org/project/yahoofinancials/

 

yahoofinancials

A powerful financial data module used for pulling both fundamental and technical data from Yahoo Finance

pypi.org