QUANTLIB固定曲置与Excel产量()

发布于 2025-01-24 19:52:20 字数 3388 浏览 3 评论 0 原文

我目前正在尝试使用Quantlib库来计算Python中国库券的产量。作为参考,我使用了Excel屈服功能,但是我对相同的输入值获得了不同的结果。

我不明白为什么我会得到不同的结果,而我不明白这种差异的来源。

我使用两个列使用收益函数,YTM列和一个实际产量列。我将从ytm开始。

我知道已经存在类似的问题,例如接下来的两个链接,但这并不能解决我的问题。

ytm

在Excel I中使用以下值:

=YIELD(valuedate, maturitydate, rate, price, redemption, coupons, 3)
  • proditaludate = 26/11/11/11/11/ 2021年
  • 截止日期= 26/01/2026
  • 速率= 0.000%
  • 价格= 45.340
  • 赎回= 100
  • 优惠券= 1
  • daycount = 3 = 3 =实际365,

使用这些值,我得到了 ytm的20.903%

为了在Python中复制这一点,我使用了此代码:。

#Dates
start = 26/11/2021 
maturity = 26/01/2026

#Yield Params
redemption = 100
coup = 1
price = 45.340
couponRate = 0.000%
rate = [couponRate]
calendar = ql.NullCalendar()
settlementDays = 0

tenor = ql.Period(ql.Annual)                   
fixedRateBond = ql.FixedRateBond(settlementDays, calendar, redemption, start, maturity, tenor, rate, ql.Actual365Fixed())               
fixedRateBond.bondYield(price,
                        ql.Actual365Fixed(),
                        ql.SimpleThenCompounded, #SimpleThenCompounded gives best result yet
                        ql.Annual,
                        start, 
                        1.0e-16, 
                        100
                        )

使用Quantlib,使用与Excel产量相同的值,我获得了 20.827%的产率,这是 0.075%的小差异。

,当查看实际产量时,使用与YTM相同的参数会获得更大的差异。

因此,在试用和错误的同样心态下,我使用了略有不同的参数,这些参数返回了我能获得的最佳结果。

实际收益率

excel值:(

=YIELD(quotationdate+3, maturitydate, rate, quotationprice, redemption, coupons, 3)  

注意:我们这样做+3,因为计算的兴趣是在结算中计算的)

  • QuordationDate = 2/3/2022
  • MaturityDate = 16/10/2049
  • 速率= 3.897%
  • Quoleprice = 3.897 % 15
  • 赎回= 100
  • 票票= 1
  • 日倒= 3 =

365

ql.Settings.instance().evaluationDate = 2/3/2022
start = 2/3/2022
maturity = 16/10/2049

coup = 1
price = 15
couponRate = 3.897%
rate = [couponRate]
settlementDays = 3

calendar = ql.NullCalendar()
businessConvention = ql.Unadjusted
dateGeneration = ql.DateGeneration.Backward
monthEnd = False
redemption = 100
tenor = ql.Period(ql.Annual)

schedule = ql.Schedule(start, 
                       maturity, 
                       tenor, 
                       calendar, 
                       businessConvention,
                       businessConvention, 
                       dateGeneration, 
                       monthEnd)
                
 bond = ql.FixedRateBond(settlementDays, redemption, schedule, rate, ql.Actual365Fixed())
 bond.bondYield(price,
                ql.Actual365Fixed(),
                ql.Compounded,
                ql.Annual)

实际 0.324%

我想强调我没有财务背景。我通过其他类似的Stackoverflow问题以及大量的反复试验获得了这些参数。

使用Quantlib中相同的参数以获得与YTM中使用的实际产率相比,结果比这些参数更差。

有人可以向我解释我应该使用哪些参数来复制Excel targe()函数,以及为什么我在Quantlib和Excel之间存在差异?

另外,Excel功能是否正确正确?

I'm currently trying to calculate the Yield of Treasury Bonds in Python using the QuantLib library. As a reference I used the Excel Yield function, but I'm getting different results for the same input-values.

I don't understand why I'm getting different results and I don't understand where this difference comes from.

I have two columns using the Yield function, a YTM column and an Actual Yield column. I'll start with YTM.

I know that similar questions already exists, like the next two links, but it doesn't resolve my issue.

YTM

In Excel I use the following values:

=YIELD(valuedate, maturitydate, rate, price, redemption, coupons, 3)
  • valuedate = 26/11/2021
  • maturitydate = 26/01/2026
  • rate = 0.000%
  • price = 45.340
  • redemption = 100
  • coupons = 1
  • dayCount = 3 = Actual365

With these values I get a YTM of 20.903%.

To replicate this in Python I used this code:.

#Dates
start = 26/11/2021 
maturity = 26/01/2026

#Yield Params
redemption = 100
coup = 1
price = 45.340
couponRate = 0.000%
rate = [couponRate]
calendar = ql.NullCalendar()
settlementDays = 0

