返回介绍

第一部分 新手入门

第二部分 股票量化相关

第三部分 基金、利率互换、固定收益类

第四部分 衍生品相关

Swap Curve Construction

发布于 2022-02-20 22:26:20 字数 12140 浏览 989 评论 0 收藏 0

在这个示例中,我们将指导用户如何使用平台的功能,完成从利率互换的市场报价完成收益率曲线的构造。

from CAL.PyCAL import *
SetEvaluationDate(Date(2015, 8, 6))

1. 构造收益率曲线

我们从一组市场标准化互换的市场报价中获取收益率曲线的信息:

  • swap_rates:标准互换对应的固定端利率
  • swap_tenor:标准互换对应的期限
swap_rates = [0.02, 0.03, 0.04 ,0.05, 0.055, 0.06, 0.065, 0.07]
swap_tenor = ['6M', '1Y', '2Y', '3Y', '4Y', '5Y',  '7Y', '10Y']
shiborIndex = Shibor('3M')

instruments = []
for rate, tenor in zip(swap_rates, swap_tenor):
    print('{0:3s} benchmark Shibor Swap fixed at: {1:.2f}%'.format(tenor, rate*100))
    rateHelper = ShiborSwapRateHelper(rate, Period(tenor), Frequency.Quarterly, shiborIndex)
    instruments.append(rateHelper)

6M  benchmark Shibor Swap fixed at: 2.00%
1Y  benchmark Shibor Swap fixed at: 3.00%
2Y  benchmark Shibor Swap fixed at: 4.00%
3Y  benchmark Shibor Swap fixed at: 5.00%
4Y  benchmark Shibor Swap fixed at: 5.50%
5Y  benchmark Shibor Swap fixed at: 6.00%
7Y  benchmark Shibor Swap fixed at: 6.50%
10Y benchmark Shibor Swap fixed at: 7.00%

通过标准互换校正(calibration)收益率曲线:

calibratedCurve = CalibratedYieldCurve(EvaluationDate(), instruments, 'Actual/365 (Fixed)')

收益率曲线的基本信息:

  • discount:折现因子
  • forward(%):远期利率
  • zero(%):零息利率
calibratedCurve.curveProfile().head(10)
datediscountforward(%)zero(%)
2015-08-062015-08-061.0000001.9949472.014979
2015-09-062015-09-060.9983071.9949472.014979
2015-10-062015-10-060.9966721.9949472.014979
2015-11-062015-11-060.9949841.9949472.014979
2015-12-062015-12-060.9933541.9949472.014979
2016-01-062016-01-060.9916721.9949472.014979
2016-02-062016-02-060.9899941.9949472.014979
2016-03-062016-03-060.9869504.0143042.276446
2016-04-062016-04-060.9835914.0143042.505840
2016-05-062016-05-060.9803514.0143042.678750

我们可以画图来看:

calibratedCurve.curveProfile()['zero(%)'].plot(figsize=(16,8))

<matplotlib.axes.AxesSubplot at 0x6bbabd0>

2. 测试

首先可以看这条收益率曲线是否真的可以完美定价基准互换(perfectly pricing):

cal = Calendar('China.IB')
startDate = cal.advanceDate(Date(2015, 8, 6), '1B', BizDayConvention.Following)
shiborIndex = Shibor('3M', calibratedCurve)
nominal = 100000000.
pricingEngine = DiscountingSwapEngine(calibratedCurve)
for rate, tenor in zip(swap_rates, swap_tenor):
    benchmarkSwap = ShiborSwap(SwapLegType.Payer, nominal, startDate, Period(tenor), Period('3M'), rate, shiborIndex)
    benchmarkSwap.setPricingEngine(pricingEngine)
    print('{0:3s} benchmark Shibor Swap NPV: {1:>8.4f}'.format(tenor, benchmarkSwap.NPV()))

