使用QuantLib计算带有Floor的FloatingRateBond的现金流量 [英] Using QuantLib to compute cash flows for FloatingRateBond with Floor

查看:150
本文介绍了使用QuantLib计算带有Floor的FloatingRateBond的现金流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QuantLib是新手,因此猜测这是一个菜鸟错误.很高兴认识这个功能强大的库,因此,谢谢您的作者和贡献者!

Very new to QuantLib so guessing this is a rookie mistake. Enjoyed getting to know this powerful library so thank you to the authors and contributors!

如果没有下限参数,我可以在没有定价工具的情况下为FloatingRateBond的现金流量生成金额,因此我不明白为什么要包括下限参数就必须要有定价工具.我认为增加下限只会为每个固定值提供一个最小值.

I'm able to generate amounts for cashflows for a FloatingRateBond without a pricer if there isn't a floor argument, so I don't understand why including a floor argument would necessitate a pricer. I would think the addition of the floor would just provide a min for each of the fixing values.

想看看是否有人在使用地板时获得了FloatingRateBond现金流.而且,如果是这样,是否有人可以发现我误入歧途.预先感谢!

Wanted to see if anyone has gotten the FloatingRateBond cashflows to work while using a floor. And, if so, if anyone can spot where I'm going astray. Thanks in advance!

我在通过预打包的安装程序(QuantLib-Python-1.8.win-amd64-py3.5.msi)安装的Windows上使用QuantLib 1.8.

I'm using the QuantLib 1.8 on windows installed via the pre-packaged installer (QuantLib-Python-1.8.win-amd64-py3.5.msi).

在这里发生错误:

File "C:/src/misc/generate_cashflows.py", line 138, in generate_cashflow
    print(cf.amount())
  File "C:\lib\site-packages\QuantLib\QuantLib.py", line 8844, in amount
    return _QuantLib.CashFlow_amount(self)
RuntimeError: pricer not set

具体代码如下:

ql_first_day, ql_first_month, ql_first_year = first_payment_date.day, first_payment_date.month, first_payment_date.year

ql_first_date = QuantLib.Date(ql_first_day, ql_first_month, ql_first_year)  

maturity_month, maturity_day, maturity_year = maturity.month, maturity.day, maturity.year
ql_maturity_date = QuantLib.Date(maturity_day, maturity_month, maturity_year)



ql_issue_day, ql_issue_month, ql_issue_year = issue_date.day, issue_date.month, issue_date.year
q1_settle_date = QuantLib.Date(ql_issue_day, ql_issue_month, ql_issue_year)

fixing_days = 0

calendar = QuantLib.UnitedStates()
ql_settle_date = calendar.adjust(q1_settle_date)
todays_date = calendar.advance(ql_settle_date, -fixing_days, QuantLib.Days)
QuantLib.Settings.instance().evaluationDate = todays_date

ql_schedule = QuantLib.Schedule(ql_settle_date,
                    ql_maturity_date, QuantLib.Period(ql_frequency_enum),
                    QuantLib.UnitedStates(),
                    QuantLib.Following, QuantLib.Following,
                    QuantLib.DateGeneration.Forward, False, ql_first_date)

ql_forecast_curve = QuantLib.RelinkableYieldTermStructureHandle()
today = datetime.datetime.today()
calc_date = QuantLib.Date(today.day, today.month, today.year)
QuantLib.Settings.instance().evaluationDate = calc_date

day_count = QuantLib.Thirty360()

# setup swaps
calendar = QuantLib.UnitedStates()
swFixedLegFrequency = QuantLib.Annual
swFixedLegConvention = QuantLib.Unadjusted
swFixedLegDayCounter = QuantLib.Thirty360()
swFloatingLegIndex = QuantLib.USDLibor(QuantLib.Period(3, QuantLib.Months))

swap_raw = [
    (1, 0.01251),
    (2, 0.01505),
    (3, 0.01701),
    (5, 0.01972),
    (7, 0.02158)
]

swap_rates = []

for year, rate in swap_raw:
    swap_rates.append(QuantLib.SwapRateHelper(
        QuantLib.QuoteHandle(QuantLib.SimpleQuote(rate)),
        QuantLib.Period(year, QuantLib.Years),
        calendar,
        swFixedLegFrequency,
        swFixedLegConvention,
        swFixedLegDayCounter,
        swFloatingLegIndex
    ))

