콘텐츠로 이동

통화 지표

통화량(M1, M2, Lf)과 은행 대출 등 통화 관련 지표를 조회하는 방법을 설명합니다.

통화량

통화량은 경제 내에서 유통되는 화폐의 총량을 나타내는 지표입니다.

지원 지표

  • M1 - 협의통화 (현금 + 요구불예금)
  • M2 - 광의통화 (M1 + 저축성예금 + 단기금융상품 등)
  • Lf - 금융기관 유동성 (M2 + 장기금융상품 등)

M2 통화량

가장 널리 사용되는 통화량 지표입니다.

import ecos

# M2 통화량 조회
df = ecos.get_money_supply(indicator="M2")
print(df.tail())

기간 지정

# 2020년 1월부터 2024년 12월까지
df = ecos.get_money_supply(
    indicator="M2",
    start_date="202001",
    end_date="202412"
)

조회 주기 지정

frequency 로 월(monthly, 기본)·분기(quarterly)·연(annual) 주기를 선택합니다. start_date / end_date 형식은 주기에 맞춰 사용합니다(월 YYYYMM / 분기 YYYYQn / 연 YYYY).

# 분기별 M2 통화량
df = ecos.get_money_supply("M2", frequency="quarterly")
print(df.tail())

날짜 형식

frequencymonthly 이면 YYYYMM, quarterly 이면 YYYYQn, annual 이면 YYYY 형식을 사용합니다. 기간을 생략하면 주기별 기본 범위가 적용됩니다.

반환 데이터 구조

컬럼 타입 설명
date datetime 조회 월
value float 통화량 (10억원)
unit str 단위 (십억원)

시각화

import ecos
import matplotlib.pyplot as plt

# M2 통화량 추이
df = ecos.get_money_supply(indicator="M2", start_date="202001")

# 조원 단위로 변환
df['value_trillion'] = df['value'] / 1000

# 그래프
df.set_index('date')['value_trillion'].plot(
    title='M2 통화량 추이',
    ylabel='통화량 (조원)',
    figsize=(12, 6),
    grid=True
)
plt.tight_layout()
plt.show()

# 통계
print(f"현재 M2: {df.iloc[-1]['value_trillion']:.0f}조원")
print(f"1년 전 대비 증가: {df.iloc[-1]['value_trillion'] - df.iloc[-12]['value_trillion']:.0f}조원")

M1, M2, Lf 비교

import ecos
import pandas as pd
import matplotlib.pyplot as plt

# 세 지표 조회
m1 = ecos.get_money_supply(indicator="M1", start_date="202001")
m2 = ecos.get_money_supply(indicator="M2", start_date="202001")
lf = ecos.get_money_supply(indicator="Lf", start_date="202001")

# 조원 단위로 변환 및 병합
merged = pd.merge(
    m1[['date', 'value']].rename(columns={'value': 'M1'}),
    m2[['date', 'value']].rename(columns={'value': 'M2'}),
    on='date'
)
merged = pd.merge(
    merged,
    lf[['date', 'value']].rename(columns={'value': 'Lf'}),
    on='date'
)

# 조원 단위로 변환
merged[['M1', 'M2', 'Lf']] = merged[['M1', 'M2', 'Lf']] / 1000

# 시각화
merged.set_index('date').plot(
    title='통화량 지표 비교',
    ylabel='통화량 (조원)',
    figsize=(12, 6),
    grid=True
)
plt.legend(['M1 (협의통화)', 'M2 (광의통화)', 'Lf (유동성)'])
plt.tight_layout()
plt.show()

은행 대출

예금은행 대출금 잔액을 조회합니다.

지원 부문

  • all - 예금은행 전체 대출금 (기본값)
  • household - 예금취급기관 가계대출

기업대출

기업대출은 get_bank_lending 으로는 제공되지 않습니다. 기업대출이 필요하면 get_series 로 산업별대출금 통계표를 직접 조회하세요.

전체 대출

import ecos

# 예금은행 전체 대출금 잔액 조회 (기본값)
df = ecos.get_bank_lending(sector="all")
print(df.tail())

가계대출

import ecos

# 가계대출 잔액 조회
df = ecos.get_bank_lending(sector="household")
print(df.tail())

기간 지정

df = ecos.get_bank_lending(
    sector="household",
    start_date="202001",
    end_date="202412"
)

조회 주기 지정

frequency 로 월(monthly, 기본)·분기(quarterly)·연(annual) 주기를 선택합니다.

# 연간 가계대출
df = ecos.get_bank_lending(sector="household", frequency="annual")
print(df.tail())

반환 데이터 구조

컬럼 타입 설명
date datetime 조회 월
value float 대출 잔액 (10억원)
unit str 단위 (십억원)