6M  benchmark Shibor Swap NPV:   0.0000
1Y  benchmark Shibor Swap NPV:  -0.0000
2Y  benchmark Shibor Swap NPV:   0.0000
3Y  benchmark Shibor Swap NPV:   0.0000
4Y  benchmark Shibor Swap NPV:  -0.0000
5Y  benchmark Shibor Swap NPV:   0.0000
7Y  benchmark Shibor Swap NPV:   0.0000
10Y benchmark Shibor Swap NPV:   0.0000

然后我们取一个假设已经存在的互换(seasoned swap),通过这条收益率曲线估计它的现值:

startDate = Date(2015, 7, 15)
shiborIndex.addFixing(Date(2015, 7, 14), 0.045)
customizeSwap = ShiborSwap(SwapLegType.Receiver, nominal, startDate, Period('9Y'), Period('3M'), 0.06, shiborIndex)
customizeSwap.setPricingEngine(pricingEngine)
print('{0:3s} Shibor Swap fixed at {1:.2f}% NPV: {2:15.4f}'.format('9Y',6.00, customizeSwap.NPV()))

9Y  Shibor Swap fixed at 6.00% NPV:   -6308510.5573
customizeSwap.legAnalysis(0).head(10)
AMOUNTNOMINALACCRUAL_START_DATEACCRUAL_END_DATEACCRUAL_DAYSINDEXFIXING_DAYSFIXING_DATESINDEX_FIXINGDAY_COUNTERACCRUAL_PERIODEFFECTIVE_RATE
PAYMENT_DATE
2015-10-1515123291e+082015-07-152015-10-1592#NA#NA#NA#NAActual/365 (Fixed)0.25205480.06
2016-01-1515123291e+082015-10-152016-01-1592#NA#NA#NA#NAActual/365 (Fixed)0.25205480.06
2016-04-1514958901e+082016-01-152016-04-1591#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2016-07-1514958901e+082016-04-152016-07-1591#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2016-10-1715452051e+082016-07-152016-10-1794#NA#NA#NA#NAActual/365 (Fixed)0.25753420.06
2017-01-1614958901e+082016-10-172017-01-1691#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2017-04-1714958901e+082017-01-162017-04-1791#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2017-07-1714958901e+082017-04-172017-07-1791#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2017-10-1614958901e+082017-07-172017-10-1691#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
2018-01-1514958901e+082017-10-162018-01-1591#NA#NA#NA#NAActual/365 (Fixed)0.24931510.06
customizeSwap.legAnalysis(1).head(10)
AMOUNTNOMINALACCRUAL_START_DATEACCRUAL_END_DATEACCRUAL_DAYSINDEXFIXING_DAYSFIXING_DATESINDEX_FIXINGDAY_COUNTERACCRUAL_PERIODEFFECTIVE_RATE
PAYMENT_DATE
2015-10-1511500001e+082015-07-152015-10-1592Shibor3M Actual/36012015-07-140.045Actual/3600.25555560.045
2016-01-15504102.31e+082015-10-152016-01-1592Shibor3M Actual/36012015-10-140.01972574Actual/3600.25555560.01972574
2016-04-15871825.41e+082016-01-152016-04-1591Shibor3M Actual/36012016-01-140.03448979Actual/3600.25277780.03448979
2016-07-1510058521e+082016-04-152016-07-1591Shibor3M Actual/36012016-04-140.03979193Actual/3600.25277780.03979193
2016-10-1712348641e+082016-07-152016-10-1794Shibor3M Actual/36012016-07-140.04729266Actual/3600.26111110.04729266
2017-01-1612602271e+082016-10-172017-01-1691Shibor3M Actual/36012016-10-140.04985512Actual/3600.25277780.04985512
2017-04-1712602271e+082017-01-162017-04-1791Shibor3M Actual/36012017-01-130.04985512Actual/3600.25277780.04985512
2017-07-1712602271e+082017-04-172017-07-1791Shibor3M Actual/36012017-04-140.04985512Actual/3600.25277780.04985512
2017-10-1616680561e+082017-07-172017-10-1691Shibor3M Actual/36012017-07-140.06598904Actual/3600.25277780.06598904
2018-01-1517907251e+082017-10-162018-01-1591Shibor3M Actual/36012017-10-130.07084187Actual/3600.25277780.07084187

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文