swap_curve = QuantLib.PiecewiseFlatForward(calc_date, swap_rates, day_count)

ql_forecast_curve.linkTo(swap_curve)

ql_index = QuantLib.USDLibor(period, ql_forecast_curve)

settlement_days = 0
face_amount = 100

ql_bond = QuantLib.FloatingRateBond(settlement_days, #settlementDays
    face_amount, # faceAmount
    ql_schedule,
    ql_index,
    QuantLib.Thirty360(),
    gearings = [],
    spreads = [libor_spread],
    caps = [],
    floors = [.01]
)

ql_discount_curve = QuantLib.RelinkableYieldTermStructureHandle()
settlement_date = QuantLib.Date(9, 2, 2017)
flatForward = QuantLib.FlatForward(
    settlement_date,
    .02,
    QuantLib.ActualActual(QuantLib.ActualActual.Bond),
    QuantLib.Compounded,
    QuantLib.Semiannual)
ql_discount_curve.linkTo(flatForward)
bondEngine = QuantLib.DiscountingBondEngine(ql_discount_curve)
ql_bond.setPricingEngine(bondEngine)

for cf in ql_bond.cashflows():
    c = QuantLib.as_floating_rate_coupon(cf)
    print(cf.amount())

推荐答案

首先是理论:在对有底价的优惠券定价时,您不仅可以从预测曲线中获得预期的LIBOR利率,还可以在与地上.取而代之的是,您需要在比率和下限之间取最小值的期望值,不幸的是E[min(R,F)]min(E[R],F)不同.因此,不,地板并不仅仅是提供最低限度的价格;而是您需要使用其他公式来估算预期收益.

The theory first: when pricing the coupon with a floor, you can't just take the expected LIBOR rate from your forecast curve and take the minimum between that and the floor. Instead, you need to take the expected value of the minimum between the rate and the floor, and unfortunately E[min(R,F)] is not the same as min(E[R],F). So no, the floor doesn't just provide a minimum; you need a different formula to estimate the expected payoff.

对QuantLib的含义是,可以(并且)将简单的浮动利率优惠券设置为默认定价器,该默认定价器仅读取预测曲线上的汇率,但是具有上限或下限的优惠券需要用户指定要使用的定价器,以及向其提供任何其他所需的数据;在您的情况下,这意味着至少具有波动性期限结构,尽管可以指定更多可选数据;有关详细信息,请参见BlackIborCouponPricer类的构造函数.

The implication for QuantLib is that simple floating-rate coupons can be (and are) set a default pricer that just reads the rate off the forecast curve, but coupons with caps or floors need the user to specify what pricer to use and to provide it with any additional needed data; in your case, this means at least a volatility term structure, although more optional data can be specified; see the constructor of the BlackIborCouponPricer class for details.

通常,波动率是在瓶盖和地板的市场报价中引导的,但是创建它的过程却很复杂(请参见 QuantLib邮件列表中进行查询.

Usually, the volatility is bootstrapped on market quotes for caps and floors, but the procedure to create it is kind of complex (see these tests for an example in C++), I'm not sure that all the needed classes are exported to Python, and you'll be better off asking about it on the QuantLib mailing list.

如果您想验证优惠券是否可以使用,可以使用恒定波动率,如:

If you want to verify that the coupons can works, you can use a constant volatility, as in:

volatility = 0.10;
vol = QuantLib.ConstantOptionletVolatility(settlement_days,
                                           calendar,
                                           QuantLib.ModifiedFollowing,
                                           volatility,
                                           day_count)

pricer = QuantLib.BlackIborCouponPricer(
    QuantLib.OptionletVolatilityStructureHandle(vol))
QuantLib.setCouponPricer(ql_bond.cashflows(), pricer)

以上内容应使您能够获得结果;但是我当然可以避免15%的波动,但这不会给您实际的市场价值...

The above should enable you to get a result; but of course I pulled the 15% volatility out of a hat, and it won't give you actual market values...

这篇关于使用QuantLib计算带有Floor的FloatingRateBond的现金流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