Vnstock Logo

Truy xuất chỉ tiêu kinh tế vĩ mô (Macro)

Chung

Mục lục

Macro giúp bạn lấy chỉ tiêu kinh tế vĩ mô theo chủ đề. Bạn gọi hàm của chủ đề cần xem, ví dụ cpi(), thư viện tự lấy đủ các chỉ tiêu của chủ đề đó. Bạn không phải tra mã chỉ tiêu.

Cách gọi

Python
from vnstock import Macro

Macro("fhsc").economy.cpi(start="2024-01-01")               # mặc định là Việt Nam
Macro("fhsc").economy.cpi(country="US", length=12)          # 12 kỳ mới nhất của mỗi chỉ tiêu
Macro("fhsc").currency.policy_rate(country="JP")
Macro("fhsc").global_macro.bond_yield(market="US", start="2026-01-01")

Cách viết của thế hệ 5 và vnstock_data 3.x vẫn chạy: Macro().economy().cpi(source="<nguồn>", period="month").

Tìm nhanh theo nhu cầu

Bộ hàm phủ 189 chỉ tiêu của Việt Nam (VN), Mỹ (US), Trung Quốc (CN), Nhật Bản (JP) và khu vực đồng euro (EU).

Bạn cần xemHàmcountry có số
GDP, tăng trưởng, GDP thực, GDP đầu người; Việt Nam có thêm GDP theo ngànheconomy.gdp()VN, US, CN, JP, EU
CPI và CPI lõi, so cùng kỳ và so tháng trướceconomy.cpi()VN, US, CN, JP, EU
Giá sản xuất, giá xuất nhập khẩu, các nhóm lạm pháteconomy.prices()US, CN, JP, EU
Đầu tư trực tiếp nước ngoàieconomy.fdi()VN
Xuất khẩu, nhập khẩu, cán cân thương mại, cán cân vãng laieconomy.import_export()VN, US, CN, JP, EU
Ngân sách, nợ công, thu và chi của chính phủeconomy.state_budget()VN, US, CN, JP, EU
Cung tiềneconomy.money_supply()VN, US, CN, JP, EU
Sản xuất công nghiệp, chỉ số nhà quản trị mua hàngeconomy.industry_prod()VN, US, CN, JP, EU
Bán lẻeconomy.retail()VN, US, CN, JP, EU
Lao động, thất nghiệpeconomy.population_labor()VN, US, CN, JP, EU
Nhà ởeconomy.housing()US
Lãi suất điều hànhcurrency.policy_rate()VN, US, CN, JP, EU
Dự trữ ngoại hốicurrency.fx_reserves()VN, US, CN, JP, EU
Bảng cân đối ngân hàng trung ươngcurrency.central_bank_assets()US, CN, JP, EU
Lãi suất tiền gửi theo ngân hàng và kỳ hạncurrency.deposit_rate()Không nhận country
Lãi suất của Cục Dự trữ Liên bang Mỹglobal_macro.fed_rate()Không nhận country
Lợi suất trái phiếu chính phủ 10 nămglobal_macro.bond_yield(market="US")market: VN, US, JP, DE

Nước không có số của hàm thì lời gọi báo VNSTOCK_INPUT_PARAM kèm các nước có số, không gọi tới nguồn. Lịch công bố sự kiện kinh tế ở Reference("<nguồn>").events.economic(start=..., end=...).

Tham số

Tham sốMặc địnhÝ nghĩa
country"VN"Nền kinh tế, xem bảng trên
start, endTừ năm 2000 tới nayYYYY-MM-DD, YYYY-MM hoặc YYYY
length12 hay "12b": 12 kỳ mới nhất của mỗi chỉ tiêu; "2Y", "6M": khoảng thời gian tính lùi từ end
periodMọi kỳChỉ giữ một tần suất: "month", "quarter", "year". Tần suất không có số thì báo VNSTOCK_INPUT_PARAM kèm các tần suất có số

global_macro.bond_yield() không có start thì lấy 30 ngày gần nhất. currency.deposit_rate() trả bảng lãi suất đang áp dụng, không nhận các tham số thời gian.

Dạng bảng

Mỗi dòng là một chỉ tiêu tại một kỳ, ở mọi hàm trừ deposit_rate():

timeperiodcountryindicatorindicator_nameindicator_valuevalue_unit
2026-09-01 07:00+07:002026-09VNcpi-yoyVN CPI (YoY)5,08percent
2026-09-01 07:00+07:002026-09VNcore-cpi-yoyVN Core CPI (YoY)4,55percent

