跳至正文
返回文库全部文档

从插值收益率曲线中采样贴现因子

文章 Quant Q&A · 作者: Mike

总结

本文展示如何获取用于构建QuantLib贴现曲线的报价期限之间各日期对应的贴现因子。示例先根据互换利率输入构建分段对数线性贴现曲线,再生成一系列未来日期,并逐一调用曲线的discount方法。所得数值构成曲线的等间距样本,可与日期一同展示。

示例代码按五年间隔取样,而问题要求按半年间隔取样;只需将日期间隔改为六个月,同样的方法即可实现。另一个回答进一步说明了关键点:曲线可以返回任何指定日期的贴现因子,因此输出不必局限于原始曲线节点。示例使用瑞典克朗互换数据,并启用了超出最后一个输入期限的外推。因此,输出展示的是API用法,而非市场证据;外推值取决于曲线假设和配置。

核心观点

  • 构建好的贴现曲线可以返回输入期限节点之间日期的贴现因子。
  • 选择所需的日期间隔,并逐个日期查询曲线。
  • 示例按五年间隔取样;更改日期增量即可按半年间隔取样。
  • 超出最后一个曲线节点的贴现因子可能依赖外推设置,应据此解读。

标签

全文
# QuantLib Python - Discount Factor Interpolation within curve nodes


# QuantLib Python - Discount Factor Interpolation within curve nodes












Generated a discount curve, dCurve.PiecewiseLogLinearDiscount() using input par rate for terms (.5Y, 1Y, 2Y, 3Y, 5Y, 7Y, 10Y, 15Y, 20Y, 30Y) and output discount curve matching the input term structure. Any suggestions on how to output the discount factor curve on a .5Y interval term structure up to 30Y?

## Answer by Xiarpedia (score 1)

https://quant.stackexchange.com/a/77563

Based on your question I created the following curve example:

```
import QuantLib as ql
import pandas as pd

# Set the evaluation date
ql.Settings.instance().evaluationDate = ql.Date(30, 12, 2022)
# Declare a store variable for the helpers
helpers = []
# Create the attributes of the swap
calendar = ql.Sweden()
frequency = ql.Annual
convention = ql.ModifiedFollowing
# Synthetic market data
daycount = ql.Thirty360(ql.Thirty360.BondBasis)
index = ql.IborIndex(
    "MyIndex",
    ql.Period("3M"),
    2,
    ql.SEKCurrency(),
    calendar,
    ql.Following,
    False,
    daycount,
)

tenor = ["4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "12Y", "15Y", "20Y", "25Y", "30Y"]
quotes = [
    3.33,
    3.2775,
    3.235,
    3.205,
    3.1775,
    3.1525,
    3.1325,
    3.095,
    3.0275,
    2.92,
    2.815,
    2.6925,
]
for r, m in zip(quotes, tenor):
    rate = ql.QuoteHandle(ql.SimpleQuote(r / 100.0))
    tenor = ql.Period(m)
    helpers.append(
        ql.SwapRateHelper(
            rate, tenor, calendar, frequency, convention, daycount, index
        )
    )
curve = ql.PiecewiseLogLinearDiscount(0, calendar, helpers, ql.Actual365Fixed())
curve.enableExtrapolation()
dates, rates = zip(*curve.nodes())
```

Which leaves me at the stage you are at. We can then interpolate on a 5 year interval as following:

```
# Interpolate on a 5Y interval
nodes = []
start_date = ql.Date(30, 12, 2022)
while True:
    start_date += ql.Period("5Y")
    nodes.append(start_date)
    if start_date > ql.Date(30, 12, 2053):
        break
discount_factors = [curve.discount(d) for d in nodes]
display(pd.DataFrame(dict({"Date": nodes, "Discount Factor": discount_factors})))
```

Which results in:

|  | Date | Discount Factor |
| 0 | December 30th, 2027 | 0.851205 |
| 1 | December 30th, 2032 | 0.735589 |
| 2 | December 30th, 2037 | 0.641855 |
| 3 | December 30th, 2042 | 0.567462 |
| 4 | December 30th, 2047 | 0.508218 |
| 5 | December 30th, 2052 | 0.464726 |
| 6 | December 30th, 2057 | 0.424997 |

## Answer by Luigi Ballabio (score 0)

https://quant.stackexchange.com/a/77564

You can pass any date you like to the `discount` method of the curve you built. It will return the corresponding discount factor.

在遵守原作品许可的前提下,附作者信息全文展示。 许可协议: CC BY-SA 4.0 (Stack Exchange)

此摘要由 Stratmill 研究智能体根据原文撰写,并非原文副本。