tenor = ql.Period(ql.Annual)                   
fixedRateBond = ql.FixedRateBond(settlementDays, calendar, redemption, start, maturity, tenor, rate, ql.Actual365Fixed())               
fixedRateBond.bondYield(price,
                        ql.Actual365Fixed(),
                        ql.SimpleThenCompounded, #SimpleThenCompounded gives best result yet
                        ql.Annual,
                        start, 
                        1.0e-16, 
                        100
                        )

With QuantLib, using the same values as Excel Yield, I get a Yield of 20.827% which is a small difference of 0.075%.

But, when looking at Actual Yield, I get bigger differences using the same parameters as with YTM.

So, with the same mindset of trial-and-error, I've used slightly different parameters which returned the best results I could obtain.

Actual Yield

Excel values:

=YIELD(quotationdate+3, maturitydate, rate, quotationprice, redemption, coupons, 3)  

(note: that we do +3 because the accrued interest is calculated on the settlementDate)

  • quotationdate = 2/3/2022
  • maturitydate = 16/10/2049
  • rate = 3.897%
  • quotationprice = 15
  • redemption = 100
  • coupons = 1
  • dayCount = 3 = Actual365

which returns a yield of 26.044%

QuantLib:

ql.Settings.instance().evaluationDate = 2/3/2022
start = 2/3/2022
maturity = 16/10/2049

coup = 1
price = 15
couponRate = 3.897%
rate = [couponRate]
settlementDays = 3

calendar = ql.NullCalendar()
businessConvention = ql.Unadjusted
dateGeneration = ql.DateGeneration.Backward
monthEnd = False
redemption = 100
tenor = ql.Period(ql.Annual)

schedule = ql.Schedule(start, 
                       maturity, 
                       tenor, 
                       calendar, 
                       businessConvention,
                       businessConvention, 
                       dateGeneration, 
                       monthEnd)
                
 bond = ql.FixedRateBond(settlementDays, redemption, schedule, rate, ql.Actual365Fixed())
 bond.bondYield(price,
                ql.Actual365Fixed(),
                ql.Compounded,
                ql.Annual)

Resulting in a Yield of 26.368% which is a difference of 0.324%

I want to stress that I don't have a financial background. I got these parameters via other similar StackOverflow questions and through a lot of trial-and-error.

Using the same parameters in QuantLib for Actual Yield as used in YTM gave worse results than these parameters.

Could someone explain to me which parameters I should use to replicate the Excel Yield() function and why I'm getting differences between QuantLib and Excel?

Also, is the Excel function granted to be 100% correct?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2025-01-31 19:52:20

从Excel的文档中,尚不清楚他们对ACT/365的定义是什么,但通常是ACT/365实际上是ACT/ACT ISDA,它与ACT/365F完全不同。

可能存在许多不同的实现(请参阅Rates Lib vs Quantlib的源代码):

wikipedia> wikipedia

=“ https://github.com/attack68/rateslib/blob/main/main/python/rateslib/calendars.py” rel =“ nofollow noreferrer”> rateslib python

noroflow noreferrer“> pontlib c ++ </

a发行的管辖权(b)和贸易场所。此外,大型国际公司(货币中心银行)可能还依靠标准化的AIBD公约,这可能与国内标准略有不同。

不幸的是,全球债券收益率计算中没有市场标准化。

我对这个问题的回答是使用最常见的实现 - 在YAS屏幕中提供BBG的帮助 - 大多数FI交易者将其用作其“黄金标准”。这就是我要复制的。

las,债券交易的约定差额应为80-120。但是,$ 45的某种交易的国库肯定是垃圾,而在任何场所的任何合理的出价/报价中,8bps的约定都将很好,而且我不会为此投入过多的精力。约定套利的概率接近零。

From Excel's documentation it is not clear what their definition of ACT/365 is, but commonly ACT/365 is in fact ACT/ACT ISDA, which is quite different than ACT/365F.

There may exist many different implementations (see source code of RatesLib vs Quantlib):

wikipedia

rateslib python

quantlib c++

Generally, IMHO, YTM calculation bases are subjective based on (a) jurisdiction of issuance, (b) and venue of trade. Further, large international firms (money center banks) may additionally rely on standardized AIBD conventions which may be different slightly from domestic standards.

Unfortunately there is no market standardization in bond yield calculations globally.

My answer to this question would be to use the most common implementation -- HELP in BBG in YAS screen--as most FI traders use that as their 'gold standard'. This is what I would replicate.

Alas, the convention difference on a bond trading 80-120 should be <1bp. But a treasury of some kind trading at $45 is certainly junk, and 8bps of convention would be well within any reasonable bid/offer on any venue, and I wouldn't put too much energy into it. Probability of convention arbitrage is near zero.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文