如何使用QuantLib创建优惠券重置频率与付款频率不同的索引?

问题描述 投票:0回答:1

在 QuantLib python 文档中,有一个创建自定义 OvernightIndex 的示例:

name = 'CNYRepo7D'
fixingDays = 1
currency = ql.CNYCurrency()
calendar = ql.China()
dayCounter = ql.Actual365Fixed()
overnight_index = ql.OvernightIndex(name, fixingDays, currency, calendar, dayCounter)

在此示例中,创建了一个 CNYRepo7D 索引作为 OvernightIndex。但是,CNYRepo7D 的优惠券重置频率为 7 天,而不是每天。因此,优惠券应该每周复利,而不是每天。这个例子正确吗?

然后我尝试使用 ql.IborIndex 来建模 CNYRepo7D,其中我使用 ql.Period(7, ql.Days) 创建了一个 IborIndex。我还尝试了周期为 3M 的 IborIndex。但结果似乎是相同的。我创建了一个平坦曲线为 5% 的掉期,并打印出浮动现金流。所有 3 个指数(隔夜、7D Ibor、3M Ibor)为我提供了相同的虚拟掉期现金流。

对重置频率与支付频率不同的掉期进行建模的正确方法是什么?

import QuantLib as ql

today = ql.Date(24,8,2024)

# create a flat curve of 5%
rate = 0.05
dayCounter = ql.Actual365Fixed()
interest_rate = ql.QuoteHandle(ql.SimpleQuote(rate))
flat_curve = ql.FlatForward(today, ql.QuoteHandle(ql.SimpleQuote(rate)), dayCounter)
curve_handle = ql.YieldTermStructureHandle(flat_curve)

currency = ql.CNYCurrency()
calendar = ql.China()


def print_floating_cashflow_given_index(index):
    # Add the fixing
    index.addFixing(ql.Date(23, 8, 2024), 0.05)
    # Create a 1Y swap with Quarterly Payment Frequency
    maturity_date = calendar.advance(today, 1, ql.Years, ql.Unadjusted)
    schedule = ql.Schedule(today, maturity_date, ql.Period(3, ql.Months), calendar, ql.ModifiedFollowing,
                           ql.ModifiedFollowing, ql.DateGeneration.Forward, False)
    schedule_len = len(schedule) - 1
    coupon_swap = ql.NonstandardSwap(ql.VanillaSwap.Receiver,
                                   [1] * schedule_len,
                                   [1] * schedule_len,
                                   schedule,
                                   [0.05] * schedule_len,
                                   dayCounter,
                                   schedule,
                                   index,
                                   [1.] * schedule_len,
                                   [0] * schedule_len,
                                   dayCounter,
                                   False,
                                   True)
    for cf in coupon_swap.floatingLeg():
        print(cf.date(), cf.amount())

# create Overnight Index
fixingDays = 1
overnight_index = ql.OvernightIndex('CNYRepo7D',
                                    fixingDays,
                                    currency,
                                    calendar,
                                    dayCounter,
                                    curve_handle)
print('Overnight Index Floating CashFlow')
print_floating_cashflow_given_index(overnight_index)

# create Ibor Weekly Index
ibor_weekly_index = ql.IborIndex(
    'CNY_Weekly',
    ql.Period(7, ql.Days),
    1,
    currency,
    calendar,
    ql.ModifiedFollowing,
    False,
    dayCounter,
    curve_handle
)
print('Weekly Ibor Index Floating CashFlow')
print_floating_cashflow_given_index(ibor_weekly_index)

# create Ibor Quarterly Index
ibor_quarterly_index = ql.IborIndex(
    'CNY_Quarterly',
    ql.Period(3, ql.Months),
    1,
    currency,
    calendar,
    ql.ModifiedFollowing,
    False,
    dayCounter,
    curve_handle
)
print('Quarterly Ibor Index Floating CashFlow')
print_floating_cashflow_given_index(ibor_quarterly_index)

输出

Overnight Index Floating CashFlow
November 25th, 2024 0.012465753424657534
February 24th, 2025 0.012543774790186646
May 26th, 2025 0.012543774790186868
August 25th, 2025 0.012543774790186868
August 25th, 2025 1.0
Weekly Ibor Index Floating CashFlow
November 25th, 2024 0.012465753424657534
February 24th, 2025 0.012543774790186646
May 26th, 2025 0.012543774790186868
August 25th, 2025 0.012543774790186868
August 25th, 2025 1.0
Quarterly Ibor Index Floating CashFlow
November 25th, 2024 0.012465753424657534
February 24th, 2025 0.012543774790186646
May 26th, 2025 0.012543774790186868
August 25th, 2025 0.012543774790186868
August 25th, 2025 1.0
quantlib
1个回答
0
投票

这将是

SubPeriodsCoupon
的用例,但事实证明当前的实现存在问题:有关示例,请参阅 https://implementingquantlib.substack.com/p/coupons-with-multiple-resets。 如果下一版本我们会解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.