전체 vs 가계 대출 비교

import ecos
import pandas as pd
import matplotlib.pyplot as plt

# 두 부문 조회
total = ecos.get_bank_lending(sector="all", start_date="202001")
household = ecos.get_bank_lending(sector="household", start_date="202001")

# 데이터 병합
merged = pd.merge(
    total[['date', 'value']].rename(columns={'value': '전체'}),
    household[['date', 'value']].rename(columns={'value': '가계'}),
    on='date'
)

# 조원 단위로 변환
merged[['전체', '가계']] = merged[['전체', '가계']] / 1000

# 시각화
merged.set_index('date').plot(
    title='은행 대출 현황',
    ylabel='대출 잔액 (조원)',
    figsize=(12, 6),
    grid=True
)
plt.legend(['전체 대출', '가계대출'])
plt.tight_layout()
plt.show()

# 비율 계산
merged['household_ratio'] = (merged['가계'] / merged['전체']) * 100

print(f"\n가계대출 비중: {merged.iloc[-1]['household_ratio']:.1f}%")

M1 세부 데이터

M1 통화량의 평잔/말잔, 계절조정/원계열 세부 데이터를 조회합니다.

지원 유형

  • 평잔_계절조정 - 평균잔액, 계절조정 계열
  • 평잔_원계열 - 평균잔액, 원계열
  • 말잔_계절조정 - 말일잔액, 계절조정 계열 (기본값)

기본 사용법

import ecos

# M1 평잔 계절조정
df = ecos.get_m1_variants(variant="평잔_계절조정")
print(df.tail())

# M1 말잔 계절조정
df = ecos.get_m1_variants(variant="말잔_계절조정")
print(df.tail())

기간 지정

df = ecos.get_m1_variants(
    variant="평잔_계절조정",
    start_date="202001",
    end_date="202412"
)

조회 주기 지정

frequency 로 월(monthly, 기본)·분기(quarterly)·연(annual) 주기를 선택합니다.

# 연간 M1
df = ecos.get_m1_variants(frequency="annual")
print(df.tail())

M2 세부 데이터

M2 통화량의 평잔/말잔, 계절조정/원계열 세부 데이터를 조회합니다.

매개변수

  • variant: M2 변형 종류 (기본값: "말잔_계절조정")
variant 값 설명
"평잔_계절조정" 기간 중 평균잔액, 계절조정 계열
"평잔_원계열" 기간 중 평균잔액, 원계열
"말잔_계절조정" 기말 잔액, 계절조정 계열 (기본값)

기본 사용법

import ecos

# M2 평잔 계절조정
df = ecos.get_m2_variants(variant="평잔_계절조정")
print(df.tail())

# M2 말잔 계절조정
df = ecos.get_m2_variants(variant="말잔_계절조정")
print(df.tail())

조회 주기 지정

frequency 로 월(monthly, 기본)·분기(quarterly)·연(annual) 주기를 선택합니다.

# 분기별 M2 평잔 원계열
df = ecos.get_m2_variants(variant="평잔_원계열", frequency="quarterly")
print(df.tail())

M2 경제주체별

