前言
在使用 QuantLib Python建構與定價以隔夜利率為基礎的衍生性金融商品(如 SOFR Swap、ESTR Swap)時,OvernightIndexedCoupon 是一個核心元件。本篇文章將深入解析該物件的設計概念、計算邏輯、內建的定價器(Pricer),以及實務應用上的注意事項。

什麼是 OvernightIndexedCoupon?
OvernightIndexedCoupon 是一種以每日隔夜利率累積計息的計算利息工具,其常見應用包括:
- SOFR、ESTR、TONA、SARON 等隔夜利率互換交易(OIS)中的浮動端現金流
- 資金調度中的浮動利息計算
建構參數簡介
在 QuantLib Python中建構 OvernightIndexedCoupon 時,基本語法如下:
ql.OvernightIndexedCoupon(
paymentDate, # 利息支付日
nominal, # 名目本金
startDate, # 計息起日
endDate, # 計息終日
overnightIndex, # 隔夜利率指標(如 ql.Sofr())
gearing=1.0,
spread=0.0,
refPeriodStart=ql.Date(),
refPeriodEnd=ql.Date(),
dayCounter=ql.Actual360(),
telescopicValueDates=False, # 開啟效能優化與否
averagingMethod=ql.OvernightIndexedCoupon.Compound,
lookbackDays=0,
lockoutDays=0,
applyObservationShift=False
)
無需手動設定Pricer()
與 IborCoupon 不同,OvernightIndexedCoupon 在建構時會自動綁定對應的 Pricer,根據選定的 averaging method:

因此,除非是要自定義Pricer,一般情況下不需要手動設定 .setPricer()。
關於參數telescopicValueDates
在處理每日複利(daily compounding)的 OIS 產品(如 SOFR、FedFunds、SARON 等)時,OvernightIndexedCoupon 需要展開整個利率期間的每日值以計算複利,這在期數很長或大量 instrument 並行計算時會造成效能瓶頸。為了解決這個問題,QuantLib 提供了telescopicValueDates 參數。當設定為 True 時,QuantLib 不會逐日展開所有值,而是利用演算法僅保留必要的日期節點來進行複利計算,以提升計算速度同時保留計算精準度。
底下為QuantLib針對這一參數的描述說明:
telescopicValueDates optimizes the schedule for calculation speed, but might fail to produce correct results if the coupon ages by more than a grace period of 7 days. It is therefore recommended not to set this flag to true unless you know exactly what you are doing. The intended use is rather by the OISRateHelper which is safe, since it reinitialises the instrument each time the evaluation date changes.
計息方式:Compound vs Simple
QuantLib Python支援兩種計息邏輯:
Compounded Averaging Rate

Simple Averaging Rate

其中:

QuantLib Python 範例
底下以SOFR為例,計算2025/3/4至2025/4/1這段區間的Compounded rate以及利息。首先初始SOFR interest rate index物件,以及給定每日fixing rate。
ref_date = ql.Date(4, 3, 2025)
# create SOFR Index and link to dummy term structure (flat curve)
sofr_curve = ql.FlatForward(ref_date, 0.0, ql.Actual365Fixed())
sofr_termStrcuture = ql.YieldTermStructureHandle(sofr_curve)
sofr_index = ql.Sofr(sofr_termStrcuture)
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)
利用類別 OvernightIndexedCoupon直接自動計算 SOFR 的浮動利息與複利利率(compounded averaging rate):
# OvernightIndexedCoupon with compounding averaging rate method
coupon_comp = ql.OvernightIndexedCoupon(
paymentDate=end_date,
nominal=1000000.0,
startDate=start_date,
endDate=end_date,
overnightIndex=sofr_index,
gearing=1.0,
spread=0.0,
dayCounter=ql.Actual360(),
averagingMethod = ql.RateAveraging.Compound
)
# calculate compouned interest and rate
payment_amount = coupon_comp.amount()
compounded_rate = coupon_comp.rate()
print(f"SOFR Compounded Rate: {compounded_rate:.6%}")
print(f"Accrued Interest: USD {payment_amount:,.2f}")
SOFR Compounded Rate: 4.331441%
Accrued Interest: USD 3,368.90
同樣的當我們想要計算的是採用Simple averaging方法時,則我們可在物件生成時,指定averagingMethod = ql.RateAveraging.Simple即可。
# OvernightIndexedCoupon with simple averaging rate method
coupon_simple = ql.OvernightIndexedCoupon(
paymentDate=end_date,
nominal=1000000.0,
startDate=start_date,
endDate=end_date,
overnightIndex=sofr_index,
gearing=1.0,
spread=0.0,
dayCounter=ql.Actual360(),
averagingMethod = ql.RateAveraging.Simple
)
# calculate compouned interest and rate
payment_amount = coupon_simple.amount()
compounded_rate = coupon_simple.rate()
print(f"SOFR Compounded Rate: {compounded_rate:.6%}")
print(f"Accrued Interest: USD {payment_amount:,.2f}")
SOFR Compounded Rate: 4.324643%
Accrued Interest: USD 3,363.61
Lag Publication
實務上,SOFR等RFRs 具有「T+1 延遲公布」的特性,這對於實際計算 Compounded Rate和付款利息時,有顯著影響。因此市場上(特別是 ISDA、ARRC 等)發展了幾種主流的處理方式。整理如下:
RFRs延遲發布特性與處理策略

類別 OvernightIndexedCoupon 已經可以支援:
- Lookback Days
- With or Without Observation Shift
假設我們要計算的SOFR浮動利息是Lookback 5天以及考慮Observation Shift時(即計息區間變為2025/2/25~2025/3/25),可以將這兩參數直接在生成OvernightIndexedCoupon給定,示範程式如下:
# add additional SOFR rates for 5 days lookback
sofr_rates_add = [(ql.Date(3,3,2025),4.33),
(ql.Date(28,2,2025),4.39),
(ql.Date(27,2,2025),4.36),
(ql.Date(26,2,2025),4.33),
(ql.Date(25,2,2025),4.33)]
for s_rate in sofr_rates_add:
sofr_index.addFixing(s_rate[0], s_rate[1]/100.0)
# define Lookback and Observation Shift
lookback_days = 5
use_observation_shift = True # else False,just Lookback, didn't shift observation dates
coupon_obs_shift = ql.OvernightIndexedCoupon(
paymentDate=end_date,
nominal=notional,
startDate=start_date,
endDate=end_date,
overnightIndex=sofr_index,
gearing=1.0,
spread=0.0,
refPeriodStart=ql.Date(),
refPeriodEnd=ql.Date(),
dayCounter=ql.Actual360(),
lookbackDays=lookback_days,
telescopicValueDates=False,
applyObservationShift=use_observation_shift
)
# output result
print(f"SOFR Compounded Rate with Lookback {lookback_days} days "
f"({'with shift' if use_observation_shift else 'no shift'}): "
f"{coupon_obs_shift.rate():.6%}")
print(f"Accrued Interest: USD {coupon_obs_shift.amount():,.2f}")
SOFR Compounded Rate with Lookback 5 days (with shift): 4.333231%
Accrued Interest: USD 3,370.29
結語
OvernightIndexedCoupon 是 QuantLib 中計算每日隔夜利息的核心元件。預設使用複利方式計息,並自動附帶對應 pricer。適合用於 SOFR、ESTR等OIS 交易的定價與風險評估。同時我們也提及在目前RFRs發佈上具有延遲一天的特性,因此真正在計算compounded averaging rate時,需考量Lookback days以及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.newyorkfed.org/medialibrary/Microsites/arrc/files/2021/users-guide-to-sofr2021-update.pdf
- https://www.newyorkfed.org/markets/reference-rates/additional-information-about-reference-rates#tgcr_bgcr_sofr_calculation_methodology




