bond_yield() có bốn cột time, indicator, indicator_value, value_unit.

  • period giữ kỳ gốc của nguồn: 2026-09, 2026-Q3, 2026. Trong một hàm có thể có nhiều tần suất, ví dụ GDP có cả quý và năm.
  • time là ngày đầu kỳ, nên các kỳ khác tần suất vẫn lọc và nối được theo thời gian.
  • value_unit đi theo từng dòng vì một hàm có nhiều đơn vị, ví dụ GDP có tỷ USD và phần trăm. Đừng cộng các chỉ tiêu khác đơn vị.

Muốn mỗi chỉ tiêu một cột:

Python
df = Macro("fhsc").economy.cpi(start="2024-01-01")
wide = df.pivot(index="time", columns="indicator", values="indicator_value")

Danh mục hàm

Bảng sinh từ thư viện bản 6.0.0, hồ sơ v5 (mặc định). "Tên khác" là tên của thế hệ 5 cho cùng dữ liệu. Danh sách đầy đủ trên máy bạn: vnstock tools, hoặc show_api() trong Python.

Kinh tế (economy)

HàmTên khácTham sốNguồn (source=)
cpi()start, end, length, countryfhsc
fdi()start, end, length, countryfhsc
gdp()start, end, length, countryfhsc
housing()start, end, length, countryfhsc
import_export()start, end, length, countryfhsc
industry_prod()start, end, length, countryfhsc
money_supply()start, end, length, countryfhsc
population_labor()start, end, length, countryfhsc
prices()start, end, length, countryfhsc
retail()start, end, length, countryfhsc
state_budget()start, end, length, countryfhsc
Cột trả về (hồ sơ v5, mặc định)
HàmCột
cpi()time, period, country, indicator, indicator_name, indicator_value, value_unit
fdi()time, period, country, indicator, indicator_name, indicator_value, value_unit
gdp()time, period, country, indicator, indicator_name, indicator_value, value_unit
housing()time, period, country, indicator, indicator_name, indicator_value, value_unit
import_export()time, period, country, indicator, indicator_name, indicator_value, value_unit
industry_prod()time, period, country, indicator, indicator_name, indicator_value, value_unit
money_supply()time, period, country, indicator, indicator_name, indicator_value, value_unit
population_labor()time, period, country, indicator, indicator_name, indicator_value, value_unit
prices()time, period, country, indicator, indicator_name, indicator_value, value_unit
retail()time, period, country, indicator, indicator_name, indicator_value, value_unit
state_budget()time, period, country, indicator, indicator_name, indicator_value, value_unit

Tiền tệ (currency)

HàmTên khácTham sốNguồn (source=)
central_bank_assets()start, end, length, countryfhsc
deposit_rate()fhsc
fx_reserves()start, end, length, countryfhsc
policy_rate()start, end, length, countryfhsc
Cột trả về (hồ sơ v5, mặc định)
HàmCột
central_bank_assets()time, period, country, indicator, indicator_name, indicator_value, value_unit
deposit_rate()bank_id, bank_name, bank_short_name, term, rate_percent, effective_date
fx_reserves()time, period, country, indicator, indicator_name, indicator_value, value_unit
policy_rate()time, period, country, indicator, indicator_name, indicator_value, value_unit

Vĩ mô thế giới (global_macro)

HàmTên khácTham sốNguồn (source=)
bond_yield()market, start, end, lengthfhsc
fed_rate()start, end, lengthfhsc
Cột trả về (hồ sơ v5, mặc định)
HàmCột
bond_yield()time, indicator, indicator_value, value_unit
fed_rate()time, period, country, indicator, indicator_name, indicator_value, value_unit

Chưa hỗ trợ

economy.credit(), economy.total_investment(), currency.exchange_rate(), currency.interbank_rate(), currency.omo() và global_macro.index() báo VNSTOCK_ROUTE_UNSUPPORTED, vì các Open API mà bản này kết nối chưa có chỉ tiêu tương ứng. Nến tỷ giá dùng Market("<nguồn>").forex("USDVND").ohlcv(), nhóm giá hàng hoá thế giới dùng Market("<nguồn>").commodity(...).

Số liệu đến từ nguồn bạn chọn. Thời điểm công bố và việc điều chỉnh số liệu do nguồn quyết định.