M2를 경제주체(가계, 기업 등)별로 분류한 데이터를 조회합니다. partial-coverage 규약(#56)에 따라 sub_category 미지정 시 전체 경제주체를 long-format으로, 지정 시 해당 주체 단일 시계열만 반환합니다. 단위는 십억원입니다.

import ecos

# 전체 경제주체 long-format (date, category_value, value, unit)
df = ecos.get_m2_by_holder()
print(df.tail())

# 단일 주체 (비금융기업) 시계열
df = ecos.get_m2_by_holder(sub_category="비금융기업 2)")
print(df.tail())

# 연간 주기
df = ecos.get_m2_by_holder(frequency="annual")
print(df.tail())

long-format 단순 합산 주의

이 통계표에는 총계(M2 전체)와 경제주체별 항목이 함께 포함되므로 주체 간 단순 합산은 하지 마세요. 특정 시계열이 필요하면 sub_category 로 선택하세요.

지원 유형

  • 평잔_계절조정 - 평균잔액, 계절조정 계열
  • 평잔_원계열 - 평균잔액, 원계열
  • 말잔_계절조정 - 말일잔액, 계절조정 계열
  • 말잔_원계열 - 말일잔액, 원계열 (기본값)

가계신용

가계신용 데이터를 업권별 또는 용도별로 조회합니다.

지원 카테고리

  • 업권별 - 예금은행, 비은행예금취급기관 등 업권별 분류 (기본값)
  • 용도별 - 주택구입, 생활비 등 용도별 분류

기본 사용법

import ecos

# 가계신용 (업권별)
df = ecos.get_household_credit(category="업권별")
print(df.tail())

# 가계신용 (용도별)
df = ecos.get_household_credit(category="용도별")
print(df.tail())

기간 지정

# 2023년 데이터 (분기별)
df = ecos.get_household_credit(
    category="업권별",
    start_date="2023Q1",
    end_date="2023Q4"
)

날짜 형식

가계신용은 분기 데이터이므로 YYYYQN 형식을 사용합니다.

반환 데이터 구조

컬럼 타입 설명
date datetime 조회 분기
value float 가계신용 (10억원)
unit str 단위 (십억원)

가계대출 세부 데이터

예금취급기관의 가계대출을 용도별로 상세 조회합니다.

기본 사용법

import ecos

# 전체 분류 long-format (date, category_value, value, unit)
df = ecos.get_household_lending_detail()
print(df.tail())

# 주택관련대출(예금취급기관) 단일 시계열 (item_code 사용 권장)
df = ecos.get_household_lending_detail(sub_category="11100A0")

v0.3.0 재설계 (#62)

이전에는 단일 항목만 반환했으나, 이제 용도×기관 전체 분류를 제공합니다. long-format에는 총계('예금취급기관')도 포함되므로 단순 합산에 주의하세요. 항목명이 길고 중복될 수 있어 단일 선택은 item_code(예: 11100A0)를 권장합니다.

기간 지정

df = ecos.get_household_lending_detail(
    start_date="202001",
    end_date="202412"
)

차주별 가계대출

차주 유형별(주택담보대출 등) 가계대출을 신규 또는 잔액 기준으로 조회합니다.

지원 유형

  • 신규 - 신규 취급액 기준
  • 잔액 - 대출 잔액 기준 (기본값)

기본 사용법

import ecos

# 차주별 신규 대출
df = ecos.get_borrower_loan(loan_type="신규")
print(df.tail())

# 차주별 대출 잔액
df = ecos.get_borrower_loan(loan_type="잔액")
print(df.tail())

기간 지정

# 2023년 데이터 (분기별)
df = ecos.get_borrower_loan(
    loan_type="잔액",
    start_date="2023Q1",
    end_date="2023Q4"
)

날짜 형식

차주별 대출은 분기 데이터이므로 YYYYQN 형식을 사용합니다.

반환 데이터 구조

컬럼 타입 설명
date datetime 조회 분기
value float 대출액 (10억원)
unit str 단위 (십억원)

차주별 대출 구조 분석

import ecos
import matplotlib.pyplot as plt

# 차주별 대출 잔액 조회
df = ecos.get_borrower_loan(
    loan_type="잔액",
    start_date="2020Q1"
)

# 조원 단위로 변환
df['value_trillion'] = df['value'] / 1000

# 시각화
df.set_index('date')['value_trillion'].plot(
    kind='bar',
    title='차주별 가계대출 잔액',
    ylabel='대출 잔액 (조원)',
    figsize=(14, 6),
    grid=True
)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

실전 활용 예제

통화량 증가율 계산

import ecos

df = ecos.get_money_supply(indicator="M2", start_date="202001")

# 전년동월대비 증가율
df['yoy_growth'] = df['value'].pct_change(periods=12) * 100

# 최근 데이터
recent = df.tail(12)

print("M2 통화량 전년동월대비 증가율:")
for _, row in recent.iterrows():
    if pd.notna(row['yoy_growth']):
        date_str = row['date'].strftime('%Y-%m')
        print(f"{date_str}: {row['yoy_growth']:.2f}%")

통화량 vs 물가 관계 분석

import ecos
import pandas as pd
import matplotlib.pyplot as plt

# 데이터 조회
m2 = ecos.get_money_supply(indicator="M2", start_date="202001")
cpi = ecos.get_cpi(start_date="202001")

# M2 증가율 계산
m2['m2_growth'] = m2['value'].pct_change(periods=12) * 100

# 데이터 병합
merged = pd.merge(
    m2[['date', 'm2_growth']],
    cpi[['date', 'value']].rename(columns={'value': 'cpi'}),
    on='date'
)
merged = merged.dropna()

# 시각화
fig, ax1 = plt.subplots(figsize=(12, 6))

ax1.plot(merged['date'], merged['m2_growth'], 'b-', label='M2 증가율')
ax1.set_xlabel('기간')
ax1.set_ylabel('M2 증가율 (%)', color='b')
ax1.tick_params(axis='y', labelcolor='b')
ax1.grid(True, alpha=0.3)

ax2 = ax1.twinx()
ax2.plot(merged['date'], merged['cpi'], 'r-', label='CPI')
ax2.set_ylabel('CPI (%)', color='r')
ax2.tick_params(axis='y', labelcolor='r')

plt.title('M2 증가율 vs CPI')
plt.tight_layout()
plt.show()

# 상관관계
correlation = merged['m2_growth'].corr(merged['cpi'])
print(f"\nM2 증가율-CPI 상관계수: {correlation:.3f}")

가계부채 증가 추세 분석

import ecos
import matplotlib.pyplot as plt

df = ecos.get_bank_lending(sector="household", start_date="201001")

# 조원 단위로 변환
df['value_trillion'] = df['value'] / 1000

# 전년동월대비 증가율
df['yoy_growth'] = df['value'].pct_change(periods=12) * 100

# 전월대비 증가액
df['mom_increase'] = df['value'].diff() / 1000  # 조원

# 시각화
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(12, 14))

# 잔액 추이
df.set_index('date')['value_trillion'].plot(
    ax=ax1,
    title='가계대출 잔액 추이',
    ylabel='잔액 (조원)',
    grid=True
)

# 증가율
df.set_index('date')['yoy_growth'].plot(
    ax=ax2,
    title='가계대출 전년동월대비 증가율',
    ylabel='증가율 (%)',
    grid=True,
    color='orange'
)
ax2.axhline(y=0, color='black', linestyle='-', linewidth=0.5)

# 월간 증가액
df.set_index('date')['mom_increase'].plot(
    ax=ax3,
    kind='bar',
    title='가계대출 월간 증가액',
    ylabel='증가액 (조원)',
    grid=True,
    color='green'
)
ax3.axhline(y=0, color='black', linestyle='-', linewidth=0.5)

plt.tight_layout()
plt.show()

# 최근 통계
recent = df.tail(6)
avg_increase = recent['mom_increase'].mean()
print(f"최근 6개월 평균 증가액: {avg_increase:.2f}조원/월")

가계부채 vs GDP 비율

import ecos
import pandas as pd

# 데이터 조회
lending = ecos.get_bank_lending(sector="household", start_date="202001")
gdp_annual = ecos.get_gdp(frequency="annual", basis="nominal", start_date="2020")

# 가계대출을 연간으로 집계 (연말 기준)
lending['year'] = lending['date'].dt.year
annual_lending = lending.groupby('year')['value'].last().reset_index()
annual_lending.columns = ['year', 'lending']

# GDP는 성장률이므로 절대값 추정 (2020년 기준)
# 실제로는 명목 GDP 절댓값이 필요하지만, 여기서는 추세 분석만 수행

print("연도별 가계대출 현황:")
for _, row in annual_lending.iterrows():
    year = row['year']
    lending_trillion = row['lending'] / 1000
    print(f"{year}년: {lending_trillion:.0f}조원")

신용 사이클 분석

import ecos
import numpy as np

# 전체 대출 조회
df = ecos.get_bank_lending(sector="all", start_date="201001")

# 전년동월대비 증가율
df['yoy_growth'] = df['value'].pct_change(periods=12) * 100

# 이동평균으로 추세 파악
df['trend'] = df['yoy_growth'].rolling(window=12).mean()

# 신용 사이클 판단
df['cycle'] = np.where(df['yoy_growth'] > df['trend'], '확장', '수축')

# 최근 상황
recent = df.tail(12)
print("최근 12개월 신용 사이클:")
for _, row in recent.iterrows():
    if pd.notna(row['cycle']):
        date_str = row['date'].strftime('%Y-%m')
        print(f"{date_str}: {row['yoy_growth']:.2f}% ({row['cycle']})")

통화량 vs 대출 관계

import ecos
import pandas as pd
import matplotlib.pyplot as plt

# 데이터 조회
m2 = ecos.get_money_supply(indicator="M2", start_date="202001")
lending = ecos.get_bank_lending(sector="all", start_date="202001")

# 조원 단위로 변환 및 병합
merged = pd.merge(
    m2[['date', 'value']].rename(columns={'value': 'M2'}),
    lending[['date', 'value']].rename(columns={'value': '대출'}),
    on='date'
)
merged[['M2', '대출']] = merged[['M2', '대출']] / 1000

# 대출/M2 비율
merged['ratio'] = (merged['대출'] / merged['M2']) * 100

# 시각화
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10))

# 절댓값 비교
merged.set_index('date')[['M2', '대출']].plot(
    ax=ax1,
    title='M2 vs 은행 대출',
    ylabel='금액 (조원)',
    grid=True
)

# 비율
merged.set_index('date')['ratio'].plot(
    ax=ax2,
    title='은행 대출 / M2 비율',
    ylabel='비율 (%)',
    grid=True,
    color='purple'
)

plt.tight_layout()
plt.show()

print(f"현재 대출/M2 비율: {merged.iloc[-1]['ratio']:.1f}%")

다음 단계