Thursday, March 3, 2016

Excel YIELD function equivalent in python Quantlib



I am struggling to get an equivalent of Excel's YIELD function using Quantlib in python. As you can see from the Excel documentation on YIELD here, only a few parameters are needed compared to this example using Quantlib http://gouthamanbalaraman.com/blog/quantlib-bond-modeling.html


UPDATE:


Also, if I use the function bondYield, I can't seem to get the same values as in Excel. Take for example this bond:


enter image description here


the YIELD above has the formula =YIELD(B1,B2,B3/100,B4,100,2,1)*100. The yield is 1.379848.


If I try to set up similar parameters in Quantlib, as shown below


# ql.Schedule
calendar = ql.UnitedStates()
bussinessConvention = ql.ModifiedFollowing
dateGeneration = ql.DateGeneration.Backward

monthEnd = False
cpn_freq = 2
issueDate = ql.Date(30, 9, 2014)
maturityDate = ql.Date(30, 9, 2019)
tenor = ql.Period(cpn_freq)
schedule = ql.Schedule(issueDate, maturityDate, tenor, calendar, bussinessConvention,
bussinessConvention, dateGeneration, monthEnd)

# ql.FixedRateBond
dayCounter = ql.ActualActual()

settlementDays = 1
faceValue = 100
couponRate = 1.75 / 100
coupons = [couponRate]
fixedRateBond = ql.FixedRateBond(settlementDays, faceValue, schedule, coupons, dayCounter)

# ql.FixedRateBond.bondYield
compounding = ql.Compounded
cleanPrice = 100.7421875
fixedRateBond.bondYield(cleanPrice, dayCounter, compounding, cpn_freq) * 100


This gives a yield of 1.3784187000852273, which is close, but not the same as the one given by the excel function.




No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...