1
0

QuantLibの固定利付債のクーポン計算方法を確認する

Last updated at Posted at 2023-10-15

ql.FixedRateBondオブジェクトがどのようにクーポンを計算するかを確認する。

固定利付債を生成
import QuantLib as ql

schedule = ql.Schedule(
    ql.Date(15, 5, 2007),       # effective date    : 開始日
    ql.Date(15, 5, 2027),       # termination date  : 終了日  
    ql.Period(0, ql.Months),    # tenor             : 間隔(0は終了日のみ)
    ql.Japan(),                 # calendar          : 祝休日
    ql.Unadjusted,              # convention        : 非営業日調整
    ql.Unadjusted,              # termination date convention : 終了日の非営業日調整
    ql.DateGeneration.Backward, # rule              : 日付生成のルール
    False,                      # end_of_month      : 開始日が月末の場合に、終了日以外の利払日を月末とするか否か
)

fixed_rate_bond = ql.FixedRateBond(
    3,                  # settlement days   : 決済期間
    100.0,              # face amount       : 額面 
    schedule,           # schedule          : 利払日
    [0.015],            # coupon            : 利率(%単位ではなく少数単位)
    ql.Actual365Fixed() # day counter       : 日数計算方法
)
キャッシュフローを確認
for cf in fixed_rate_bond.cashflows():
    print(cf.date(), cf.amount())

# May 17th, 2027 30.02054794520548
# May 17th, 2027 100.0
クーポン計算方法を確認
cf = fixed_rate_bond.cashflows()[0]
cf: ql.FixedRateCoupon = ql.as_fixed_rate_coupon(cf)

assert cf.amount() == cf.rate() * cf.accrualPeriod() * cf.nominal()  # 30.02054794520548
assert cf.rate() == 0.03
assert cf.accrualPeriod() == cf.dayCounter().yearFraction(cf.accrualStartDate(), cf.accrualEndDate())  # 20.013698630136986
assert cf.nominal() == fixed_rate_bond.notional() # 100
assert cf.accrualDays() == cf.accrualEndDate() - cf.accrualStartDate() #7305
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0