前言
在金融市場中,利率無所不在,從存放款利率、債券殖利率到衍生性金融商品定價,無不與「時間價值」息息相關。隨著全球轉向無風險利率(RFRs)作為新一代定價基準,如SOFR(美國)、ESTR(歐元區)、TONA(日本)等,讓我們必須重新認識隔夜利率(Overnight Rate)與複利利率(Compounded Rate)在實務應用中的角色。
本篇文章將從Money Market Rate(貨幣市場利率)、Overnight Rate(隔夜利率)、以及Compounded Rate(複利利率)三個概念切入,並透過 QuantLib Python 程式庫進行實作,逐步解析這些利率概念在金融商品定價中的應用邏輯,幫助你從理論走向實務。
InterestRateIndex 類別簡介
QuantLib Python中InterestRateIndex 是一個抽象類別,繼承自另一類別Index,其設計目的是為了代表不同種類的利率指標。提供了以下幾個主要屬性與方法:
name():指標名稱fixingDays():幾個工作天前的報價為有效利率currency():幣別calendar():指標適用的曆法dayCounter():日數計算方式fixing(date):取得某日的比價利率值forecastFixing(date):若無實際利率,則用模型預測addFixing(date, rate): 將對應日期的比價利率存入Index中
主要的子類別則有
IborIndex : 用於銀行間的固定天期拆款利率指標,如先前的LIBOR 3M。
OvernightIndex: 適用於隔夜型指標,如 Fed Funds、SOFR、ESTR 等
Money Market Rate
Money Market Rate(貨幣市場利率) 是指在短期資金市場中進行無擔保借貸所適用的利率,通常涵蓋到期日少於一年的資金工具,例如定期存款、商業本票(Commercial Paper)、可轉讓存單(CD)等。這類利率反映市場上短期資金的供需情況,對於金融機構的資金調度、流動性風險管理及產品定價具有高度參考價值。
常見的 Money Market Rate
- LIBOR(倫敦銀行間拆款利率):過去國際間常用的基準利率,已於2023/6/30停用。
- TAIBOR、HIBOR:為台灣與香港本地銀行間市場的短期拆款利率。
- SOFR、ESTR、TONAR etc.:銀行或金融機構在隔夜資金市場中借貸的利率指標。
這些利率不只是參考數字,許多金融商品(如浮動利率債券、結構型商品)都是根據這些指標利率來設計的。
QuantLib Python範例
我們可以利用 QuantLib Python 已經寫好的IborIndex 類別快速建立常見的 Money Market Index物件(例如USDLibor),以及計算利息數字:
# set rate fixing Date
fixing_Date = ql.Date(7, 4, 2025) # the Date format in Quantlib here is dd/mm/yyyy
# create USD Libor 3M Index
libor3m = ql.USDLibor(ql.Period("3M"))
print("Libor 3M Name:", libor3m.name())
value_date = libor3m.valueDate(fixing_Date) # Value Date
print("Libor 3M Value Date:", value_date.ISO()) # print date and the format is yyyy-mm-dd
maturity_date = libor3m.maturityDate(value_date) # Maturity Date
print("Libor 3M Maturity Date:", maturity_date.ISO())
fixing_rate = 0.05
dc_fraction = libor3m.dayCounter().yearFraction(value_date, maturity_date)
interest = 100.0 * fixing_rate * dc_fraction
print(f"Accrued interest: USD {interest:,.2f}")
Libor 3M Name: USDLibor3M Actual/360
Libor 3M Value Date: 2025-04-09
Libor 3M Maturity Date: 2025-07-09
Accrued interest: USD 1.26
但當我們想要使用的利率指標例如台灣市場的TAIBOR,這種尚未被直接在QuantLib Python中定義為類別的利率指標,則我們同樣可以透過物件導向中的繼承作法,直接繼承類別IborIndex 之方式,來定義出新的利率指標,便於後續的使用,Python的實作方式如下:
import QuantLib as ql
class TAIBOR(ql.IborIndex):
def __init__(self, tenor=ql.Period("3M"),
yield_curve=ql.RelinkableYieldTermStructureHandle()):
family_name = "TAIBOR"
fixing_days = 2
currency = ql.TWDCurrency()
calendar = ql.Taiwan()
convention = ql.ModifiedFollowing
end_of_month = False
day_counter = ql.Actual365Fixed()
super().__init__(
family_name,
tenor,
fixing_days,
currency,
calendar,
convention,
end_of_month,
day_counter,
yield_curve
)
# create TAIBOR 3M Index instance
taibor_index = TAIBOR(ql.Period("3M"))
print("TAIBOR Index Name:", taibor_index.name())
print("Fixing Calendar:", taibor_index.fixingCalendar().name())
print("Day Count:", taibor_index.dayCounter().name())
print("3M Maturity Date:", taibor_index.maturityDate(ql.Date(7, 4, 2025)).ISO())
TAIBOR Index Name: TAIBOR3M Actual/365 (Fixed)
Fixing Calendar: Taiwan stock exchange
Day Count: Actual/365 (Fixed)
3M Maturity Date: 2025-07-07
實務應用
Money Market Rate 被廣泛運用於:
- 銀行間短期資金調度、資金拆借合約(如Interbank Lending)
- 資金成本管理
- 建構短天期的利率曲線
Overnight Interest Rate
Overnight Interest Rate(隔夜利率) 是銀行或金融機構在隔夜資金市場中借貸的利率。與其他貨幣市場利率不同,隔夜利率反映的是最短期、最流動的資金價格,因此通常被視為一個國家短期利率政策的風向球,並具有極高的政策敏感性。
常見的隔夜利率指標
- Fed Funds Rate:美國聯邦基金利率,由美聯儲政策引導。
- SOFR(Secured Overnight Financing Rate):以美國國債為擔保的隔夜回購市場利率。
- ESTR(Euro Short-Term Rate):歐洲央行公布的無擔保隔夜利率。
- TONA(Tokyo Overnight Average Rate):日本市場中的主要隔夜利率指標。
這些隔夜利率既可用作短期利率預期的指標,也常被用於利率交換、衍生性金融商品折現計算的基礎。
SOFR、ESTR、TONA也被稱為無風險利率指標(RFRs, Risk-Free Rates),目前全球主要的指標總覽如下:

SOFR Compounded Rate
SOFR Compounded rate的計算公式:

QuantLib Python範例
底下我們透過 QuantLib Python直接建立SOFR的利率指標,並示範如何按照公式來計算出compouned rate:
sofr_index = ql.Sofr()
print("SOFR Index Name:", sofr_index.name())
SOFR Index Name: SOFRON Actual/360
ref_date = ql.Date(4, 3, 2025)
calendar = ql.UnitedStates(ql.UnitedStates.GovernmentBond)
# assuming data period is 2025/3/4 ~ 2025/3/31
start_date = ql.Date(4, 3, 2025)
end_date = ql.Date(1, 4, 2025)
# <https://www.newyorkfed.org/markets/reference-rates/sofr>
sofr_rates = [(ql.Date(31,3,2025),4.41),
(ql.Date(28,3,2025),4.34),
(ql.Date(27,3,2025),4.36),
(ql.Date(26,3,2025),4.35),
(ql.Date(25,3,2025),4.33),
(ql.Date(24,3,2025),4.31),
(ql.Date(21,3,2025),4.3),
(ql.Date(20,3,2025),4.29),
(ql.Date(19,3,2025),4.29),
(ql.Date(18,3,2025),4.31),
(ql.Date(17,3,2025),4.32),
(ql.Date(14,3,2025),4.3),
(ql.Date(13,3,2025),4.3),
(ql.Date(12,3,2025),4.31),
(ql.Date(11,3,2025),4.32),
(ql.Date(10,3,2025),4.33),
(ql.Date(7,3,2025),4.34),
(ql.Date(6,3,2025),4.35),
(ql.Date(5,3,2025),4.34),
(ql.Date(4,3,2025),4.33)]
# add daily USD/SOFR fixing rate
for s_rate in sofr_rates:
sofr_index.addFixing(s_rate[0], s_rate[1]/100.0)
# initial notional and compound factor
notional = 1000000.0
compound_factor = 1.0
day_count = ql.Actual360()
# calculate compounded rate
current_date = start_date
while current_date < end_date:
next_date = calendar.advance(current_date, ql.Period(1, ql.Days))
if calendar.isBusinessDay(current_date) and calendar.isBusinessDay(next_date):
dcf = day_count.yearFraction(current_date, next_date)
r = sofr_index.fixing(current_date)
compound_factor *= (1 + r * dcf)
current_date = next_date
interest = notional * (compound_factor - 1)
compounded_rate = (compound_factor - 1) / day_count.yearFraction(start_date, end_date)
# output result
print(f"SOFR compounded factor: {compound_factor:.8f}")
print(f"Accrued interest from 3/4/2025 to 4/1/2025: USD {interest:,.2f}")
print(f"Compounded rate (annualized): {compounded_rate:.6%}")
SOFR compounded factor: 1.00336890
Accrued interest: USD 3,368.90
Compounded rate (annualized): 4.331441%
隔夜利率的應用範圍非常廣泛,舉例如下:
- 央行政策傳導工具:例如美國聯準會透過調整目標區間,引導Fed Funds Rate變化。
- 現金流折現與風險控管:用SOFR建構出的OIS曲線,是目前銀行金融機構風險控管中的核心。
- 報酬計算基礎:SOFR compounded daily 是目前浮動利率債券計息的標準邏輯。
結語
隨著金融市場逐步採用無風險利率(Risk-Free Rates, RFRs)作為定價基準,理解並正確計算如 SOFR、ESTR 等隔夜利率及其複利效果已成為市場參與者的重要知識。
在 QuantLib Python中,其實已經提供能夠實際計算這些浮動利率與利息的邏輯,包括處理SOFR Lookback、Observation Shift 等市場慣例,將理論落實為可執行的計算物件。接下來就會依序針對QuantLib Python是如何計算這些浮動利息內容繼續跟大家聊聊!
參考資料
- Ballabio, Luigi. Implementing QuantLib. Online resource
- Goutham Balaraman, Luigi Ballabio. QuantLib Python Cookbook. Leanpub, 2020. https://leanpub.com/quantlibpythoncookbook
- https://www.esunbank.com/zh-tw/about/faq/content?q=loan%2F068
- https://www.dbs.com.tw/corporate-zh/ibor
附註: 本文Python程式示範是基於QuantLib Python版本1.37










