feat: CME FedWatch 확률 역산 (#8) #42

Merged
xhh merged 1 commit from issue-8-fedwatch into main 2026-04-23 01:21:26 +09:00
Owner

Summary

ZQ (30-Day Fed Funds) 월물 체인 settle 가격 → FOMC 회의별 인상/동결/인하 확률을 역산해 fed_expectations 에 저장.

  • cme_fedwatch_collector.py: 월 코드 규칙, 체인 빌더, yfinance fetch, 확률 역산 수식 (CME 방법론의 avg-blend 근사), 연쇄 회의 rate 전파
  • scripts/collect_fedwatch.py: 12개월 체인 수집 후 FOMC 8회 계산해 upsert. --rate-pre 미지정 시 DB 의 DFEDTARU/FEDFUNDS 자동 사용
  • 8 신규 테스트 (월 코드 / 연도 롤오버 / 100%·50%·0% 경계 / 누락 계약 / 연쇄 rate 전파 / yfinance mock)

Test plan

  • ruff check clean
  • 61 tests pass (53 → 61)
  • (수동) uv run python scripts/collect_fedwatch.py --rate-pre 4.25 실 수집 검증

Closes #8

## Summary ZQ (30-Day Fed Funds) 월물 체인 settle 가격 → FOMC 회의별 인상/동결/인하 확률을 역산해 `fed_expectations` 에 저장. - `cme_fedwatch_collector.py`: 월 코드 규칙, 체인 빌더, yfinance fetch, 확률 역산 수식 (CME 방법론의 avg-blend 근사), 연쇄 회의 rate 전파 - `scripts/collect_fedwatch.py`: 12개월 체인 수집 후 FOMC 8회 계산해 upsert. `--rate-pre` 미지정 시 DB 의 DFEDTARU/FEDFUNDS 자동 사용 - 8 신규 테스트 (월 코드 / 연도 롤오버 / 100%·50%·0% 경계 / 누락 계약 / 연쇄 rate 전파 / yfinance mock) ## Test plan - [x] ruff check clean - [x] 61 tests pass (53 → 61) - [ ] (수동) `uv run python scripts/collect_fedwatch.py --rate-pre 4.25` 실 수집 검증 Closes #8
feat: CME FedWatch 확률 역산 (#8)
All checks were successful
Tests (PR) / pytest (pull_request) Successful in 26s
3ba38c9c48
ZQ (30-Day Fed Funds) 월물 체인 settle 가격으로부터 FOMC 회의별 인상/
동결/인하 확률을 역산해 `fed_expectations` 테이블에 저장.

구현
----
- `collectors/cme_fedwatch_collector.py`
  - `zq_contract_symbol(y, m)` — CME 월 코드(F-Z) 규칙으로 ZQ 심볼 생성
  - `build_zq_chain(from_date, months=12)` — 12개월 체인 심볼 목록
  - `fetch_settle_chain(symbols)` — yfinance 로 최근 Close 수집 (재시도)
  - `compute_meeting_probability(meeting, chain, rate_pre)` — 단일 회의
    역산 수식:
      avg_N = 100 - P_N
      r_post = (D*avg_N - pre_days*r_pre) / post_days
      prob_hike = clip((r_post - r_pre) / 0.25, 0, 1)
      prob_cut  = clip((r_pre - r_post) / 0.25, 0, 1)
      prob_hold = 1 - prob_hike - prob_cut
    말일 회의는 다음월물 avg 로 fallback.
  - `compute_all_meetings()` — 이전 회의 post rate 를 다음 회의의 pre
    rate 로 이어 받아 연쇄 경로 추적
  - `FOMC_MEETINGS` 상수 — 2026 전체 + 2027 상반기
- `scripts/collect_fedwatch.py` — 체인 수집 + 확률 계산 + upsert.
  `--rate-pre` 없으면 DB 의 DFEDTARU/FEDFUNDS 최근값을 자동 사용.

검증
----
- `tests/collectors/test_cme_fedwatch_collector.py` 8 케이스:
  월 코드 매핑, 체인 연도 롤오버, 100% 인상/동결 경계, 50% 부분 인하,
  누락 월물 처리, 연쇄 회의 rate 전파, yfinance mock 수집.
- 수식은 CME FedWatch 공개 방법론과 동일한 avg-blend 근사 (단일 25bp
  스텝 가정). 복수 스텝 누적 분포는 후속 확장.

61 tests pass (53 → 61).

Closes #8

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
xhh merged commit 4bcc901af3 into main 2026-04-23 01:21:26 +09:00
xhh deleted branch issue-8-fedwatch 2026-04-23 01:21:26 +09:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
xhh/financial-data-platform!42
No description provided.