首页 > 解决方案 > 可赎回债券的 OAS Quantlib

问题描述

我正在尝试确定 QuantLib 中可赎回债券的 OAS。但是,我的结果总是否定的!?

我想知道调用时间表中是否存在一些问题,因为根据赫尔怀特模型对债券定价所返回的债券收益率似乎是合理的。

考虑以下债券合约:

import QuantLib as ql
import numpy as np
import pandas as pd


bf = ql.BondFunctions
qd = ql.DateParser.parseFormatted

# Conventions
accrual_convention = ql.Unadjusted
Rule = ql.DateGeneration.Backward
endofMonth = False
firstDate = None

# OAS
compounding = ql.Compounded
frequency = ql.Annual

calendar = ql.UnitedStates()

a = 0.1
sigma = 0.1
grid_points = 100
face_amount = 100
mkt_price = 78

contract = {
    'IssueDate': ql.Date(30,6,2016),
    'MaturityDate': ql.Date(15,6,2023),
    'SettlementDays': 2,
    'FirstCouponDate': ql.Date(15,12,2016),
    'NextToLastCouponDate': ql.Date(15,12,2022),
    'RealValue': 0.0675,
    'FirstCallDate': ql.Date(15,6,2019),
    'OptionalityEndDate': ql.Date(15,6,2023),
    'OperatingCountry': 'US',
    'StrikeDate': [ql.Date(15,6,2019), ql.Date(15,6,2020), ql.Date(15,6,2021)],
    'OptionalityType': ['Call', 'Call', 'Call'],
    'NoticeDays': [30, 30, 30],
    'StrikePrice': [103.375, 101.688, 100.0]}

# Here is the zero curve:

times= np.array(['0 MO', '1 MO', '2 MO', '3 MO', '6 MO', '1 YR', '2 YR', '3 YR',
       '5 YR', '7 YR', '10 YR', '20 YR', '30 YR'], dtype=object)

dates = [ql.Date(9,2,2017), ql.Date(9,3,2017), ql. Date(9,4,2017),
         ql.Date(9,5,2017),ql.Date(9,8,2017), ql.Date(9,2,2018),
         ql.Date(9,2,2019),ql.Date(9,2,2020), ql.Date(9,2,2022),
         ql.Date(9,2,2024), ql.Date(9,2,2027),ql.Date(9,2,2037),
         ql.Date(9,2,2047)]

rates = np.array([0.51 , 0.51 , 0.525, 0.54 , 0.64 ,
                   0.8  , 1.2  , 1.46 , 1.88 , 2.2  ,
                   2.4  , 2.74 , 3.02 ])

day_count = ql.ActualActual()
calc_date = ql.Date(9,2,2017)
ql.Settings.instance().evaluationDate = calc_date

issue_date = contract["IssueDate"]
maturity_date = contract["MaturityDate"]
tenor = ql.Period(ql.Semiannual)

coupon = contract["RealValue"]
settlement_days = contract["SettlementDays"]

# Determine Schedule
schedule = ql.Schedule(issue_date,
                       maturity_date,
                       tenor,
                       calendar,
                       accrual_convention,
                       accrual_convention,
                       Rule,
                       endofMonth)

# Initiate Zero Curve
curve = ql.ZeroCurve(dates,
                     rates,
                     ql.ActualActual(),
                     calendar,
                     ql.Linear())
curve.enableExtrapolation()
ts_handle = ql.YieldTermStructureHandle(curve)

def get_call_schedule(df, period=ql.Period(ql.Annual)):
    dates = df["StrikeDate"]
    prices = df["StrikePrice"]
    callability_schedule = ql.CallabilitySchedule()
    null_calendar = ql.NullCalendar()
    call_date = df["StrikeDate"][0]
    for time in range(len(df["StrikeDate"])):
        callability_price  = ql.CallabilityPrice(prices[time],
                                                 ql.CallabilityPrice.Clean)
        callability_schedule.append(ql.Callability(callability_price, 
                                                   ql.Callability.Call,
                                                   dates[time]))
        call_date = null_calendar.advance(call_date, period)
    return callability_schedule


callability_schedule = get_call_schedule(contract)

bond = ql.CallableFixedRateBond(settlement_days,
                                face_amount,
                                schedule,
                                [coupon],
                                day_count,
                                ql.Following,
                                face_amount,
                                calc_date,
                                callability_schedule)



def value_bond(a, s, ts_handle, grid_points, bond):
    model = ql.HullWhite(ts_handle, a, s)
    engine = ql.TreeCallableFixedRateBondEngine(model, grid_points)
    bond.setPricingEngine(engine)
    return bond

bondprice = value_bond(a, sigma, ts_handle, grid_points, bond)
OAS = bondprice.OAS(mkt_price,
                    ts_handle,
                    day_count,
                    compounding,
                    frequency)
bond_yield = bondprice.bondYield(mkt_price,
                                 day_count,
                                 compounding,
                                 frequency)

print(OAS)
print(bond_yield)

这产生了 -6.69 的 OAS 值和 0.121 或 12.1% 的债券收益率 (YTM)。如果一个人在执行日期考虑欧式期权与在息票支付日期支付执行价格的美式期权,会有很大的不同!?

标签: pythonquantlib

解决方案


您的利率下降了 100 倍。2% 的利率需要写为 0.02,而不是 2.0。


推荐阅读