Dữ liệu kinh tế từ Cục Dự trữ Liên bang

Nhập và quản lý dữ liệu tài chính bằng Python

Stefan Jansen

Instructor

Dữ liệu kinh tế từ FRED

Logo FRED

  • Federal Reserve Economic Data
  • 500.000 chuỗi, bao phủ nhiều nhóm:
    • Tăng trưởng kinh tế & việc làm
    • Chính sách tiền tệ & tài khóa
    • Nhân khẩu học, ngành, giá hàng hóa
    • Tần suất ngày, tháng, năm
Nhập và quản lý dữ liệu tài chính bằng Python

Lấy dữ liệu từ FRED

tìm kiếm fred.png

1 https://fred.stlouisfed.org/
Nhập và quản lý dữ liệu tài chính bằng Python

Lấy dữ liệu từ FRED

tìm kiếm fred 2.png

1 https://fred.stlouisfed.org/
Nhập và quản lý dữ liệu tài chính bằng Python

Lấy dữ liệu từ FRED

tìm kiếm fred 3.png

1 https://fred.stlouisfed.org/
Nhập và quản lý dữ liệu tài chính bằng Python

Lãi suất

from pandas_datareader.data import DataReader
from datetime import date

series_code = 'DGS10' # Lãi suất trái phiếu Kho bạc 10 năm
data_source = 'fred' # Dịch vụ dữ liệu kinh tế của FED
start = date(1962, 1, 1)
data = DataReader(series_code, data_source, start)
data.info()
DatetimeIndex: 15754 entries, 1962-01-02 to 2022-05-20
Data columns (total 1 columns):
 #   Column  Non-Null Count  Dtype  
 --  ------  --------------  -----  
 0   DGS10   15083 non-null  float64
dtypes: float64(1)
Nhập và quản lý dữ liệu tài chính bằng Python

Giá cổ phiếu: trực quan hóa

  • .rename(columns={old_name: new_name})
series_name = 'Trái phiếu 10 năm'
data = data.rename(columns={series_code: series_name})

data.plot(title=series_name); plt.show()

Hình trực quan mới

Nhập và quản lý dữ liệu tài chính bằng Python

Kết hợp dữ liệu cổ phiếu và kinh tế

start = date(2000, 1, 1)
series = 'DCOILWTICO' # Giá dầu WTI (West Texas Intermediate)

oil = DataReader(series, 'fred', start)
ticker = 'XOM' # Exxon Mobil Corporation stock = DataReader(ticker, 'yanoo', start)
data = pd.concat([stock[['Close']], oil], axis=1)
data.info()
DatetimeIndex: 5841 entries, 2000-01-03 to 2022-05-23
Data columns (total 2 columns):
 #   Column      Non-Null Count  Dtype  
 --  ------      --------------  -----  
 0   Close       5634 non-null   float64
 1   DCOILWTICO  5615 non-null   float64
Nhập và quản lý dữ liệu tài chính bằng Python

Kết hợp dữ liệu cổ phiếu và kinh tế

data.columns = ['Exxon', 'Giá dầu']
data.plot()
plt.show()

2_2_tickers.png

Nhập và quản lý dữ liệu tài chính bằng Python

Ayo berlatih!

Nhập và quản lý dữ liệu tài chính bằng Python

Preparing Video For Download...